Add fault-tolerance to kpad driver

== DETAILS

So, the KPadRead function will sometimes return 0, but this doesn't mean
the wiimote is actually disconnected. It's usually something transient, like
the BT chip has nothing to send or whatever. I don't know.

So, I added a buffer so that it won't disconnect the pad without 5
consecutive 0-reads.

This is a temporary hack; a proper solution will use the Wii U's callback
mechanisms to do wiimote detection. But that's a separate project. This at
least prevents OSD spam.

== TESTING

Tested locally. Verified that connecting/disconnecting nunchuk during play
still works properly.
This commit is contained in:
gblues 2018-04-24 21:46:42 -07:00
parent f33fa3d566
commit 07864aebb4

View File

@ -206,6 +206,8 @@ static void kpad_deregister(unsigned channel)
}
}
static int poll_failures[WIIU_WIIMOTE_CHANNELS] = { 0, 0, 0, 0 };
static void kpad_poll(void)
{
unsigned channel;
@ -217,10 +219,16 @@ static void kpad_poll(void)
memset(&kpad, 0, sizeof(kpad));
result = KPADRead(channel, &kpad, 1);
/* this is a hack to prevent spurious disconnects */
/* TODO: use KPADSetConnectCallback and use callbacks to detect */
/* pad disconnects properly. */
if (result == 0) {
kpad_deregister(channel);
poll_failures[channel]++;
if(poll_failures[channel] > 5)
kpad_deregister(channel);
continue;
}
poll_failures[channel] = 0;
kpad_poll_one_channel(channel, &kpad);
}