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

View File

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

View File

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