src/joystick/iphoneos/SDL_sysjoystick.m
changeset 6707 70eeb7e3ec2f
parent 6698 28ab2ef7bfc9
child 6744 4ac2bb6dc80c
equal deleted inserted replaced
6706:b9f5fb1e78b5 6707:70eeb7e3ec2f
    38 SDL_SYS_JoystickInit(void)
    38 SDL_SYS_JoystickInit(void)
    39 {
    39 {
    40     return (1);
    40     return (1);
    41 }
    41 }
    42 
    42 
       
    43 int SDL_SYS_NumJoysticks()
       
    44 {
       
    45     return 1;
       
    46 }
       
    47 
       
    48 void SDL_SYS_JoystickDetect()
       
    49 {
       
    50 }
       
    51 
       
    52 SDL_bool SDL_SYS_JoystickNeedsPolling()
       
    53 {
       
    54     return SDL_FALSE;
       
    55 }
       
    56 
    43 /* Function to get the device-dependent name of a joystick */
    57 /* Function to get the device-dependent name of a joystick */
    44 const char *
    58 const char *
    45 SDL_SYS_JoystickNameForIndex(int index)
    59 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    46 {
    60 {
    47 	switch(index) {
    61     return accelerometerName;
    48 		case 0:
    62 }
    49 			return accelerometerName;
    63 
    50 		default:
    64 /* Function to perform the mapping from device index to the instance id for this index */
    51 			SDL_SetError("No joystick available with that index");
    65 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    52 			return NULL;
    66 {
    53 	}
    67     return device_index;
    54 }
    68 }
    55 
    69 
    56 /* Function to open a joystick for use.
    70 /* Function to open a joystick for use.
    57    The joystick to open is specified by the index field of the joystick.
    71    The joystick to open is specified by the index field of the joystick.
    58    This should fill the nbuttons and naxes fields of the joystick structure.
    72    This should fill the nbuttons and naxes fields of the joystick structure.
    59    It returns 0, or -1 if there is an error.
    73    It returns 0, or -1 if there is an error.
    60  */
    74  */
    61 int
    75 int
    62 SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    76 SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    63 {
    77 {
    64 	if (device_index == 0) {
    78     joystick->naxes = 3;
    65 		joystick->naxes = 3;
    79     joystick->nhats = 0;
    66 		joystick->nhats = 0;
    80     joystick->nballs = 0;
    67 		joystick->nballs = 0;
    81     joystick->nbuttons = 0;
    68 		joystick->nbuttons = 0;
    82     [[SDLUIAccelerationDelegate sharedDelegate] startup];
    69 		[[SDLUIAccelerationDelegate sharedDelegate] startup];
    83     return 0;
    70 		return 0;
    84 }
    71 	} else {
    85 
    72 		SDL_SetError("No joystick available with that index");
    86 /* Function to determine is this joystick is attached to the system right now */
    73 		return (-1);
    87 SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    74 	}
    88 {
       
    89     return SDL_TRUE;
    75 }
    90 }
    76 
    91 
    77 /* Function to update the state of a joystick - called as a device poll.
    92 /* Function to update the state of a joystick - called as a device poll.
    78  * This function shouldn't update the joystick structure directly,
    93  * This function shouldn't update the joystick structure directly,
    79  * but instead should call SDL_PrivateJoystick*() to deliver events
    94  * but instead should call SDL_PrivateJoystick*() to deliver events
   116 SDL_SYS_JoystickQuit(void)
   131 SDL_SYS_JoystickQuit(void)
   117 {
   132 {
   118     return;
   133     return;
   119 }
   134 }
   120 
   135 
   121 /* Function to perform the mapping from device index to the instance id for this index */
   136 JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   122 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
       
   123 {
       
   124     return index;
       
   125 }
       
   126 
       
   127 /* Function to determine is this joystick is attached to the system right now */
       
   128 int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
       
   129 {
       
   130     return 1;
       
   131 }
       
   132 
       
   133 int SDL_SYS_NumJoysticks()
       
   134 {
       
   135     return 1;
       
   136 }
       
   137 
       
   138 int SDL_SYS_JoystickNeedsPolling()
       
   139 {
       
   140     return 0;
       
   141 }
       
   142 
       
   143 void SDL_SYS_JoystickDetect()
       
   144 {
       
   145 }
       
   146 
       
   147 JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
       
   148 {
   137 {
   149     JoystickGUID guid;
   138     JoystickGUID guid;
   150     // the GUID is just the first 16 chars of the name for now
   139     // the GUID is just the first 16 chars of the name for now
   151     const char *name = SDL_SYS_JoystickNameForIndex( device_index );
   140     const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   152     SDL_zero( guid );
   141     SDL_zero( guid );
   153     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   142     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   154     return guid;
   143     return guid;
   155 }
   144 }
   156 
   145 
   157 JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
   146 JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   158 {
   147 {
   159     JoystickGUID guid;
   148     JoystickGUID guid;
   160     // the GUID is just the first 16 chars of the name for now
   149     // the GUID is just the first 16 chars of the name for now
   161     const char *name = joystick->name;
   150     const char *name = joystick->name;
   162     SDL_zero( guid );
   151     SDL_zero( guid );