?? wiiremotesampleapplication.java
字號:
System.out.println("Remote disconnected... Please Wii again."); System.exit(0); } public void statusReported(WRStatusEvent evt) { System.out.println("Battery level: " + (double)evt.getBatteryLevel()/2+ "%"); System.out.println("Continuous: " + evt.isContinuousEnabled()); System.out.println("Remote continuous: " + remote.isContinuousEnabled()); } public void IRInputReceived(WRIREvent evt) { /* for ( IRLight light : evt.getIRLights() ) { if ( light != null ) { System.out.println("X: "+light.getX()); System.out.println("Y: "+light.getY()); } } */ } public void accelerationInputReceived(WRAccelerationEvent evt) { if ( accelerometerSource ) { lastX = x; lastY = y; lastZ = z; x = (int)(evt.getXAcceleration()/5*300)+300; y = (int)(evt.getYAcceleration()/5*300)+300; z = (int)(evt.getZAcceleration()/5*300)+300; t++; graph.repaint(); } /* System.out.println("---Acceleration Data---"); System.out.println("X: " + evt.getXAcceleration()); System.out.println("Y: " + evt.getYAcceleration()); System.out.println("Z: " + evt.getZAcceleration()); */ } public void extensionInputReceived(WRExtensionEvent evt) { if ( evt instanceof WRNunchukExtensionEvent ) { WRNunchukExtensionEvent NEvt = (WRNunchukExtensionEvent)evt; if ( !accelerometerSource ) { WRAccelerationEvent AEvt = NEvt.getAcceleration(); lastX = x; lastY = y; lastZ = z; x = (int)(AEvt.getXAcceleration()/5*300)+300; y = (int)(AEvt.getYAcceleration()/5*300)+300; z = (int)(AEvt.getZAcceleration()/5*300)+300; t++; graph.repaint(); } if ( NEvt.wasPressed(WRNunchukExtensionEvent.C) ) { System.out.println("Jump..."); } if ( NEvt.wasPressed(WRNunchukExtensionEvent.Z) ) { System.out.println("And crouch."); } } else if ( evt instanceof WRClassicControllerExtensionEvent ) { WRClassicControllerExtensionEvent CCEvt; CCEvt = (WRClassicControllerExtensionEvent)evt; if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.A) ) { System.out.println("A!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.B) ) { System.out.println("B!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.Y) ) { System.out.println("Y!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.X) ) { System.out.println("X!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.LEFT_Z) ) { System.out.println("ZL!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.RIGHT_Z) ) { System.out.println("ZR!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.LEFT_TRIGGER) ) { System.out.println("TL!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.RIGHT_TRIGGER) ) { System.out.println("TR!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.DPAD_LEFT) ) { System.out.println("DL!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.DPAD_RIGHT) ) { System.out.println("DR!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.DPAD_UP) ) { System.out.println("DU!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.DPAD_DOWN) ) { System.out.println("DD!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.PLUS) ) { System.out.println("Plus!"); } if ( CCEvt.wasPressed(WRClassicControllerExtensionEvent.MINUS) ) { System.out.println("Minus!"); } if ( CCEvt.isPressed(WRClassicControllerExtensionEvent.HOME) ) { System.out.println("L shoulder: " + CCEvt.getLeftTrigger()); System.out.println("R shoulder: " + CCEvt.getRightTrigger()); } } } public void extensionConnected(WiiRemoteExtension extension) { System.out.println("Extension connected!"); try { remote.setExtensionEnabled(true); } catch ( Exception e ) { e.printStackTrace(); } } public void extensionPartiallyInserted() { System.out.println("Extension partially inserted. Please push it in more!"); } public void extensionUnknown() { System.out.println("Extension unknown. Did you try to plug in a toaster or something?"); } public void extensionDisconnected(WiiRemoteExtension extension) { System.out.println("Extension disconnected. Why'd you unplug it?"); } private void mouseCycle() { try { if ( status == 0 ) { if ( accelerometerStatus == 0 ) { remote.setMouse(MotionAccelerometerMouse.getDefault()); } else if ( accelerometerStatus == 1 ) { remote.setMouse(TiltAccelerometerMouse.getDefault()); } else if ( accelerometerStatus == 2 ) { remote.setMouse(new MotionAccelerometerMouse(80, 60, AccelerometerMouse.NUNCHUK_EXTENSION, 0.06, 0.08)); } else if ( accelerometerStatus == 3 ) { remote.setMouse(new TiltAccelerometerMouse(10, 10, AccelerometerMouse.NUNCHUK_EXTENSION, 0.1, 0.1)); } } else if ( status == 1 ) { remote.setMouse(IRMouse.getDefault()); } else if ( status == 2 ) { remote.setMouse(IRAccelerometerMouse.getDefault()); } else if ( status == 3 ) { if ( analogStickStatus == 0 ) { remote.setMouse(AbsoluteAnalogStickMouse.getDefault()); } else if ( analogStickStatus == 1 ) { remote.setMouse(RelativeAnalogStickMouse.getDefault()); } else if ( analogStickStatus == 2 ) { remote.setMouse(new AbsoluteAnalogStickMouse(1, 1, AnalogStickMouse.CLASSIC_CONTROLLER_LEFT)); } else if ( analogStickStatus == 3 ) { remote.setMouse(new RelativeAnalogStickMouse(10, 10, 0.05, 0.05, AnalogStickMouse.CLASSIC_CONTROLLER_LEFT)); } else if ( analogStickStatus == 4 ) { remote.setMouse(new AbsoluteAnalogStickMouse(1, 1, AnalogStickMouse.CLASSIC_CONTROLLER_RIGHT)); } else if ( analogStickStatus == 5 ) { remote.setMouse(new RelativeAnalogStickMouse(10, 10, 0.05, 0.05, AnalogStickMouse.CLASSIC_CONTROLLER_RIGHT)); } } mouseTestPanel.repaint(); } catch ( Exception e ) { e.printStackTrace(); } } public void buttonInputReceived(WRButtonEvent evt) { if ( evt.wasPressed(WRButtonEvent.TWO) ) { System.out.println("2"); } if ( evt.wasPressed(WRButtonEvent.ONE) ) { System.out.println("1"); } if ( evt.wasPressed(WRButtonEvent.B) ) { System.out.println("B"); } if ( evt.wasPressed(WRButtonEvent.A) ) { System.out.println("A"); } if ( evt.wasPressed(WRButtonEvent.MINUS) ) { System.out.println("Minus"); } if ( evt.wasPressed(WRButtonEvent.HOME) ) { System.out.println("Home"); } if ( evt.wasPressed(WRButtonEvent.LEFT) ) { System.out.println("Left"); } if ( evt.wasPressed(WRButtonEvent.RIGHT) ) { System.out.println("Right"); } if ( evt.wasPressed(WRButtonEvent.DOWN) ) { System.out.println("Down"); } if ( evt.wasPressed(WRButtonEvent.UP) ) { System.out.println("Up"); } if ( evt.wasPressed(WRButtonEvent.PLUS) ) { System.out.println("Plus"); } try { //if (evt.isPressed(WRButtonEvent.MINUS) && evt.wasPressed(WRButtonEvent.PLUS)) //System.out.println("Avg Tardiness: " + remote.totalTardiness/remote.reportsProcessed); if ( evt.isPressed(WRButtonEvent.HOME) ) { boolean lightChanged = false; if ( evt.wasPressed(WRButtonEvent.PLUS) && !mouseTestingOn ) { mouseTestingOn = true; remote.getButtonMaps().add(new ButtonMouseMap(WRButtonEvent.B, java.awt.event.InputEvent.BUTTON1_MASK)); remote.getButtonMaps().add(new ButtonMouseMap(WRButtonEvent.A, java.awt.event.InputEvent.BUTTON3_MASK)); remote.getButtonMaps().add(new ButtonMouseWheelMap(WRButtonEvent.UP, -5, 100)); remote.getButtonMaps().add(new ButtonMouseWheelMap(WRButtonEvent.DOWN, 5, 100)); mouseTestFrame.setVisible(true); mouseCycle(); } else if ( evt.wasPressed(WRButtonEvent.MINUS) && mouseTestingOn ) { mouseTestingOn = false; remote.getButtonMaps().remove(new ButtonMouseMap(WRButtonEvent.B, java.awt.event.InputEvent.BUTTON1_MASK)); remote.getButtonMaps().remove(new ButtonMouseMap(WRButtonEvent.A, java.awt.event.InputEvent.BUTTON3_MASK)); remote.getButtonMaps().remove(new ButtonMouseWheelMap(WRButtonEvent.UP, -5, 100)); remote.getButtonMaps().remove(new ButtonMouseWheelMap(WRButtonEvent.DOWN, 5, 100)); mouseTestFrame.setVisible(false); remote.setMouse(null); } else if ( evt.wasPressed(WRButtonEvent.ONE) ) { accelerometerSource = !accelerometerSource; if (accelerometerSource)graphFrame.setTitle("Accelerometer graph: Wii Remote"); else graphFrame.setTitle("Accelerometer graph: Nunchuk"); } else if ( evt.wasPressed(WRButtonEvent.TWO) ) { // Code for Wii Remote memory dump/comparison Thread thread = new Thread(new MyFileThread(this)); thread.start(); } else if ( mouseTestingOn ) { boolean change = false; if ( evt.wasPressed(WRButtonEvent.HOME+WRButtonEvent.RIGHT) ) { status = (status+1)%4; change = true; } else if ( evt.wasPressed(WRButtonEvent.HOME+WRButtonEvent.LEFT) ) { status = (status+3)%4; change = true; } if ( status == 0 ) { if ( evt.wasPressed(WRButtonEvent.DOWN) ) { accelerometerStatus = (accelerometerStatus+1)%4; change = true; } else if ( evt.wasPressed(WRButtonEvent.UP) ) { accelerometerStatus = (accelerometerStatus+3)%4; change = true; } } else if ( status == 3 ) { if ( evt.wasPressed(WRButtonEvent.DOWN) ) { analogStickStatus = (analogStickStatus+1)%6; change = true; } else if (evt.wasPressed(WRButtonEvent.UP)) { analogStickStatus = (analogStickStatus+5)%6; change = true; } } if ( change ) { mouseCycle(); } } } else if ( evt.wasPressed(WRButtonEvent.TWO) ) { remote.requestStatus(); if ( remote.isPlayingSound() ) { remote.stopSound(); } } else if ( evt.wasPressed(WRButtonEvent.ONE) ) { if ( prebuf != null ) { remote.playPrebufferedSound(prebuf, WiiRemote.SF_PCM8S); } } else if ( evt.wasPressed(WRButtonEvent.PLUS) ) { if ( remote.isSpeakerEnabled() ) { double volume = (remote.getSpeakerVolume()*20+1)/20; if ( volume <= 1 ) { remote.setSpeakerVolume(volume); } System.out.println("Volume: " + remote.getSpeakerVolume()); } } else if ( evt.wasPressed(WRButtonEvent.MINUS) ) { if ( remote.isSpeakerEnabled() ) { double volume = (remote.getSpeakerVolume()*20-1)/20; if ( volume >= 0 ) { remote.setSpeakerVolume(volume); } System.out.println("Volume: " + remote.getSpeakerVolume()); } } } catch( Exception e ) { e.printStackTrace(); } } }//===========================================================================//= EOF =//===========================================================================
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -