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