Wiimote device netter gemaakt.
This commit is contained in:
@@ -16,7 +16,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
public class Manager<T extends Worker & Titled & Exitable> extends Worker {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
protected static final long serialVersionUID = 1L;
|
||||
protected static final int INTERVAL = 100;
|
||||
protected static final int INTERVAL = 500;
|
||||
|
||||
protected T[] manageableArray;
|
||||
protected Map<T, SelectButton<T>> buttonMap;
|
||||
|
||||
@@ -53,6 +53,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
|
||||
/* Activation */
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
connect();
|
||||
/*add(
|
||||
new Hold(WiimoteButton.A),
|
||||
@@ -175,14 +176,10 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
log.error(e);
|
||||
}
|
||||
if (wiimote == null) {
|
||||
wiimoteDiscovery.work();
|
||||
if (wiimote == null) {
|
||||
wiimoteDiscovery.disconnect();
|
||||
try {
|
||||
wiimoteDiscovery.activate();
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
try {
|
||||
wiimoteDiscovery.activate();
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,11 +190,8 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
//wiimote.activateMotionSensing();
|
||||
try {
|
||||
wiimoteDiscovery.deactivate();
|
||||
super.activate();
|
||||
} catch (DeactivateException e) {
|
||||
log.error(e);
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
} catch (DeviceNotFoundException e) {
|
||||
log.error(e);
|
||||
@@ -220,7 +214,6 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
|
||||
public boolean active() {
|
||||
if (wiimote != null) {
|
||||
log.debug("Check activity");
|
||||
connected = false;
|
||||
wiimote.getStatus();
|
||||
synchronized (this) {
|
||||
|
||||
@@ -4,9 +4,13 @@ import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import mimis.Worker;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
|
||||
public class WiimoteDiscovery extends Worker {
|
||||
protected WiimoteDevice wiimoteDevice;
|
||||
protected Process process;
|
||||
protected boolean disconnect;
|
||||
|
||||
public WiimoteDiscovery(WiimoteDevice wiimoteDevice) {
|
||||
this.wiimoteDevice = wiimoteDevice;
|
||||
@@ -23,7 +27,7 @@ public class WiimoteDiscovery extends Worker {
|
||||
public boolean execute(String parameters) {
|
||||
String command = "native/wiiscan.exe -l none " + parameters;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
Scanner scanner = new Scanner(process.getInputStream());
|
||||
while (scanner.hasNext()) {
|
||||
if (scanner.next().equals("[OK]")) {
|
||||
@@ -32,14 +36,30 @@ public class WiimoteDiscovery extends Worker {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
} finally {
|
||||
process =null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void work() {
|
||||
log.debug("Discover wiimotes");
|
||||
if (connect()) {
|
||||
wiimoteDevice.connected();
|
||||
} else if (disconnect) {
|
||||
disconnect();
|
||||
}
|
||||
disconnect = false;
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
disconnect = true;
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user