added wiipair, allowing for permanent pairing of wiimotes. Modified WiimoteDevice to stop using old WiimoteDiscovery method with wiiscan.

This commit is contained in:
2013-03-22 16:55:38 +01:00
parent 993888ac41
commit b7556aaf72
3 changed files with 21 additions and 21 deletions

BIN
java/WiiPair.exe Normal file

Binary file not shown.

View File

@@ -35,7 +35,6 @@ public class WiimoteDevice extends Component implements Device, GestureListener
protected static WiimoteService wiimoteService; protected static WiimoteService wiimoteService;
protected WiimoteTaskMapCycle taskMapCycle; protected WiimoteTaskMapCycle taskMapCycle;
protected WiimoteDiscovery wiimoteDiscovery;
protected Wiimote wiimote; protected Wiimote wiimote;
protected boolean connected; protected boolean connected;
protected GestureDevice gestureDevice; protected GestureDevice gestureDevice;
@@ -52,7 +51,6 @@ public class WiimoteDevice extends Component implements Device, GestureListener
public WiimoteDevice() { public WiimoteDevice() {
super(TITLE); super(TITLE);
taskMapCycle = new WiimoteTaskMapCycle(); taskMapCycle = new WiimoteTaskMapCycle();
wiimoteDiscovery = new WiimoteDiscovery(this);
gestureDevice = new GestureDevice(); gestureDevice = new GestureDevice();
gestureDevice.add(this); gestureDevice.add(this);
motionDevice = new MotionDevice(this); motionDevice = new MotionDevice(this);
@@ -62,14 +60,15 @@ public class WiimoteDevice extends Component implements Device, GestureListener
/* Worker */ /* Worker */
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
motionDevice.setRouter(router); if (wiimote == null) {
motionDevice.start(); motionDevice.setRouter(router);
parser(Action.ADD, taskMapCycle.player); motionDevice.start();
wiimote = null; parser(Action.ADD, taskMapCycle.player);
}
try { try {
connect(); connect();
} catch (DeviceNotFoundException e) { } catch (DeviceNotFoundException e) {
wiimoteDiscovery.start(); log.warn(e);
} }
super.activate(); super.activate();
} }
@@ -98,13 +97,9 @@ public class WiimoteDevice extends Component implements Device, GestureListener
protected void deactivate() throws DeactivateException { protected void deactivate() throws DeactivateException {
super.deactivate(); super.deactivate();
ledWorker.stop(); ledWorker.stop();
wiimoteDiscovery.stop();
motionDevice.stop(); motionDevice.stop();
if (disconnect) { if (disconnect && wiimote != null) {
if (wiimote != null) { wiimote.disconnect();
wiimote.disconnect();
}
wiimoteDiscovery.disconnect();
disconnect = false; disconnect = false;
} }
} }
@@ -117,7 +112,6 @@ public class WiimoteDevice extends Component implements Device, GestureListener
wiimote = null; wiimote = null;
} }
wiimoteService.exit(); wiimoteService.exit();
wiimoteDiscovery.exit();
motionDevice.exit(); motionDevice.exit();
} }
@@ -182,22 +176,24 @@ public class WiimoteDevice extends Component implements Device, GestureListener
public void feedback(Feedback feedback) { public void feedback(Feedback feedback) {
if (wiimote != null && active()) { if (wiimote != null && active()) {
//log.debug("Wiimote rumble feedback"); log.debug("Wiimote rumble feedback");
//wiimote.rumble(RUMBLE); wiimote.rumble(RUMBLE);
} }
} }
/* Connectivity */ /* Connectivity */
public synchronized void connect() throws DeviceNotFoundException { public synchronized void connect() throws DeviceNotFoundException {
wiimote = wiimoteService.getDevice(this); wiimote = wiimoteService.getDevice(this);
//wiimote.activateContinuous(); wiimote.activateContinuous();
wiimote.activateMotionSensing(); wiimote.activateMotionSensing();
wiimoteDiscovery.stop();
ledWorker.start(); ledWorker.start();
} }
/* Listeners */ /* Listeners */
public void onButtonsEvent(WiimoteButtonsEvent event) { public void onButtonsEvent(WiimoteButtonsEvent event) {
if (!active) {
return;
}
int pressed = event.getButtonsJustPressed() - event.getButtonsHeld(); int pressed = event.getButtonsJustPressed() - event.getButtonsHeld();
int released = event.getButtonsJustReleased(); int released = event.getButtonsJustReleased();
try { try {
@@ -214,6 +210,9 @@ public class WiimoteDevice extends Component implements Device, GestureListener
} }
public void onMotionSensingEvent(MotionSensingEvent event) { public void onMotionSensingEvent(MotionSensingEvent event) {
if (!active) {
return;
}
gestureDevice.add(event.getGforce()); gestureDevice.add(event.getGforce());
motionDevice.add(event); motionDevice.add(event);
} }

View File

@@ -30,12 +30,12 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
public class WiimoteService extends WiiUseApiManager implements WiimoteListener { public class WiimoteService extends WiiUseApiManager implements WiimoteListener {
protected Log log = LogFactory.getLog(getClass()); protected Log log = LogFactory.getLog(getClass());
public static void main(String[] args) { /*public static void main(String[] args) {
Log log = LogFactory.getLog(WiimoteService.class); Log log = LogFactory.getLog(WiimoteService.class);
for (Wiimote wm : WiiUseApiManager.getWiimotes(1, false)) { for (Wiimote wm : WiiUseApiManager.getWiimotes(1, false)) {
log.debug(wm); log.debug(wm);
} }
} }*/
protected final boolean RUMBLE = false; protected final boolean RUMBLE = false;
@@ -81,10 +81,11 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
} }
public void onButtonsEvent(WiimoteButtonsEvent event) { public void onButtonsEvent(WiimoteButtonsEvent event) {
getWiimoteDevice(event).onButtonsEvent(event); getWiimoteDevice(event).onButtonsEvent(event);
} }
public void onMotionSensingEvent(MotionSensingEvent event) { public void onMotionSensingEvent(MotionSensingEvent event) {
getWiimoteDevice(event).onMotionSensingEvent(event); getWiimoteDevice(event).onMotionSensingEvent(event);
} }