src/joystick/bsd/SDL_sysjoystick.c
changeset 12105 997ec56425a8
parent 12090 c3209fca27b2
child 12106 94f9bf5b9c36
     1.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Fri Aug 10 14:32:30 2018 -0400
     1.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Fri Aug 10 14:42:40 2018 -0400
     1.3 @@ -161,15 +161,15 @@
     1.4  #define REP_BUF_DATA(rep) ((rep)->buf->data)
     1.5  #endif
     1.6  
     1.7 -static int SDL_SYS_numjoysticks = 0;
     1.8 +static int numjoysticks = 0;
     1.9  
    1.10 -int
    1.11 -SDL_SYS_JoystickInit(void)
    1.12 +static int
    1.13 +BSD_JoystickInit(void)
    1.14  {
    1.15      char s[16];
    1.16      int i, fd;
    1.17  
    1.18 -    SDL_SYS_numjoysticks = 0;
    1.19 +    numjoysticks = 0;
    1.20  
    1.21      SDL_memset(joynames, 0, sizeof(joynames));
    1.22      SDL_memset(joydevnames, 0, sizeof(joydevnames));
    1.23 @@ -179,21 +179,21 @@
    1.24  
    1.25          SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
    1.26  
    1.27 -        joynames[SDL_SYS_numjoysticks] = SDL_strdup(s);
    1.28 +        joynames[numjoysticks] = SDL_strdup(s);
    1.29  
    1.30 -        if (SDL_SYS_JoystickOpen(&nj, SDL_SYS_numjoysticks) == 0) {
    1.31 -            SDL_SYS_JoystickClose(&nj);
    1.32 -            SDL_SYS_numjoysticks++;
    1.33 +        if (BSD_JoystickOpen(&nj, numjoysticks) == 0) {
    1.34 +            BSD_JoystickClose(&nj);
    1.35 +            numjoysticks++;
    1.36          } else {
    1.37 -            SDL_free(joynames[SDL_SYS_numjoysticks]);
    1.38 -            joynames[SDL_SYS_numjoysticks] = NULL;
    1.39 +            SDL_free(joynames[numjoysticks]);
    1.40 +            joynames[numjoysticks] = NULL;
    1.41          }
    1.42      }
    1.43      for (i = 0; i < MAX_JOY_JOYS; i++) {
    1.44          SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
    1.45          fd = open(s, O_RDONLY);
    1.46          if (fd != -1) {
    1.47 -            joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
    1.48 +            joynames[numjoysticks++] = SDL_strdup(s);
    1.49              close(fd);
    1.50          }
    1.51      }
    1.52 @@ -201,22 +201,22 @@
    1.53      /* Read the default USB HID usage table. */
    1.54      hid_init(NULL);
    1.55  
    1.56 -    return (SDL_SYS_numjoysticks);
    1.57 +    return (numjoysticks);
    1.58  }
    1.59  
    1.60 -int
    1.61 -SDL_SYS_NumJoysticks(void)
    1.62 +static int
    1.63 +BSD_JoystickGetCount(void)
    1.64  {
    1.65 -    return SDL_SYS_numjoysticks;
    1.66 +    return numjoysticks;
    1.67  }
    1.68  
    1.69 -void
    1.70 -SDL_SYS_JoystickDetect(void)
    1.71 +static void
    1.72 +BSD_JoystickDetect(void)
    1.73  {
    1.74  }
    1.75  
    1.76 -const char *
    1.77 -SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    1.78 +static const char *
    1.79 +BSD_JoystickGetDeviceName(int device_index)
    1.80  {
    1.81      if (joydevnames[device_index] != NULL) {
    1.82          return (joydevnames[device_index]);
    1.83 @@ -225,7 +225,8 @@
    1.84  }
    1.85  
    1.86  /* Function to perform the mapping from device index to the instance id for this index */
    1.87 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    1.88 +static SDL_JoystickID
    1.89 +BSD_JoystickGetDeviceInstanceID(int device_index)
    1.90  {
    1.91      return device_index;
    1.92  }
    1.93 @@ -281,8 +282,8 @@
    1.94  }
    1.95  
    1.96  
    1.97 -int
    1.98 -SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
    1.99 +static int
   1.100 +BSD_JoystickOpen(SDL_Joystick * joy, int device_index)
   1.101  {
   1.102      char *path = joynames[device_index];
   1.103      struct joystick_hwdata *hw;
   1.104 @@ -365,8 +366,8 @@
   1.105          str[i] = '\0';
   1.106          asprintf(&new_name, "%s @ %s", str, path);
   1.107          if (new_name != NULL) {
   1.108 -            SDL_free(joydevnames[SDL_SYS_numjoysticks]);
   1.109 -            joydevnames[SDL_SYS_numjoysticks] = new_name;
   1.110 +            SDL_free(joydevnames[numjoysticks]);
   1.111 +            joydevnames[numjoysticks] = new_name;
   1.112          }
   1.113      }
   1.114  desc_failed:
   1.115 @@ -467,8 +468,8 @@
   1.116      return (-1);
   1.117  }
   1.118  
   1.119 -void
   1.120 -SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
   1.121 +static void
   1.122 +BSD_JoystickUpdate(SDL_Joystick * joy)
   1.123  {
   1.124      struct hid_item hitem;
   1.125      struct hid_data *hdata;
   1.126 @@ -580,8 +581,8 @@
   1.127  }
   1.128  
   1.129  /* Function to close a joystick after use */
   1.130 -void
   1.131 -SDL_SYS_JoystickClose(SDL_Joystick * joy)
   1.132 +static void
   1.133 +BSD_JoystickClose(SDL_Joystick * joy)
   1.134  {
   1.135      if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
   1.136          report_free(&joy->hwdata->inreport);
   1.137 @@ -592,8 +593,8 @@
   1.138      SDL_free(joy->hwdata);
   1.139  }
   1.140  
   1.141 -void
   1.142 -SDL_SYS_JoystickQuit(void)
   1.143 +static void
   1.144 +BSD_JoystickQuit(void)
   1.145  {
   1.146      int i;
   1.147  
   1.148 @@ -605,21 +606,12 @@
   1.149      return;
   1.150  }
   1.151  
   1.152 -SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   1.153 +static SDL_JoystickGUID
   1.154 +BSD_JoystickGetDeviceGUID( int device_index )
   1.155  {
   1.156      SDL_JoystickGUID guid;
   1.157      /* the GUID is just the first 16 chars of the name for now */
   1.158 -    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   1.159 -    SDL_zero( guid );
   1.160 -    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   1.161 -    return guid;
   1.162 -}
   1.163 -
   1.164 -SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   1.165 -{
   1.166 -    SDL_JoystickGUID guid;
   1.167 -    /* the GUID is just the first 16 chars of the name for now */
   1.168 -    const char *name = joystick->name;
   1.169 +    const char *name = BSD_JoystickNameForDeviceIndex( device_index );
   1.170      SDL_zero( guid );
   1.171      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   1.172      return guid;
   1.173 @@ -680,6 +672,27 @@
   1.174      r->status = SREPORT_UNINIT;
   1.175  }
   1.176  
   1.177 +static int
   1.178 +BSD_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   1.179 +{
   1.180 +    return SDL_Unsupported();
   1.181 +}
   1.182 +
   1.183 +SDL_JoystickDriver SDL_BSD_JoystickDriver =
   1.184 +{
   1.185 +    BSD_JoystickInit,
   1.186 +    BSD_JoystickGetCount,
   1.187 +    BSD_JoystickDetect,
   1.188 +    BSD_JoystickGetDeviceName,
   1.189 +    BSD_JoystickGetDeviceGUID,
   1.190 +    BSD_JoystickGetDeviceInstanceID,
   1.191 +    BSD_JoystickOpen,
   1.192 +    BSD_JoystickRumble,
   1.193 +    BSD_JoystickUpdate,
   1.194 +    BSD_JoystickClose,
   1.195 +    BSD_JoystickQuit,
   1.196 +};
   1.197 +
   1.198  #endif /* SDL_JOYSTICK_USBHID */
   1.199  
   1.200  /* vi: set ts=4 sw=4 expandtab: */