author | Sam Lantinga <slouken@libsdl.org> |
Mon, 26 Nov 2012 23:58:53 -0800 | |
changeset 6706 | b9f5fb1e78b5 |
parent 6705 | 1075e5ff6de0 |
child 6707 | 70eeb7e3ec2f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
2 |
Simple DirectMedia Layer |
6138 | 3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
0 | 4 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
5 |
This software is provided 'as-is', without any express or implied |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
6 |
warranty. In no event will the authors be held liable for any damages |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
7 |
arising from the use of this software. |
0 | 8 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
9 |
Permission is granted to anyone to use this software for any purpose, |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
10 |
including commercial applications, and to alter it and redistribute it |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
11 |
freely, subject to the following restrictions: |
0 | 12 |
|
5535
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
13 |
1. The origin of this software must not be misrepresented; you must not |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
14 |
claim that you wrote the original software. If you use this software |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
15 |
in a product, an acknowledgment in the product documentation would be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
16 |
appreciated but is not required. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
17 |
2. Altered source versions must be plainly marked as such, and must not be |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
18 |
misrepresented as being the original software. |
96594ac5fd1a
SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents:
5262
diff
changeset
|
19 |
3. This notice may not be removed or altered from any source distribution. |
0 | 20 |
*/ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
21 |
#include "SDL_config.h" |
0 | 22 |
|
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
23 |
#if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED) |
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
24 |
|
0 | 25 |
/* This is the system specific header for the SDL joystick API */ |
26 |
||
27 |
#include "SDL_joystick.h" |
|
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 |
#include "../SDL_sysjoystick.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
29 |
#include "../SDL_joystick_c.h" |
0 | 30 |
|
31 |
/* Function to scan the system for joysticks. |
|
32 |
* It should return 0, or -1 on an unrecoverable fatal error. |
|
33 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
34 |
int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
35 |
SDL_SYS_JoystickInit(void) |
0 | 36 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
37 |
return (0); |
0 | 38 |
} |
39 |
||
40 |
/* Function to get the device-dependent name of a joystick */ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
41 |
const char * |
6706
b9f5fb1e78b5
This should really fix it..
Sam Lantinga <slouken@libsdl.org>
parents:
6705
diff
changeset
|
42 |
SDL_SYS_JoystickNameForIndex(int index) |
0 | 43 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
44 |
SDL_SetError("Logic error: No joysticks available"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
45 |
return (NULL); |
0 | 46 |
} |
47 |
||
48 |
/* Function to open a joystick for use. |
|
49 |
The joystick to open is specified by the index field of the joystick. |
|
50 |
This should fill the nbuttons and naxes fields of the joystick structure. |
|
51 |
It returns 0, or -1 if there is an error. |
|
52 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
53 |
int |
6698
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
54 |
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) |
0 | 55 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
56 |
SDL_SetError("Logic error: No joysticks available"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
57 |
return (-1); |
0 | 58 |
} |
59 |
||
60 |
/* Function to update the state of a joystick - called as a device poll. |
|
61 |
* This function shouldn't update the joystick structure directly, |
|
62 |
* but instead should call SDL_PrivateJoystick*() to deliver events |
|
63 |
* and update joystick device state. |
|
64 |
*/ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
65 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
66 |
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
0 | 67 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
68 |
return; |
0 | 69 |
} |
70 |
||
71 |
/* Function to close a joystick after use */ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
72 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
73 |
SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
0 | 74 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
75 |
return; |
0 | 76 |
} |
77 |
||
78 |
/* Function to perform any system-specific joystick related cleanup */ |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
79 |
void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
80 |
SDL_SYS_JoystickQuit(void) |
0 | 81 |
{ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
82 |
return; |
0 | 83 |
} |
84 |
||
6698
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
85 |
/* Function to perform the mapping from device index to the instance id for this index */ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
86 |
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index) |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
87 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
88 |
return index; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
89 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
90 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
91 |
/* Function to determine is this joystick is attached to the system right now */ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
92 |
int SDL_SYS_JoystickAttached(SDL_Joystick *joystick) |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
93 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
94 |
return 1; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
95 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
96 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
97 |
int SDL_SYS_NumJoysticks() |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
98 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
99 |
return 0; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
100 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
101 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
102 |
int SDL_SYS_JoystickNeedsPolling() |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
103 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
104 |
return 0; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
105 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
106 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
107 |
void SDL_SYS_JoystickDetect() |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
108 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
109 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
110 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
111 |
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index ) |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
112 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
113 |
JoystickGUID guid; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
114 |
// the GUID is just the first 16 chars of the name for now |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
115 |
const char *name = SDL_SYS_JoystickNameForIndex( device_index ); |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
116 |
SDL_zero( guid ); |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
117 |
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
118 |
return guid; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
119 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
120 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
121 |
|
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
122 |
JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick) |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
123 |
{ |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
124 |
JoystickGUID guid; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
125 |
// the GUID is just the first 16 chars of the name for now |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
126 |
const char *name = joystick->name; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
127 |
SDL_zero( guid ); |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
128 |
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) ); |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
129 |
return guid; |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
130 |
} |
28ab2ef7bfc9
Completed adding new hotplug stubs for the joystick implementations
Sam Lantinga <slouken@libsdl.org>
parents:
6138
diff
changeset
|
131 |
|
1635
92947e3a18db
Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
132 |
#endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */ |
3104
86ea6c073d87
Fixed undefined references to joystick code
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
133 |
|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1635
diff
changeset
|
134 |
/* vi: set ts=4 sw=4 expandtab: */ |