summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSonicadvance1 <sonicadvance1@gmail.com>2009-06-22 10:11:31 +0000
committerSonicadvance1 <sonicadvance1@gmail.com>2009-06-22 10:11:31 +0000
commitcbff6dfde35bb27c08e352370236aad23eeb38b3 (patch)
tree8b00df20f4d5e8b34dc42250237e2b5150733cc0
parentc14548c8dbff4b4b471ee9a888421e866d5d5610 (diff)
Get Wiimote working in Linux, events.c works the same under Linux as OSX, Windows strips the first byte of the packet? Probably should be handled in WiiUse instead of our code
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3535 8ced0084-cf51-0410-be5f-012b33b47a6e
-rw-r--r--Externals/WiiUseSrc/Src/events.c110
-rw-r--r--Externals/WiiUseSrc/Src/io_nix.c68
2 files changed, 57 insertions, 121 deletions
diff --git a/Externals/WiiUseSrc/Src/events.c b/Externals/WiiUseSrc/Src/events.c
index 63269e52c5..7323350960 100644
--- a/Externals/WiiUseSrc/Src/events.c
+++ b/Externals/WiiUseSrc/Src/events.c
@@ -85,113 +85,25 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
int evnt = 0;
#ifndef WIN32
- #if defined(__APPLE__)
-
- int i;
-
- if (!wm)
- return 0;
-
- for (i = 0; i < wiimotes; ++i) {
- wm[i]->event = WIIUSE_NONE;
-
- if (wiiuse_io_read(wm[i])) {
- /* propagate the event */
- propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
- evnt += (wm[i]->event != WIIUSE_NONE);
-
- /* clear out the event buffer */
- memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
- } else {
- idle_cycle(wm[i]);
- }
- }
-
- #else
- /*
- * *nix
- */
- struct timeval tv;
- fd_set fds;
- int r;
int i;
- int highest_fd = -1;
- if (!wm) return 0;
-
- /* block select() for 1/2000th of a second */
- tv.tv_sec = 0;
- tv.tv_usec = 500;
-
- FD_ZERO(&fds);
+ if (!wm)
+ return 0;
for (i = 0; i < wiimotes; ++i) {
- /* only poll it if it is connected */
- if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
- FD_SET(wm[i]->in_sock, &fds);
+ wm[i]->event = WIIUSE_NONE;
- /* find the highest fd of the connected wiimotes */
- if (wm[i]->in_sock > highest_fd)
- highest_fd = wm[i]->in_sock;
- }
+ if (wiiuse_io_read(wm[i])) {
+ /* propagate the event */
+ propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
+ evnt += (wm[i]->event != WIIUSE_NONE);
- wm[i]->event = WIIUSE_NONE;
- }
-
- if (highest_fd == -1)
- /* nothing to poll */
- return 0;
-
- if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
- WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
- perror("Error Details");
- return 0;
- }
-
- /* check each socket for an event */
- for (i = 0; i < wiimotes; ++i) {
- /* if this wiimote is not connected, skip it */
- if (!WIIMOTE_IS_CONNECTED(wm[i]))
- continue;
-
- if (FD_ISSET(wm[i]->in_sock, &fds)) {
- /* clear out the event buffer */
- memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
-
- /* clear out any old read requests */
- clear_dirty_reads(wm[i]);
-
- /* read the pending message into the buffer */
- r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
- if (r == -1) {
- /* error reading data */
- WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
- perror("Error Details");
-
- if (errno == ENOTCONN) {
- /* this can happen if the bluetooth dongle is disconnected */
- WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid);
- wiiuse_disconnect(wm[i]);
- wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT;
- }
-
- continue;
+ /* clear out the event buffer */
+ memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
+ } else {
+ idle_cycle(wm[i]);
}
- if (!r) {
- /* remote disconnect */
- wiiuse_disconnected(wm[i]);
- evnt = 1;
- continue;
- }
-
- /* propagate the event */
- propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
- evnt += (wm[i]->event != WIIUSE_NONE);
- } else {
- idle_cycle(wm[i]);
- }
}
- #endif
#else
/*
* Windows
diff --git a/Externals/WiiUseSrc/Src/io_nix.c b/Externals/WiiUseSrc/Src/io_nix.c
index 4ccd984050..2fededf611 100644
--- a/Externals/WiiUseSrc/Src/io_nix.c
+++ b/Externals/WiiUseSrc/Src/io_nix.c
@@ -268,37 +268,61 @@ int wiiuse_io_read(struct wiimote_t* wm) {
WIIUSE_INFO("Wiimote is Null0x%x\n", wm);
return 0;
}
- /*
- * *nix
- */
+
+ struct timeval tv;
+ fd_set fds;
int r;
int i;
+ if (!wm) return 0;
- /* read the pending message into the buffer */
- r = read(wm->in_sock, wm->event_buf, sizeof(wm->event_buf));
- if (r == -1)
- {
- /* error reading data */
- WIIUSE_INFO("Receiving wiimote data (id %i).", wm->unid);
- perror("Error Details");
+ /* block select() for 1/2000th of a second */
+ tv.tv_sec = 0;
+ tv.tv_usec = 500;
- if (errno == ENOTCONN) {
- /* this can happen if the bluetooth dongle is disconnected */
- WIIUSE_INFO("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid);
- wiiuse_disconnect(wm);
- wm->event = WIIUSE_UNEXPECTED_DISCONNECT;
- }
+ FD_ZERO(&fds);
+ /* only poll it if it is connected */
+ if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) {
+ FD_SET(wm->in_sock, &fds);
+ //highest_fd = wm[i]->in_sock;
+ }
+ else
+ /* nothing to poll */
+ return 0;
+ if (select(wm->in_sock + 1, &fds, NULL, NULL, &tv) == -1) {
+ WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
+ perror("Error Details");
return 0;
}
- //WIIUSE_INFO("Size %d, first 4 0x%02X%02X%02X%02X\n",r, wm->event_buf[0],wm->event_buf[1], wm->event_buf[2],wm->event_buf[3]);
- if (!r) {
- /* remote disconnect */
- WIIUSE_INFO("Wiimote Disconnect\n");
- wiiuse_disconnected(wm);
+
+ /* if this wiimote is not connected, skip it */
+ if (!WIIMOTE_IS_CONNECTED(wm))
return 0;
+
+ if (FD_ISSET(wm->in_sock, &fds))
+ {
+ /* read the pending message into the buffer */
+ r = read(wm->in_sock, wm->event_buf, sizeof(wm->event_buf));
+ if (r == -1) {
+ /* error reading data */
+ WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
+ perror("Error Details");
+
+ if (errno == ENOTCONN) {
+ /* this can happen if the bluetooth dongle is disconnected */
+ WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid);
+ wiiuse_disconnect(wm);
+ wm->event = WIIUSE_UNEXPECTED_DISCONNECT;
+ }
+
+ return 0;
+ }
+ if (!r) {
+ /* remote disconnect */
+ wiiuse_disconnected(wm);
+ return 0;
+ }
}
-
return 1;
}