mirror of https://github.com/encounter/SDL.git
bsd: Update joystick code for new interfaces.
(this is an untested push to see if buildbot likes it.)
This commit is contained in:
parent
b692c35237
commit
67764070f0
|
@ -64,6 +64,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
|
||||||
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
||||||
&SDL_EMSCRIPTEN_JoystickDriver,
|
&SDL_EMSCRIPTEN_JoystickDriver,
|
||||||
#endif
|
#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
|
#ifdef SDL_JOYSTICK_HIDAPI
|
||||||
&SDL_HIDAPI_JoystickDriver,
|
&SDL_HIDAPI_JoystickDriver,
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -138,6 +138,7 @@ typedef struct _SDL_JoystickDriver
|
||||||
|
|
||||||
/* The available joystick drivers */
|
/* The available joystick drivers */
|
||||||
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
|
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
|
||||||
|
extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
|
||||||
extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
|
extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
|
||||||
extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
|
extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
|
||||||
extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
|
extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
|
||||||
|
|
|
@ -161,15 +161,15 @@ static void report_free(struct report *);
|
||||||
#define REP_BUF_DATA(rep) ((rep)->buf->data)
|
#define REP_BUF_DATA(rep) ((rep)->buf->data)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int SDL_SYS_numjoysticks = 0;
|
static int numjoysticks = 0;
|
||||||
|
|
||||||
int
|
static int
|
||||||
SDL_SYS_JoystickInit(void)
|
BSD_JoystickInit(void)
|
||||||
{
|
{
|
||||||
char s[16];
|
char s[16];
|
||||||
int i, fd;
|
int i, fd;
|
||||||
|
|
||||||
SDL_SYS_numjoysticks = 0;
|
numjoysticks = 0;
|
||||||
|
|
||||||
SDL_memset(joynames, 0, sizeof(joynames));
|
SDL_memset(joynames, 0, sizeof(joynames));
|
||||||
SDL_memset(joydevnames, 0, sizeof(joydevnames));
|
SDL_memset(joydevnames, 0, sizeof(joydevnames));
|
||||||
|
@ -179,21 +179,21 @@ SDL_SYS_JoystickInit(void)
|
||||||
|
|
||||||
SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
|
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) {
|
if (BSD_JoystickOpen(&nj, numjoysticks) == 0) {
|
||||||
SDL_SYS_JoystickClose(&nj);
|
BSD_JoystickClose(&nj);
|
||||||
SDL_SYS_numjoysticks++;
|
numjoysticks++;
|
||||||
} else {
|
} else {
|
||||||
SDL_free(joynames[SDL_SYS_numjoysticks]);
|
SDL_free(joynames[numjoysticks]);
|
||||||
joynames[SDL_SYS_numjoysticks] = NULL;
|
joynames[numjoysticks] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < MAX_JOY_JOYS; i++) {
|
for (i = 0; i < MAX_JOY_JOYS; i++) {
|
||||||
SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
|
SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
|
||||||
fd = open(s, O_RDONLY);
|
fd = open(s, O_RDONLY);
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
joynames[SDL_SYS_numjoysticks++] = SDL_strdup(s);
|
joynames[numjoysticks++] = SDL_strdup(s);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,22 +201,22 @@ SDL_SYS_JoystickInit(void)
|
||||||
/* Read the default USB HID usage table. */
|
/* Read the default USB HID usage table. */
|
||||||
hid_init(NULL);
|
hid_init(NULL);
|
||||||
|
|
||||||
return (SDL_SYS_numjoysticks);
|
return (numjoysticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
SDL_SYS_NumJoysticks(void)
|
BSD_JoystickGetCount(void)
|
||||||
{
|
{
|
||||||
return SDL_SYS_numjoysticks;
|
return numjoysticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
SDL_SYS_JoystickDetect(void)
|
BSD_JoystickDetect(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
static const char *
|
||||||
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
BSD_JoystickGetDeviceName(int device_index)
|
||||||
{
|
{
|
||||||
if (joydevnames[device_index] != NULL) {
|
if (joydevnames[device_index] != NULL) {
|
||||||
return (joydevnames[device_index]);
|
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 */
|
/* 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;
|
return device_index;
|
||||||
}
|
}
|
||||||
|
@ -281,8 +282,8 @@ hatval_to_sdl(Sint32 hatval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
|
BSD_JoystickOpen(SDL_Joystick * joy, int device_index)
|
||||||
{
|
{
|
||||||
char *path = joynames[device_index];
|
char *path = joynames[device_index];
|
||||||
struct joystick_hwdata *hw;
|
struct joystick_hwdata *hw;
|
||||||
|
@ -365,8 +366,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
|
||||||
str[i] = '\0';
|
str[i] = '\0';
|
||||||
asprintf(&new_name, "%s @ %s", str, path);
|
asprintf(&new_name, "%s @ %s", str, path);
|
||||||
if (new_name != NULL) {
|
if (new_name != NULL) {
|
||||||
SDL_free(joydevnames[SDL_SYS_numjoysticks]);
|
SDL_free(joydevnames[numjoysticks]);
|
||||||
joydevnames[SDL_SYS_numjoysticks] = new_name;
|
joydevnames[numjoysticks] = new_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
desc_failed:
|
desc_failed:
|
||||||
|
@ -467,8 +468,8 @@ desc_failed:
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
|
BSD_JoystickUpdate(SDL_Joystick * joy)
|
||||||
{
|
{
|
||||||
struct hid_item hitem;
|
struct hid_item hitem;
|
||||||
struct hid_data *hdata;
|
struct hid_data *hdata;
|
||||||
|
@ -580,8 +581,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function to close a joystick after use */
|
/* Function to close a joystick after use */
|
||||||
void
|
static void
|
||||||
SDL_SYS_JoystickClose(SDL_Joystick * joy)
|
BSD_JoystickClose(SDL_Joystick * joy)
|
||||||
{
|
{
|
||||||
if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
|
if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
|
||||||
report_free(&joy->hwdata->inreport);
|
report_free(&joy->hwdata->inreport);
|
||||||
|
@ -592,8 +593,8 @@ SDL_SYS_JoystickClose(SDL_Joystick * joy)
|
||||||
SDL_free(joy->hwdata);
|
SDL_free(joy->hwdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
SDL_SYS_JoystickQuit(void)
|
BSD_JoystickQuit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -605,21 +606,12 @@ SDL_SYS_JoystickQuit(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
|
static SDL_JoystickGUID
|
||||||
|
BSD_JoystickGetDeviceGUID( int device_index )
|
||||||
{
|
{
|
||||||
SDL_JoystickGUID guid;
|
SDL_JoystickGUID guid;
|
||||||
/* the GUID is just the first 16 chars of the name for now */
|
/* the GUID is just the first 16 chars of the name for now */
|
||||||
const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
|
const char *name = BSD_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;
|
|
||||||
SDL_zero( guid );
|
SDL_zero( guid );
|
||||||
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
|
||||||
return guid;
|
return guid;
|
||||||
|
@ -680,6 +672,27 @@ report_free(struct report *r)
|
||||||
r->status = SREPORT_UNINIT;
|
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 */
|
#endif /* SDL_JOYSTICK_USBHID */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
Loading…
Reference in New Issue