fixed a bug on disconnection

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@61 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-02-21 23:01:15 +00:00
parent fbcd75095d
commit b2260afccf
3 changed files with 25 additions and 27 deletions

View File

@@ -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 !!");
}

View File

@@ -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) {

View File

@@ -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){