From d7038fea173f79b26e432a2fb7b82c6d23cf88ce Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Thu, 26 Mar 2009 03:07:12 +0000 Subject: [PATCH] Made wiiuse_io_read work under Linux. still no Wiimote working under linux though, which Im not quite sure why. the mode seems to get set most of the time. Maybe mine is blocking? git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2755 8ced0084-cf51-0410-be5f-012b33b47a6e --- Externals/WiiUseSrc/Src/io_nix.c | 47 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/Externals/WiiUseSrc/Src/io_nix.c b/Externals/WiiUseSrc/Src/io_nix.c index ec4e0e1780..b764083a73 100644 --- a/Externals/WiiUseSrc/Src/io_nix.c +++ b/Externals/WiiUseSrc/Src/io_nix.c @@ -33,6 +33,12 @@ #ifndef WIN32 +#include +#include + +#include +#include +#include #include #include #include @@ -253,11 +259,44 @@ void wiiuse_disconnect(struct wiimote_t* wm) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); } - - int wiiuse_io_read(struct wiimote_t* wm) { - /* not used */ - return 0; + if (!wm) + { + printf("Wiimote is Null0x%x\n", wm); + return 0; + } + /* + * *nix + */ + int r; + int i; + + /* 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 */ + printf("Receiving wiimote data (id %i).", wm->unid); + perror("Error Details"); + + if (errno == ENOTCONN) { + /* this can happen if the bluetooth dongle is disconnected */ + printf("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid); + wiiuse_disconnect(wm); + wm->event = WIIUSE_UNEXPECTED_DISCONNECT; + } + + return 0; + } + //printf("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 */ + printf("Wiimote Disconnect\n"); + wiiuse_disconnected(wm); + return 0; + } + + return 1; }