Fix multiple virtual wheel events with noisy input

Prior to this change, the x52d virtual mouse logic was assuming that the
joystick would only send one report with the wheel button state as "on",
and subsequent reports would be "off". However, with some joysticks, the
other axis sensors could be faulty or noisy, and the joystick could send
multiple reports with the mouse button "on", without an "off" state in
between. This was causing scroll events to be much faster than would be
expected (1 mouse scroll to 1 screen scroll event)

This change should fix the problem, by comparing the value of the
previous button state. This should now trigger a wheel event only on a
rising edge (from "off" to "on").

See #46
fix-multiple-scroll-events
nirenjan 2023-03-18 00:43:17 -07:00
parent 0870518598
commit aa95ed306f
3 changed files with 22 additions and 20 deletions

View File

@ -52,13 +52,15 @@ static int report_wheel(void)
{ {
int rc = 1; int rc = 1;
int wheel = 0; int wheel = 0;
bool old_scroll_up = old_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP];
bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP]; bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP];
bool old_scroll_dn = old_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN];
bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN]; bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN];
if (scroll_up) { if (scroll_up && (scroll_up != old_scroll_up)) {
// Scroll up event // Scroll up event
wheel = 1 * mouse_scroll_dir; wheel = 1 * mouse_scroll_dir;
} else if (scroll_dn) { } else if (scroll_dn && (scroll_dn != old_scroll_dn)) {
// Scroll down event // Scroll down event
wheel = -1 * mouse_scroll_dir; wheel = -1 * mouse_scroll_dir;
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: libx52 0.3.0\n" "Project-Id-Version: libx52 0.3.0\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2023-01-04 08:39-0800\n" "POT-Creation-Date: 2023-03-18 00:49-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -861,38 +861,38 @@ msgstr ""
msgid "Error writing mouse button event (button %d, state %d)" msgid "Error writing mouse button event (button %d, state %d)"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:69 #: daemon/x52d_mouse_evdev.c:71
#, c-format #, c-format
msgid "Error writing mouse wheel event %d" msgid "Error writing mouse wheel event %d"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:102 #: daemon/x52d_mouse_evdev.c:104
#, c-format #, c-format
msgid "Error writing mouse axis event (axis %d, value %d)" msgid "Error writing mouse axis event (axis %d, value %d)"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:115 #: daemon/x52d_mouse_evdev.c:117
msgid "Error writing mouse sync event" msgid "Error writing mouse sync event"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:134 #: daemon/x52d_mouse_evdev.c:136
msgid "Starting X52 virtual mouse driver thread" msgid "Starting X52 virtual mouse driver thread"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:157 #: daemon/x52d_mouse_evdev.c:159
#, c-format #, c-format
msgid "Error %d initializing mouse thread: %s" msgid "Error %d initializing mouse thread: %s"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:164 #: daemon/x52d_mouse_evdev.c:166
msgid "Shutting down X52 virtual mouse driver thread" msgid "Shutting down X52 virtual mouse driver thread"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:171 #: daemon/x52d_mouse_evdev.c:173
msgid "Virtual mouse not created. Ignoring thread state change" msgid "Virtual mouse not created. Ignoring thread state change"
msgstr "" msgstr ""
#: daemon/x52d_mouse_evdev.c:236 #: daemon/x52d_mouse_evdev.c:238
#, c-format #, c-format
msgid "Error %d creating X52 virtual mouse: %s" msgid "Error %d creating X52 virtual mouse: %s"
msgstr "" msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: libx52 0.2.3\n" "Project-Id-Version: libx52 0.2.3\n"
"Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n" "Report-Msgid-Bugs-To: https://github.com/nirenjan/libx52/issues\n"
"POT-Creation-Date: 2023-01-04 08:39-0800\n" "POT-Creation-Date: 2023-03-18 00:49-0700\n"
"PO-Revision-Date: 2023-01-04 08:40-0800\n" "PO-Revision-Date: 2023-01-04 08:40-0800\n"
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n" "Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
"Language-Team: Dummy Language for testing i18n\n" "Language-Team: Dummy Language for testing i18n\n"
@ -914,38 +914,38 @@ msgstr "Ettingsay ousemay everseray ollscray otay %s"
msgid "Error writing mouse button event (button %d, state %d)" msgid "Error writing mouse button event (button %d, state %d)"
msgstr "Erroray itingwray ousemay uttonbay eventay (uttonbay %d, atestay %d)" msgstr "Erroray itingwray ousemay uttonbay eventay (uttonbay %d, atestay %d)"
#: daemon/x52d_mouse_evdev.c:69 #: daemon/x52d_mouse_evdev.c:71
#, c-format #, c-format
msgid "Error writing mouse wheel event %d" msgid "Error writing mouse wheel event %d"
msgstr "Erroray itingwray ousemay eelwhay eventay %d" msgstr "Erroray itingwray ousemay eelwhay eventay %d"
#: daemon/x52d_mouse_evdev.c:102 #: daemon/x52d_mouse_evdev.c:104
#, c-format #, c-format
msgid "Error writing mouse axis event (axis %d, value %d)" msgid "Error writing mouse axis event (axis %d, value %d)"
msgstr "Erroray itingwray ousemay axisay eventay (axisay %d, aluevay %d)" msgstr "Erroray itingwray ousemay axisay eventay (axisay %d, aluevay %d)"
#: daemon/x52d_mouse_evdev.c:115 #: daemon/x52d_mouse_evdev.c:117
msgid "Error writing mouse sync event" msgid "Error writing mouse sync event"
msgstr "Erroray itingwray ousemay yncsay eventay" msgstr "Erroray itingwray ousemay yncsay eventay"
#: daemon/x52d_mouse_evdev.c:134 #: daemon/x52d_mouse_evdev.c:136
msgid "Starting X52 virtual mouse driver thread" msgid "Starting X52 virtual mouse driver thread"
msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray" msgstr "Artingstay X52 irtualvay ousemay iverdray eadthray"
#: daemon/x52d_mouse_evdev.c:157 #: daemon/x52d_mouse_evdev.c:159
#, c-format #, c-format
msgid "Error %d initializing mouse thread: %s" msgid "Error %d initializing mouse thread: %s"
msgstr "Erroray %d initializingay ousemay eadthray: %s" msgstr "Erroray %d initializingay ousemay eadthray: %s"
#: daemon/x52d_mouse_evdev.c:164 #: daemon/x52d_mouse_evdev.c:166
msgid "Shutting down X52 virtual mouse driver thread" msgid "Shutting down X52 virtual mouse driver thread"
msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray" msgstr "Uttingshay ownday X52 irtualvay ousemay iverdray eadthray"
#: daemon/x52d_mouse_evdev.c:171 #: daemon/x52d_mouse_evdev.c:173
msgid "Virtual mouse not created. Ignoring thread state change" msgid "Virtual mouse not created. Ignoring thread state change"
msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay" msgstr "Irtualvay ousemay otnay eatedcray. Ignoringa eadthray atestay angechay"
#: daemon/x52d_mouse_evdev.c:236 #: daemon/x52d_mouse_evdev.c:238
#, c-format #, c-format
msgid "Error %d creating X52 virtual mouse: %s" msgid "Error %d creating X52 virtual mouse: %s"
msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s" msgstr "Erroray %d eatingcray X52 irtualvay ousemay: %s"