From 74a2079db49322284bc216dee2a78fb63b0c5ba7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 26 Nov 2012 22:02:01 -0800 Subject: [PATCH] Fixed building joystick code on Android --- src/joystick/android/SDL_sysjoystick.c | 53 +++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index fab2d1c37..88d0c2eb8 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -43,14 +43,12 @@ static const char *accelerometerName = "Android accelerometer"; int SDL_SYS_JoystickInit(void) { - SDL_numjoysticks = 1; - return (1); } /* Function to get the device-dependent name of a joystick */ const char * -SDL_SYS_JoystickName(int index) +SDL_SYS_JoystickNameForIndex(int index) { if (index == 0) { return accelerometerName; @@ -66,13 +64,12 @@ SDL_SYS_JoystickName(int index) It returns 0, or -1 if there is an error. */ int -SDL_SYS_JoystickOpen(SDL_Joystick * joystick) +SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int index) { joystick->nbuttons = 0; joystick->nhats = 0; joystick->nballs = 0; joystick->naxes = 3; - joystick->name = accelerometerName; return 0; } @@ -109,6 +106,52 @@ SDL_SYS_JoystickQuit(void) { } +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index) +{ + return index; +} + +/* Function to determine is this joystick is attached to the system right now */ +int SDL_SYS_JoystickAttached(SDL_Joystick *joystick) +{ + return 1; +} + +int SDL_SYS_NumJoysticks() +{ + return 1; +} + +int SDL_SYS_JoystickNeedsPolling() +{ + return 0; +} + +void SDL_SYS_JoystickDetect() +{ +} + +JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index ) +{ + JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = SDL_SYS_JoystickNameForIndex( device_index ); + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + +JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick) +{ + JoystickGUID guid; + // the GUID is just the first 16 chars of the name for now + const char *name = joystick->name; + SDL_zero( guid ); + SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); + return guid; +} + #endif /* SDL_JOYSTICK_NDS */ /* vi: set ts=4 sw=4 expandtab: */