Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Completed adding new hotplug stubs for the joystick implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 27, 2012
1 parent 443b83f commit 9e9b99b
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 33 deletions.
69 changes: 59 additions & 10 deletions src/joystick/beos/SDL_bejoystick.cc
Expand Up @@ -50,6 +50,8 @@ extern "C"
int16 *new_axes;
};

static int SDL_SYS_numjoysticks = 0;

/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
* joysticks. Joystick 0 should be the system default joystick.
Expand All @@ -58,34 +60,33 @@ extern "C"
int SDL_SYS_JoystickInit(void)
{
BJoystick joystick;
int numjoysticks;
int i;
int32 nports;
char name[B_OS_NAME_LENGTH];

/* Search for attached joysticks */
nports = joystick.CountDevices();
numjoysticks = 0;
SDL_SYS_numjoysticks = 0;
SDL_memset(SDL_joyport, 0, (sizeof SDL_joyport));
SDL_memset(SDL_joyname, 0, (sizeof SDL_joyname));
for (i = 0; (SDL_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
for (i = 0; (SDL_SYS_numjoysticks < MAX_JOYSTICKS) && (i < nports); ++i)
{
if (joystick.GetDeviceName(i, name) == B_OK) {
if (joystick.Open(name) != B_ERROR) {
BString stick_name;
joystick.GetControllerName(&stick_name);
SDL_joyport[numjoysticks] = strdup(name);
SDL_joyname[numjoysticks] = strdup(stick_name.String());
numjoysticks++;
SDL_joyport[SDL_SYS_numjoysticks] = strdup(name);
SDL_joyname[SDL_SYS_numjoysticks] = strdup(stick_name.String());
SDL_SYS_numjoysticks++;
joystick.Close();
}
}
}
return (numjoysticks);
return (SDL_SYS_numjoysticks);
}

/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index)
const char *SDL_SYS_JoystickNameForIndex(int index)
{
return SDL_joyname[index];
}
Expand All @@ -95,11 +96,12 @@ extern "C"
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
int SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
{
BJoystick *stick;

/* Create the joystick data structure */
joystick->instance_id = device_index;
joystick->hwdata = (struct joystick_hwdata *)
SDL_malloc(sizeof(*joystick->hwdata));
if (joystick->hwdata == NULL) {
Expand All @@ -111,7 +113,7 @@ extern "C"
joystick->hwdata->stick = stick;

/* Open the requested joystick for use */
if (stick->Open(SDL_joyport[joystick->index]) == B_ERROR) {
if (stick->Open(SDL_joyport[device_index]) == B_ERROR) {
SDL_SetError("Unable to open joystick");
SDL_SYS_JoystickClose(joystick);
return (-1);
Expand Down Expand Up @@ -233,6 +235,53 @@ extern "C"
SDL_joyname[0] = NULL;
}

/* 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 SDL_SYS_numjoysticks;
}

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;
}

}; // extern "C"

#endif /* SDL_JOYSTICK_BEOS */
Expand Down
1 change: 1 addition & 0 deletions src/joystick/bsd/SDL_sysjoystick.c
Expand Up @@ -278,6 +278,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joy, int device_index)
return (-1);
}

joy->instance_id = device_index;
hw = (struct joystick_hwdata *)
SDL_malloc(sizeof(struct joystick_hwdata));
if (hw == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/darwin/SDL_sysjoystick.c
Expand Up @@ -831,8 +831,8 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
for (index = device_index; index > 0; index--)
device = device->pNext;

joystick->hwdata = device;
joystick->instance_id = device->instance_id;
joystick->hwdata = device;
joystick->name = device->product;

joystick->naxes = device->axes;
Expand Down
51 changes: 49 additions & 2 deletions src/joystick/dummy/SDL_sysjoystick.c
Expand Up @@ -42,7 +42,7 @@ SDL_SYS_JoystickInit(void)

/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickName(int index)
SDL_SYS_JoystickNameForDevice(int index)
{
SDL_SetError("Logic error: No joysticks available");
return (NULL);
Expand All @@ -54,7 +54,7 @@ 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 device_index)
{
SDL_SetError("Logic error: No joysticks available");
return (-1);
Expand Down Expand Up @@ -85,6 +85,53 @@ SDL_SYS_JoystickQuit(void)
return;
}

/* 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 0;
}

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_DUMMY || SDL_JOYSTICK_DISABLED */

/* vi: set ts=4 sw=4 expandtab: */
4 changes: 1 addition & 3 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -68,12 +68,10 @@
joystick->nbuttons = 0;
[[SDLUIAccelerationDelegate sharedDelegate] startup];
return 0;
}
else {
} else {
SDL_SetError("No joystick available with that index");
return (-1);
}

}

/* Function to update the state of a joystick - called as a device poll.
Expand Down
4 changes: 2 additions & 2 deletions src/joystick/linux/SDL_sysjoystick.c
Expand Up @@ -390,7 +390,7 @@ EV_IsJoystick(int fd)

#endif /* SDL_INPUT_LINUXEV */

int SDL_SYS_numjoysticks = 0;
static int SDL_SYS_numjoysticks = 0;

/* Function to scan the system for joysticks */
int
Expand Down Expand Up @@ -827,6 +827,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
SDL_SetError("Unable to open %s\n", SDL_joylist[joystick->instance_id]);
return (-1);
}
joystick->instance_id = device_index;
joystick->hwdata = (struct joystick_hwdata *)
SDL_malloc(sizeof(*joystick->hwdata));
if (joystick->hwdata == NULL) {
Expand All @@ -837,7 +838,6 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
joystick->hwdata->fd = fd;
joystick->hwdata->fname = fname;
joystick->instance_id = device_index;

/* Set the joystick to non-blocking read mode */
fcntl(fd, F_SETFL, O_NONBLOCK);
Expand Down
52 changes: 49 additions & 3 deletions src/joystick/nds/SDL_sysjoystick.c
Expand Up @@ -43,13 +43,12 @@
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)
return "NDS builtin joypad";
Expand All @@ -63,7 +62,7 @@ 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 device_index)
{
joystick->nbuttons = 8;
joystick->nhats = 0;
Expand Down Expand Up @@ -168,4 +167,51 @@ 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 */
2 changes: 1 addition & 1 deletion src/joystick/windows/SDL_dxjoystick.c
Expand Up @@ -707,6 +707,7 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);

/* allocate memory for system specific hardware data */
joystick->instance_id = joystickdevice->nInstanceID;
joystick->hwdata =
(struct joystick_hwdata *) SDL_malloc(sizeof(struct joystick_hwdata));
if (joystick->hwdata == NULL) {
Expand All @@ -716,7 +717,6 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
SDL_memset(joystick->hwdata, 0, sizeof(struct joystick_hwdata));
joystick->hwdata->buffered = 1;
joystick->hwdata->removed = 0;
joystick->instance_id = joystickdevice->nInstanceID;
joystick->hwdata->Capabilities.dwSize = sizeof(DIDEVCAPS);
joystick->hwdata->guid = joystickdevice->guid;

Expand Down

0 comments on commit 9e9b99b

Please sign in to comment.