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
This commit is contained in:
parent
c14548c8db
commit
cbff6dfde3
|
@ -85,8 +85,6 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
|
||||||
int evnt = 0;
|
int evnt = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#if defined(__APPLE__)
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!wm)
|
if (!wm)
|
||||||
|
@ -106,92 +104,6 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
|
||||||
idle_cycle(wm[i]);
|
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
/* find the highest fd of the connected wiimotes */
|
|
||||||
if (wm[i]->in_sock > highest_fd)
|
|
||||||
highest_fd = wm[i]->in_sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
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
|
#else
|
||||||
/*
|
/*
|
||||||
* Windows
|
* Windows
|
||||||
|
|
|
@ -268,37 +268,61 @@ int wiiuse_io_read(struct wiimote_t* wm) {
|
||||||
WIIUSE_INFO("Wiimote is Null0x%x\n", wm);
|
WIIUSE_INFO("Wiimote is Null0x%x\n", wm);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* *nix
|
struct timeval tv;
|
||||||
*/
|
fd_set fds;
|
||||||
int r;
|
int r;
|
||||||
int i;
|
int i;
|
||||||
|
if (!wm) return 0;
|
||||||
|
|
||||||
|
/* block select() for 1/2000th of a second */
|
||||||
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 500;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 */
|
/* read the pending message into the buffer */
|
||||||
r = read(wm->in_sock, wm->event_buf, sizeof(wm->event_buf));
|
r = read(wm->in_sock, wm->event_buf, sizeof(wm->event_buf));
|
||||||
if (r == -1)
|
if (r == -1) {
|
||||||
{
|
|
||||||
/* error reading data */
|
/* error reading data */
|
||||||
WIIUSE_INFO("Receiving wiimote data (id %i).", wm->unid);
|
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid);
|
||||||
perror("Error Details");
|
perror("Error Details");
|
||||||
|
|
||||||
if (errno == ENOTCONN) {
|
if (errno == ENOTCONN) {
|
||||||
/* this can happen if the bluetooth dongle is disconnected */
|
/* 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_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid);
|
||||||
wiiuse_disconnect(wm);
|
wiiuse_disconnect(wm);
|
||||||
wm->event = WIIUSE_UNEXPECTED_DISCONNECT;
|
wm->event = WIIUSE_UNEXPECTED_DISCONNECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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) {
|
if (!r) {
|
||||||
/* remote disconnect */
|
/* remote disconnect */
|
||||||
WIIUSE_INFO("Wiimote Disconnect\n");
|
|
||||||
wiiuse_disconnected(wm);
|
wiiuse_disconnected(wm);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue