diff options
Diffstat (limited to 'Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c')
-rw-r--r-- | Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c b/Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c index 9408545..679b80c 100644 --- a/Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c +++ b/Source/3rdParty/SDL2/src/joystick/bsd/SDL_sysjoystick.c @@ -161,15 +161,18 @@ static void report_free(struct report *); #define REP_BUF_DATA(rep) ((rep)->buf->data) #endif -static int SDL_SYS_numjoysticks = 0; +static int numjoysticks = 0; -int -SDL_SYS_JoystickInit(void) +static int BSD_JoystickOpen(SDL_Joystick * joy, int device_index); +static void BSD_JoystickClose(SDL_Joystick * joy); + +static int +BSD_JoystickInit(void) { char s[16]; int i, fd; - SDL_SYS_numjoysticks = 0; + numjoysticks = 0; SDL_memset(joynames, 0, sizeof(joynames)); SDL_memset(joydevnames, 0, sizeof(joydevnames)); @@ -179,21 +182,21 @@ SDL_SYS_JoystickInit(void) SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i); - joynames[SDL_SYS_numjoysticks] = SDL_strdup(s); + joynames[numjoysticks] = SDL_strdup(s); - if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) { - SDL_SYS_JoystickClose(&nj); - SDL_SYS_numjoysticks++; + if (BSD_JoystickOpen(&nj, numjoysticks) == 0) { + BSD_JoystickClose(&nj); + numjoysticks++; } else { - SDL_free(joynames[SDL_SYS_numjoysticks]); - joynames[SDL_SYS_numjoysticks] = NULL; + SDL_free(joynames[numjoysticks]); + joynames[numjoysticks] = NULL; } } for (i = 0; i < MAX_JOY_JOYS; i++) { SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i); fd = open(s, O_RDONLY); if (fd != -1) { - joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s); + joynames[numjoysticks++] = SDL_strdup(s); close(fd); } } @@ -201,22 +204,22 @@ SDL_SYS_JoystickInit(void) /* Read the default USB HID usage table. */ hid_init(NULL); - return (SDL_SYS_numjoysticks); + return (numjoysticks); } -int -SDL_SYS_NumJoysticks(void) +static int +BSD_JoystickGetCount(void) { - return SDL_SYS_numjoysticks; + return numjoysticks; } -void -SDL_SYS_JoystickDetect(void) +static void +BSD_JoystickDetect(void) { } -const char * -SDL_SYS_JoystickNameForDeviceIndex(int device_index) +static const char * +BSD_JoystickGetDeviceName(int device_index) { if (joydevnames[device_index] != NULL) { return (joydevnames[device_index]); @@ -224,8 +227,15 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index) return (joynames[device_index]); } +static int +BSD_JoystickGetDevicePlayerIndex(int device_index) +{ + return -1; +} + /* Function to perform the mapping from device index to the instance id for this index */ -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index) +static SDL_JoystickID +BSD_JoystickGetDeviceInstanceID(int device_index) { return device_index; } @@ -281,8 +291,8 @@ hatval_to_sdl(Sint32 hatval) } -int -SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) +static int +BSD_JoystickOpen(SDL_Joystick * joy, int device_index) { char *path = joynames[device_index]; struct joystick_hwdata *hw; @@ -365,8 +375,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index) str[i] = '\0'; asprintf(&new_name, "%s @ %s", str, path); if (new_name != NULL) { - SDL_free(joydevnames[SDL_SYS_numjoysticks]); - joydevnames[SDL_SYS_numjoysticks] = new_name; + SDL_free(joydevnames[numjoysticks]); + joydevnames[numjoysticks] = new_name; } } desc_failed: @@ -467,14 +477,8 @@ desc_failed: return (-1); } -/* Function to determine if this joystick is attached to the system right now */ -SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick) -{ - return SDL_TRUE; -} - -void -SDL_SYS_JoystickUpdate(SDL_Joystick * joy) +static void +BSD_JoystickUpdate(SDL_Joystick * joy) { struct hid_item hitem; struct hid_data *hdata; @@ -586,8 +590,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy) } /* Function to close a joystick after use */ -void -SDL_SYS_JoystickClose(SDL_Joystick * joy) +static void +BSD_JoystickClose(SDL_Joystick * joy) { if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) { report_free(&joy->hwdata->inreport); @@ -598,8 +602,8 @@ SDL_SYS_JoystickClose(SDL_Joystick * joy) SDL_free(joy->hwdata); } -void -SDL_SYS_JoystickQuit(void) +static void +BSD_JoystickQuit(void) { int i; @@ -611,21 +615,12 @@ SDL_SYS_JoystickQuit(void) return; } -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index ) +static SDL_JoystickGUID +BSD_JoystickGetDeviceGUID( int device_index ) { SDL_JoystickGUID guid; /* the GUID is just the first 16 chars of the name for now */ - const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index ); - SDL_zero( guid ); - SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); - return guid; -} - -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick) -{ - SDL_JoystickGUID guid; - /* the GUID is just the first 16 chars of the name for now */ - const char *name = joystick->name; + const char *name = BSD_JoystickGetDeviceName( device_index ); SDL_zero( guid ); SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); return guid; @@ -686,6 +681,28 @@ report_free(struct report *r) r->status = SREPORT_UNINIT; } +static int +BSD_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) +{ + return SDL_Unsupported(); +} + +SDL_JoystickDriver SDL_BSD_JoystickDriver = +{ + BSD_JoystickInit, + BSD_JoystickGetCount, + BSD_JoystickDetect, + BSD_JoystickGetDeviceName, + BSD_JoystickGetDevicePlayerIndex, + BSD_JoystickGetDeviceGUID, + BSD_JoystickGetDeviceInstanceID, + BSD_JoystickOpen, + BSD_JoystickRumble, + BSD_JoystickUpdate, + BSD_JoystickClose, + BSD_JoystickQuit, +}; + #endif /* SDL_JOYSTICK_USBHID */ /* vi: set ts=4 sw=4 expandtab: */ |