Use the HID usage for the button as the button number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/src/joystick/bsd/SDL_bsdjoystick.c b/src/joystick/bsd/SDL_bsdjoystick.c
index 7c0e0c3..59780d2 100644
--- a/src/joystick/bsd/SDL_bsdjoystick.c
+++ b/src/joystick/bsd/SDL_bsdjoystick.c
@@ -229,7 +229,7 @@ static void report_free(struct report *);
static int
-usage_to_joyaxe(unsigned usage)
+usage_to_joyaxe(int usage)
{
int joyaxe;
switch (usage) {
@@ -365,7 +365,7 @@ CreateHwData(const char *path)
switch (HID_PAGE(hitem.usage)) {
case HUP_GENERIC_DESKTOP:
{
- unsigned usage = HID_USAGE(hitem.usage);
+ int usage = HID_USAGE(hitem.usage);
int joyaxe = usage_to_joyaxe(usage);
if (joyaxe >= 0) {
hw->axis_map[joyaxe] = 1;
@@ -379,7 +379,12 @@ CreateHwData(const char *path)
break;
}
case HUP_BUTTON:
- hw->nbuttons++;
+ {
+ int usage = HID_USAGE(hitem.usage);
+ if (usage > hw->nbuttons) {
+ hw->nbuttons = usage;
+ }
+ }
break;
default:
break;
@@ -652,7 +657,6 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
Sint32 v;
#ifdef __OpenBSD__
Sint32 dpad[4] = {0, 0, 0, 0};
- int actualbutton;
#endif
#ifdef SUPPORT_JOY_GAMEPORT
@@ -715,13 +719,13 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
continue;
}
- for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
+ while (hid_get_item(hdata, &hitem) > 0) {
switch (hitem.kind) {
case hid_input:
switch (HID_PAGE(hitem.usage)) {
case HUP_GENERIC_DESKTOP:
{
- unsigned usage = HID_USAGE(hitem.usage);
+ int usage = HID_USAGE(hitem.usage);
int joyaxe = usage_to_joyaxe(usage);
if (joyaxe >= 0) {
naxe = joy->hwdata->axis_map[joyaxe];
@@ -773,13 +777,8 @@ BSD_JoystickUpdate(SDL_Joystick *joy)
}
case HUP_BUTTON:
v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
-#ifdef __OpenBSD__
- actualbutton = HID_USAGE(hitem.usage) - 1; /* sdl buttons are zero-based */
- SDL_PrivateJoystickButton(joy, actualbutton, v);
-#else
+ nbutton = HID_USAGE(hitem.usage) - 1; /* SDL buttons are zero-based */
SDL_PrivateJoystickButton(joy, nbutton, v);
-#endif
- nbutton++;
break;
default:
continue;