diff --git a/WiiUseJ/src/tests/Tests.java b/WiiUseJ/src/tests/Tests.java index 1979759..71d2e44 100644 --- a/WiiUseJ/src/tests/Tests.java +++ b/WiiUseJ/src/tests/Tests.java @@ -45,7 +45,6 @@ public class Tests implements WiimoteListener { private static int nb = 0; - @Override public void wiimoteEvent(WiiMoteEvent e) { System.out.println("Number of events : "+nb++); if (dump == DISPLAY_EACH_VALUE) { @@ -354,13 +353,11 @@ public class Tests implements WiimoteListener { } } - @Override public void statusEvent(StatusEvent e) { //Display status variables System.out.println(e); } - @Override public void disconnectionEvent(DisconnectionEvent e) { System.out.println(e.getWiimoteId()+" notify it's been disconnected !!"); } diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index d5c3d2e..6d4b8b4 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -98,7 +98,7 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote to disconnect. */ - public void closeConnection(int id) { + public void closeConnection(int id) { removeWiiUseApiListener(wiimotes[id-1]); wiimotes[id-1] = null; requests.add(new WiiUseApiRequest(id, @@ -321,7 +321,30 @@ public class WiiUseApiManager extends Thread { EventsGatherer gather = new EventsGatherer(nbMaxWiimotes); // Start polling and tell the observers when there Wiimote events - while (running.get()) { + while (running.get() && connected > 0) { + + /* Polling */ + wiiuse.specialPoll(gather); + + /* deal with events gathered in Wiiuse API */ + for (WiiUseApiEvent evt : gather.getEvents()) { + if (evt.getWiimoteId() != -1) {// event filled + // there is an event notify observers + notifyWiiUseApiListener(evt); + if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) { + // check if it was a disconnection + // in this case disconnect the wiimote + closeConnection(evt.getWiimoteId()); + } + } else { + System.out + .println("There is an event with id == -1 ??? there is a problem !!! : " + + evt); + } + } + gather.clearEvents(); + + /* deal with request done to wiiuse API*/ WiiUseApiRequest req = requests.poll(); if (req != null) {// there is a request for the wiiuse api int id = req.getId(); @@ -393,27 +416,6 @@ public class WiiUseApiManager extends Thread { System.out.println("Bad request to Wiiuse API !!!!!"); } } - - /* Polling */ - wiiuse.specialPoll(gather); - - /* deal with events gathered in Wiiuse API */ - for (WiiUseApiEvent evt : gather.getEvents()) { - if (evt.getWiimoteId() != -1) {// event filled - // there is an event notify observers - notifyWiiUseApiListener(evt); - if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) { - // check if it was a disconnection - // in this case disconnect the wiimote - closeConnection(evt.getWiimoteId()); - } - } else { - System.out - .println("There is an event with id == -1 ??? there is a problem !!! : " - + evt); - } - } - gather.clearEvents(); } } else { if (connected <= 0) { diff --git a/WiiUseJ/src/wiiusej/Wiimote.java b/WiiUseJ/src/wiiusej/Wiimote.java index e85a0cc..66a95e4 100644 --- a/WiiUseJ/src/wiiusej/Wiimote.java +++ b/WiiUseJ/src/wiiusej/Wiimote.java @@ -166,7 +166,6 @@ public class Wiimote implements WiiUseApiListener { manager.getStatus(id); } - @Override public void wiiUseApiEvent(WiiUseApiEvent e) { if (e.getWiimoteId() == id){ if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){