bsd: Update joystick code for new interfaces. (this is an untested push to see if buildbot likes it.)
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 8c70e99..dff3a14 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -64,6 +64,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_EMSCRIPTEN
&SDL_EMSCRIPTEN_JoystickDriver,
#endif
+#ifdef SDL_JOYSTICK_USBHID /* !!! FIXME: "USBHID" is a generic name, and doubly-confusing with HIDAPI next to it. This is the *BSD interface, rename this. */
+ &SDL_BSD_JoystickDriver,
+#endif
#ifdef SDL_JOYSTICK_HIDAPI
&SDL_HIDAPI_JoystickDriver,
#endif
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 43704d7..7a1f0d0 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -138,6 +138,7 @@ typedef struct _SDL_JoystickDriver
/* The available joystick drivers */
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
+extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
diff --git a/src/joystick/bsd/SDL_sysjoystick.c b/src/joystick/bsd/SDL_sysjoystick.c
index 2c55b23..7b145fd 100644
--- a/src/joystick/bsd/SDL_sysjoystick.c
+++ b/src/joystick/bsd/SDL_sysjoystick.c
@@ -161,15 +161,15 @@ 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_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 +179,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 +201,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]);
@@ -225,7 +225,8 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
}
/* 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 +282,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 +366,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,8 +468,8 @@ desc_failed:
return (-1);
}
-void
-SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
+static void
+BSD_JoystickUpdate(SDL_Joystick * joy)
{
struct hid_item hitem;
struct hid_data *hdata;
@@ -580,8 +581,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);
@@ -592,8 +593,8 @@ SDL_SYS_JoystickClose(SDL_Joystick * joy)
SDL_free(joy->hwdata);
}
-void
-SDL_SYS_JoystickQuit(void)
+static void
+BSD_JoystickQuit(void)
{
int i;
@@ -605,21 +606,12 @@ SDL_SYS_JoystickQuit(void)
return;
}
-SDL_JoystickGUID SDL_SYS_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)
+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 = joystick->name;
+ const char *name = BSD_JoystickNameForDeviceIndex( device_index );
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
@@ -680,6 +672,27 @@ 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_JoystickGetDeviceGUID,
+ BSD_JoystickGetDeviceInstanceID,
+ BSD_JoystickOpen,
+ BSD_JoystickRumble,
+ BSD_JoystickUpdate,
+ BSD_JoystickClose,
+ BSD_JoystickQuit,
+};
+
#endif /* SDL_JOYSTICK_USBHID */
/* vi: set ts=4 sw=4 expandtab: */