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:
@@ -45,7 +45,6 @@ public class Tests implements WiimoteListener {
|
|||||||
|
|
||||||
private static int nb = 0;
|
private static int nb = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void wiimoteEvent(WiiMoteEvent e) {
|
public void wiimoteEvent(WiiMoteEvent e) {
|
||||||
System.out.println("Number of events : "+nb++);
|
System.out.println("Number of events : "+nb++);
|
||||||
if (dump == DISPLAY_EACH_VALUE) {
|
if (dump == DISPLAY_EACH_VALUE) {
|
||||||
@@ -354,13 +353,11 @@ public class Tests implements WiimoteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void statusEvent(StatusEvent e) {
|
public void statusEvent(StatusEvent e) {
|
||||||
//Display status variables
|
//Display status variables
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnectionEvent(DisconnectionEvent e) {
|
public void disconnectionEvent(DisconnectionEvent e) {
|
||||||
System.out.println(e.getWiimoteId()+" notify it's been disconnected !!");
|
System.out.println(e.getWiimoteId()+" notify it's been disconnected !!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,7 +321,30 @@ public class WiiUseApiManager extends Thread {
|
|||||||
EventsGatherer gather = new EventsGatherer(nbMaxWiimotes);
|
EventsGatherer gather = new EventsGatherer(nbMaxWiimotes);
|
||||||
|
|
||||||
// Start polling and tell the observers when there Wiimote events
|
// 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();
|
WiiUseApiRequest req = requests.poll();
|
||||||
if (req != null) {// there is a request for the wiiuse api
|
if (req != null) {// there is a request for the wiiuse api
|
||||||
int id = req.getId();
|
int id = req.getId();
|
||||||
@@ -393,27 +416,6 @@ public class WiiUseApiManager extends Thread {
|
|||||||
System.out.println("Bad request to Wiiuse API !!!!!");
|
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 {
|
} else {
|
||||||
if (connected <= 0) {
|
if (connected <= 0) {
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
manager.getStatus(id);
|
manager.getStatus(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void wiiUseApiEvent(WiiUseApiEvent e) {
|
public void wiiUseApiEvent(WiiUseApiEvent e) {
|
||||||
if (e.getWiimoteId() == id){
|
if (e.getWiimoteId() == id){
|
||||||
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){
|
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){
|
||||||
|
|||||||
Reference in New Issue
Block a user