Home | History | Annotate | Download | only in beos

Lines Matching defs:joystick

26 /* This is the system specific header for the SDL joystick API */
29 #include <be/device/Joystick.h>
45 /* The private structure used to keep track of a joystick */
54 * joysticks. Joystick 0 should be the system default joystick.
59 BJoystick joystick;
66 nports = joystick.CountDevices();
71 if ( joystick.GetDeviceName(i, name) == B_OK ) {
72 if ( joystick.Open(name) != B_ERROR ) {
74 joystick.GetControllerName(&stick_name);
79 joystick.Close();
86 /* Function to get the device-dependent name of a joystick */
92 /* Function to open a joystick for use.
93 The joystick to open is specified by the index field of the joystick.
94 This should fill the nbuttons and naxes fields of the joystick structure.
97 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
101 /* Create the joystick data structure */
102 joystick->hwdata = (struct joystick_hwdata *)
103 SDL_malloc(sizeof(*joystick->hwdata));
104 if ( joystick->hwdata == NULL ) {
108 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
110 joystick->hwdata->stick = stick;
112 /* Open the requested joystick for use */
113 if ( stick->Open(SDL_joyport[joystick->index]) == B_ERROR ) {
114 SDL_SetError("Unable to open joystick");
115 SDL_SYS_JoystickClose(joystick);
119 /* Set the joystick to calibrated mode */
122 /* Get the number of buttons, hats, and axes on the joystick */
123 joystick->nbuttons = stick->CountButtons();
124 joystick->naxes = stick->CountAxes();
125 joystick->nhats = stick->CountHats();
127 joystick->hwdata->new_axes = (int16 *)
128 SDL_malloc(joystick->naxes*sizeof(int16));
129 joystick->hwdata->new_hats = (uint8 *)
130 SDL_malloc(joystick->nhats*sizeof(uint8));
131 if ( ! joystick->hwdata->new_hats || ! joystick->hwdata->new_axes ) {
133 SDL_SYS_JoystickClose(joystick);
141 /* Function to update the state of a joystick - called as a device poll.
142 * This function shouldn't update the joystick structure directly,
144 * and update joystick device state.
146 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
168 stick = joystick->hwdata->stick;
169 axes = joystick->hwdata->new_axes;
170 hats = joystick->hwdata->new_hats;
172 /* Get the new joystick state */
179 for ( i=0; i<joystick->naxes; ++i ) {
180 change = ((int32)axes[i] - joystick->axes[i]);
182 SDL_PrivateJoystickAxis(joystick, i, axes[i]);
187 for ( i=0; i<joystick->nhats; ++i ) {
188 if ( hats[i] != joystick->hats[i] ) {
189 SDL_PrivateJoystickHat(joystick, i, hat_map[hats[i]]);
194 for ( i=0; i<joystick->nbuttons; ++i ) {
195 if ( (buttons&0x01) != joystick->buttons[i] ) {
196 SDL_PrivateJoystickButton(joystick, i, (buttons&0x01));
202 /* Function to close a joystick after use */
203 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
205 if ( joystick->hwdata ) {
206 joystick->hwdata->stick->Close();
207 delete joystick->hwdata->stick;
208 if ( joystick->hwdata->new_hats ) {
209 SDL_free(joystick->hwdata->new_hats);
211 if ( joystick->hwdata->new_axes ) {
212 SDL_free(joystick->hwdata->new_axes);
214 SDL_free(joystick->hwdata);
215 joystick->hwdata = NULL;
219 /* Function to perform any system-specific joystick related cleanup */