Merge pull request #144 from bucko909/master

Properly handle Linux event device button numbers
This commit is contained in:
Colby Klein
2014-04-28 23:56:17 -07:00
@@ -386,9 +386,18 @@ void InputHandler_Linux_Event::InputThread()
switch (event.type) { switch (event.type) {
case EV_KEY: { case EV_KEY: {
int iNum = event.code; int iNum;
// In 2.6.11 using an EMS USB2, the event number for P1 Tri (the first button) if (event.code >= BTN_JOYSTICK && event.code <= BTN_JOYSTICK + 0xf) {
// is being reported as 32 instead of 0. Correct for this. // These guys have arbitrary names, but the kernel code in hid-input.c maps exactly 0xf of them.
iNum = event.code - BTN_JOYSTICK;
} else if (event.code >= BTN_TRIGGER_HAPPY1 && event.code <= BTN_TRIGGER_HAPPY40) {
// Actually, we only have 32 buttons defined.
iNum = event.code - BTN_TRIGGER_HAPPY1 + 0x10;
} else {
// If the button number is >40+0xf, it gets mapped to a code with no #define.
// I don't know if this is appropriate at all, but what else to do?
iNum = event.code;
}
wrap( iNum, 32 ); // max number of joystick buttons. Make this a constant? wrap( iNum, 32 ); // max number of joystick buttons. Make this a constant?
ButtonPressed( DeviceInput(g_apEventDevices[i]->m_Dev, enum_add2(JOY_BUTTON_1, iNum), event.value != 0, now) ); ButtonPressed( DeviceInput(g_apEventDevices[i]->m_Dev, enum_add2(JOY_BUTTON_1, iNum), event.value != 0, now) );
break; break;