SDL  2.0
SDL_sysjoystick.h File Reference
#include "../SDL_internal.h"
#include "SDL_joystick.h"
#include "SDL_joystick_c.h"
+ Include dependency graph for SDL_sysjoystick.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDL_Joystick
 
struct  SDL_Joystick::balldelta
 

Functions

int SDL_SYS_JoystickInit (void)
 
int SDL_SYS_NumJoysticks ()
 
void SDL_SYS_JoystickDetect ()
 
const char * SDL_SYS_JoystickNameForDeviceIndex (int device_index)
 
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex (int device_index)
 
int SDL_SYS_JoystickOpen (SDL_Joystick *joystick, int device_index)
 
SDL_bool SDL_SYS_JoystickAttached (SDL_Joystick *joystick)
 
void SDL_SYS_JoystickUpdate (SDL_Joystick *joystick)
 
void SDL_SYS_JoystickClose (SDL_Joystick *joystick)
 
void SDL_SYS_JoystickQuit (void)
 
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID (int device_index)
 
SDL_JoystickGUID SDL_SYS_JoystickGetGUID (SDL_Joystick *joystick)
 

Function Documentation

SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex ( int  device_index)

Definition at line 327 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::instance_id.

Referenced by SDL_GameControllerOpen(), and SDL_JoystickOpen().

328 {
329  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
330  return device ? device->instance_id : 0;
331 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
SDL_bool SDL_SYS_JoystickAttached ( SDL_Joystick *  joystick)

Definition at line 382 of file SDL_sysjoystick.m.

References NULL.

Referenced by SDL_JoystickGetAttached().

383 {
384  return joystick->hwdata != NULL;
385 }
#define NULL
Definition: begin_code.h:143
void SDL_SYS_JoystickClose ( SDL_Joystick *  joystick)

Definition at line 586 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, recDevice::joystick, and NULL.

Referenced by SDL_JoystickClose().

587 {
588  SDL_JoystickDeviceItem *device = joystick->hwdata;
589 
590  if (device == NULL) {
591  return;
592  }
593 
594  device->joystick = NULL;
595 
596  @autoreleasepool {
597  if (device->accelerometer) {
598  [motionManager stopAccelerometerUpdates];
599  } else if (device->controller) {
600 #ifdef SDL_JOYSTICK_MFI
601  GCController *controller = device->controller;
602  controller.controllerPausedHandler = nil;
603  controller.playerIndex = -1;
604 #endif
605  }
606  }
607 }
SDL_Joystick * joystick
#define NULL
Definition: begin_code.h:143
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager
void SDL_SYS_JoystickDetect ( )

Definition at line 314 of file SDL_sysjoystick.m.

Referenced by SDL_JoystickUpdate().

315 {
316 }
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID ( int  device_index)

Definition at line 639 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetDeviceGUID().

640 {
641  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
642  SDL_JoystickGUID guid;
643  if (device) {
644  guid = device->guid;
645  } else {
646  SDL_zero(guid);
647  }
648  return guid;
649 }
SDL_JoystickGUID guid
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_JoystickGUID SDL_SYS_JoystickGetGUID ( SDL_Joystick *  joystick)

Definition at line 652 of file SDL_sysjoystick.m.

References recDevice::guid, and SDL_zero.

Referenced by SDL_JoystickGetGUID().

653 {
654  SDL_JoystickGUID guid;
655  if (joystick->hwdata) {
656  guid = joystick->hwdata->guid;
657  } else {
658  SDL_zero(guid);
659  }
660  return guid;
661 }
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
int SDL_SYS_JoystickInit ( void  )

Definition at line 260 of file SDL_sysjoystick.m.

References recDevice::controller, sort_controllers::controllers, numjoysticks, SDL_atoi, SDL_FALSE, SDL_GetHint, SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_SYS_AddJoystickDevice(), and SDL_TRUE.

Referenced by SDL_JoystickInit().

261 {
262  @autoreleasepool {
263  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
265 
266  if (!hint || SDL_atoi(hint)) {
267  /* Default behavior, accelerometer as joystick */
269  }
270 
271 #ifdef SDL_JOYSTICK_MFI
272  /* GameController.framework was added in iOS 7. */
273  if (![GCController class]) {
274  return numjoysticks;
275  }
276 
277  for (GCController *controller in [GCController controllers]) {
279  }
280 
281  connectObserver = [center addObserverForName:GCControllerDidConnectNotification
282  object:nil
283  queue:nil
284  usingBlock:^(NSNotification *note) {
285  GCController *controller = note.object;
287  }];
288 
289  disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
290  object:nil
291  queue:nil
292  usingBlock:^(NSNotification *note) {
293  GCController *controller = note.object;
295  while (device != NULL) {
296  if (device->controller == controller) {
298  break;
299  }
300  device = device->next;
301  }
302  }];
303 #endif /* SDL_JOYSTICK_MFI */
304  }
305 
306  return numjoysticks;
307 }
static SDL_JoystickDeviceItem * deviceList
#define SDL_GetHint
struct joystick_hwdata * next
#define SDL_HINT_ACCELEROMETER_AS_JOYSTICK
A variable controlling whether the Android / iOS built-in accelerometer should be listed as a joystic...
Definition: SDL_hints.h:289
#define SDL_atoi
#define NULL
Definition: begin_code.h:143
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
static int numjoysticks
GLuint in
static void SDL_SYS_AddJoystickDevice(GCController *controller, SDL_bool accelerometer)
GCController __unsafe_unretained * controller
const char* SDL_SYS_JoystickNameForDeviceIndex ( int  device_index)

Definition at line 320 of file SDL_sysjoystick.m.

References GetDeviceForIndex(), and recDevice::name.

Referenced by SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

321 {
322  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
323  return device ? device->name : "Unknown";
324 }
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
int SDL_SYS_JoystickOpen ( SDL_Joystick *  joystick,
int  device_index 
)

Definition at line 339 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, GetDeviceForIndex(), recDevice::instance_id, recDevice::joystick, motionManager, recDevice::naxes, recDevice::nbuttons, recDevice::nhats, NULL, and SDL_SetError.

Referenced by SDL_JoystickOpen().

340 {
341  SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
342  if (device == NULL) {
343  return SDL_SetError("Could not open Joystick: no hardware device for the specified index");
344  }
345 
346  joystick->hwdata = device;
347  joystick->instance_id = device->instance_id;
348 
349  joystick->naxes = device->naxes;
350  joystick->nhats = device->nhats;
351  joystick->nbuttons = device->nbuttons;
352  joystick->nballs = 0;
353 
354  device->joystick = joystick;
355 
356  @autoreleasepool {
357  if (device->accelerometer) {
358  if (motionManager == nil) {
359  motionManager = [[CMMotionManager alloc] init];
360  }
361 
362  /* Shorter times between updates can significantly increase CPU usage. */
363  motionManager.accelerometerUpdateInterval = 0.1;
364  [motionManager startAccelerometerUpdates];
365  } else {
366 #ifdef SDL_JOYSTICK_MFI
367  GCController *controller = device->controller;
368  controller.controllerPausedHandler = ^(GCController *c) {
369  if (joystick->hwdata) {
370  ++joystick->hwdata->num_pause_presses;
371  }
372  };
373 #endif /* SDL_JOYSTICK_MFI */
374  }
375  }
376 
377  return 0;
378 }
SDL_Joystick * joystick
static SDL_JoystickDeviceItem * GetDeviceForIndex(int device_index)
const GLubyte * c
#define NULL
Definition: begin_code.h:143
#define SDL_SetError
GCController __unsafe_unretained * controller
static CMMotionManager * motionManager
void SDL_SYS_JoystickQuit ( void  )

Definition at line 611 of file SDL_sysjoystick.m.

References motionManager, NULL, numjoysticks, and SDL_SYS_RemoveJoystickDevice().

Referenced by SDL_JoystickQuit().

612 {
613  @autoreleasepool {
614 #ifdef SDL_JOYSTICK_MFI
615  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
616 
617  if (connectObserver) {
618  [center removeObserver:connectObserver name:GCControllerDidConnectNotification object:nil];
619  connectObserver = nil;
620  }
621 
622  if (disconnectObserver) {
623  [center removeObserver:disconnectObserver name:GCControllerDidDisconnectNotification object:nil];
624  disconnectObserver = nil;
625  }
626 #endif /* SDL_JOYSTICK_MFI */
627 
628  while (deviceList != NULL) {
630  }
631 
632  motionManager = nil;
633  }
634 
635  numjoysticks = 0;
636 }
static SDL_JoystickDeviceItem * deviceList
GLuint const GLchar * name
#define NULL
Definition: begin_code.h:143
static SDL_JoystickDeviceItem * SDL_SYS_RemoveJoystickDevice(SDL_JoystickDeviceItem *device)
static int numjoysticks
static CMMotionManager * motionManager
void SDL_SYS_JoystickUpdate ( SDL_Joystick *  joystick)

Definition at line 569 of file SDL_sysjoystick.m.

References recDevice::accelerometer, recDevice::controller, NULL, SDL_SYS_AccelerometerUpdate(), and SDL_SYS_MFIJoystickUpdate().

Referenced by SDL_GameControllerOpen(), SDL_JoystickOpen(), and SDL_JoystickUpdate().

570 {
571  SDL_JoystickDeviceItem *device = joystick->hwdata;
572 
573  if (device == NULL) {
574  return;
575  }
576 
577  if (device->accelerometer) {
578  SDL_SYS_AccelerometerUpdate(joystick);
579  } else if (device->controller) {
580  SDL_SYS_MFIJoystickUpdate(joystick);
581  }
582 }
static void SDL_SYS_MFIJoystickUpdate(SDL_Joystick *joystick)
#define NULL
Definition: begin_code.h:143
static void SDL_SYS_AccelerometerUpdate(SDL_Joystick *joystick)
GCController __unsafe_unretained * controller
int SDL_SYS_NumJoysticks ( )

Definition at line 309 of file SDL_sysjoystick.m.

References numjoysticks.

Referenced by SDL_NumJoysticks().

310 {
311  return numjoysticks;
312 }
static int numjoysticks