From 2893d8cef8d8d57d31e207b130d8c8e693f91dcb Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Tue, 14 Jul 2020 19:53:08 -0700 Subject: [PATCH] device: Fix erroneous dpad_*-up events when emulating a dpad on Linux The first time axis are processed while a dpad axis is engaged will result in the opposite dpad "button" getting set to a state of S_up from S_unknown, which results in an '-up' event getting fired. Instead, assume the emulated dpad buttons start in a state of S_up. This fix is for the Joystick API and for the evdev API, but only the evdev changes were tested. Closes #973 --- panda/src/device/evdevInputDevice.cxx | 4 ++++ panda/src/device/linuxJoystickDevice.cxx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/panda/src/device/evdevInputDevice.cxx b/panda/src/device/evdevInputDevice.cxx index 26bb83186e..9407650898 100644 --- a/panda/src/device/evdevInputDevice.cxx +++ b/panda/src/device/evdevInputDevice.cxx @@ -595,6 +595,8 @@ init_device() { _buttons.push_back(ButtonState(GamepadButton::hat_left())); _buttons.push_back(ButtonState(GamepadButton::hat_right())); } + _buttons[_dpad_left_button]._state = S_up; + _buttons[_dpad_left_button+1]._state = S_up; } break; case ABS_HAT0Y: @@ -608,6 +610,8 @@ init_device() { _buttons.push_back(ButtonState(GamepadButton::hat_up())); _buttons.push_back(ButtonState(GamepadButton::hat_down())); } + _buttons[_dpad_up_button]._state = S_up; + _buttons[_dpad_up_button+1]._state = S_up; } break; case ABS_HAT2X: diff --git a/panda/src/device/linuxJoystickDevice.cxx b/panda/src/device/linuxJoystickDevice.cxx index c964ea8499..697300adff 100644 --- a/panda/src/device/linuxJoystickDevice.cxx +++ b/panda/src/device/linuxJoystickDevice.cxx @@ -234,6 +234,8 @@ open_device() { add_button(GamepadButton::hat_left()); add_button(GamepadButton::hat_right()); } + _buttons[_dpad_left_button]._state = S_up; + _buttons[_dpad_left_button+1]._state = S_up; axis = Axis::none; } break; @@ -250,6 +252,8 @@ open_device() { add_button(GamepadButton::hat_up()); add_button(GamepadButton::hat_down()); } + _buttons[_dpad_up_button]._state = S_up; + _buttons[_dpad_up_button+1]._state = S_up; axis = Axis::none; } break;