22#include "SDL_config.h"
24#ifdef SDL_SENSOR_COREMOTION
27#include <CoreMotion/CoreMotion.h>
32#include "../SDL_syssensor.h"
33#include "../SDL_sensor_c.h"
39} SDL_CoreMotionSensor;
41static CMMotionManager *SDL_motion_manager;
43static int SDL_sensors_count;
46SDL_COREMOTION_SensorInit(
void)
48 int i, sensors_count = 0;
50 if (!SDL_motion_manager) {
51 SDL_motion_manager = [[CMMotionManager alloc] init];
54 if (SDL_motion_manager.accelerometerAvailable) {
57 if (SDL_motion_manager.gyroAvailable) {
61 if (sensors_count > 0) {
68 if (SDL_motion_manager.accelerometerAvailable) {
73 if (SDL_motion_manager.gyroAvailable) {
78 SDL_sensors_count = sensors_count;
84SDL_COREMOTION_SensorGetCount(
void)
86 return SDL_sensors_count;
90SDL_COREMOTION_SensorDetect(
void)
95SDL_COREMOTION_SensorGetDeviceName(
int device_index)
99 return "Accelerometer";
108SDL_COREMOTION_SensorGetDeviceType(
int device_index)
114SDL_COREMOTION_SensorGetDeviceNonPortableType(
int device_index)
120SDL_COREMOTION_SensorGetDeviceInstanceID(
int device_index)
126SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor,
int device_index)
131 if (hwdata ==
NULL) {
134 sensor->hwdata = hwdata;
136 switch (sensor->type)
139 [SDL_motion_manager startAccelerometerUpdates];
142 [SDL_motion_manager startGyroUpdates];
151SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor)
153 switch (sensor->type)
157 CMAccelerometerData *accelerometerData = SDL_motion_manager.accelerometerData;
158 if (accelerometerData) {
159 CMAcceleration acceleration = accelerometerData.acceleration;
173 CMGyroData *gyroData = SDL_motion_manager.gyroData;
175 CMRotationRate rotationRate = gyroData.rotationRate;
177 data[0] = rotationRate.x;
178 data[1] = rotationRate.y;
179 data[2] = rotationRate.z;
193SDL_COREMOTION_SensorClose(SDL_Sensor *sensor)
195 if (sensor->hwdata) {
196 switch (sensor->type)
199 [SDL_motion_manager stopAccelerometerUpdates];
202 [SDL_motion_manager stopGyroUpdates];
208 sensor->hwdata =
NULL;
213SDL_COREMOTION_SensorQuit(
void)
219 SDL_COREMOTION_SensorInit,
220 SDL_COREMOTION_SensorGetCount,
221 SDL_COREMOTION_SensorDetect,
222 SDL_COREMOTION_SensorGetDeviceName,
223 SDL_COREMOTION_SensorGetDeviceType,
224 SDL_COREMOTION_SensorGetDeviceNonPortableType,
225 SDL_COREMOTION_SensorGetDeviceInstanceID,
226 SDL_COREMOTION_SensorOpen,
227 SDL_COREMOTION_SensorUpdate,
228 SDL_COREMOTION_SensorClose,
229 SDL_COREMOTION_SensorQuit,
#define SDL_OutOfMemory()
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLuint GLsizei GLenum type
static SDL_Sensor * SDL_sensors
SDL_SensorID SDL_GetNextSensorInstanceID()
int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
#define SDL_STANDARD_GRAVITY
#define SDL_arraysize(array)
SDL_SensorDriver SDL_COREMOTION_SensorDriver
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)