Skip to content

Commit

Permalink
Detect non-standard joystick buttons
Browse files Browse the repository at this point in the history
The Xbox One S controller when connected via Bluetooth
is exposing its select button with the Linux KEY_BACK
code, which is outside of the normal input code
scan range for joysticks.  This patch adds additional
scanning to pick up such extra buttons, and adds
them as buttons after the normal ranges to preserve
compatibility with existing key mappings.
  • Loading branch information
daviderickson committed Feb 24, 2017
1 parent 3ae52e2 commit da8662b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion input/drivers_joypad/udev_joypad.c
Expand Up @@ -118,7 +118,7 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
switch (events[i].type)
{
case EV_KEY:
if (code >= BTN_MISC || (code >= KEY_UP && code <= KEY_DOWN))
if (code >= 0 && code < KEY_MAX)
{
if (events[i].value)
BIT64_SET(pad->buttons, pad->button_bind[code]);
Expand Down Expand Up @@ -253,6 +253,15 @@ static int udev_add_pad(struct udev_device *dev, unsigned p, int fd, const char
for (i = BTN_MISC; i < KEY_MAX && buttons < UDEV_NUM_BUTTONS; i++)
if (test_bit(i, keybit))
pad->button_bind[i] = buttons++;
/* The following two ranges are scanned and added after the above
* ranges to maintain compatibility with existing key maps.
*/
for (i = 0; i < KEY_UP && buttons < UDEV_NUM_BUTTONS; i++)
if (test_bit(i, keybit))
pad->button_bind[i] = buttons++;
for (i = KEY_DOWN + 1; i < BTN_MISC && buttons < UDEV_NUM_BUTTONS; i++)
if (test_bit(i, keybit))
pad->button_bind[i] = buttons++;
for (i = 0; i < ABS_MISC && axes < NUM_AXES; i++)
{
/* Skip hats for now. */
Expand Down

0 comments on commit da8662b

Please sign in to comment.