Add error counting (for controller swapping)

This commit is contained in:
Raphael Assenat 2015-10-31 15:58:53 -04:00
parent b10322a9d2
commit a56c4eef4e
1 changed files with 13 additions and 1 deletions

14
main.c
View File

@ -26,6 +26,7 @@
#include "reportdesc.c"
#include "dataHidReport.c"
#define MAX_READ_ERRORS 30
struct cfg0 {
struct usb_configuration_descriptor configdesc;
@ -269,6 +270,7 @@ int main(void)
gamepad_data pad_data;
unsigned char gamepad_vibrate = 0;
unsigned char state = STATE_WAIT_POLLTIME;
int error_count;
hwinit();
usart1_init();
@ -305,7 +307,17 @@ int main(void)
pad = detectPad();
}
if (pad) {
pad->update();
if (pad->update()) {
error_count++;
if (error_count > MAX_READ_ERRORS) {
pad = NULL;
state = STATE_WAIT_POLLTIME;
error_count = 0;
break;
}
} else {
error_count=0;
}
if (pad->changed()) {