returns the state of a stick, remote or otherwise
| 278 | |
| 279 | // returns the state of a stick, remote or otherwise |
| 280 | void joy_GetPos(tJoystick joy, tJoyPos *pos) { |
| 281 | SDL_Joystick *stick; |
| 282 | int i; |
| 283 | |
| 284 | memset(pos, 0, (sizeof *pos)); |
| 285 | |
| 286 | // retrieve joystick info from the net, or locally. |
| 287 | stick = Joysticks[joy].handle; |
| 288 | if (stick) { |
| 289 | uint32_t mask; |
| 290 | |
| 291 | mask = Joysticks[joy].caps.axes_mask; |
| 292 | pos->x = SDL_JoystickGetAxis(stick, 0); |
| 293 | pos->y = SDL_JoystickGetAxis(stick, 1); |
| 294 | if (mask & JOYFLAG_ZVALID) { |
| 295 | pos->z = SDL_JoystickGetAxis(stick, 2); |
| 296 | } |
| 297 | if (mask & JOYFLAG_RVALID) { |
| 298 | pos->r = SDL_JoystickGetAxis(stick, 3); |
| 299 | } |
| 300 | if (mask & JOYFLAG_UVALID) { |
| 301 | pos->u = SDL_JoystickGetAxis(stick, 4); |
| 302 | } |
| 303 | if (mask & JOYFLAG_VVALID) { |
| 304 | pos->v = SDL_JoystickGetAxis(stick, 5); |
| 305 | } |
| 306 | for (i = 0; i < JOYPOV_NUM; ++i) { |
| 307 | if (mask & (JOYFLAG_POVVALID << i)) { |
| 308 | pos->pov[i] = map_hat(SDL_JoystickGetHat(stick, i)); |
| 309 | } |
| 310 | } |
| 311 | for (i = Joysticks[joy].caps.num_btns; i >= 0; --i) { |
| 312 | if (SDL_JoystickGetButton(stick, i)) { |
| 313 | pos->buttons |= (1 << i); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | static int joyGetNumDevs(void) { |
| 320 | int found = 0; |
no test coverage detected