24 #ifdef SDL_SENSOR_COREMOTION 27 #include <CoreMotion/CoreMotion.h> 32 #include "../SDL_syssensor.h" 33 #include "../SDL_sensor_c.h" 39 } SDL_CoreMotionSensor;
41 static CMMotionManager *SDL_motion_manager;
43 static int SDL_sensors_count;
46 SDL_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;
84 SDL_COREMOTION_SensorGetCount(
void)
86 return SDL_sensors_count;
90 SDL_COREMOTION_SensorDetect(
void)
95 SDL_COREMOTION_SensorGetDeviceName(
int device_index)
99 return "Accelerometer";
108 SDL_COREMOTION_SensorGetDeviceType(
int device_index)
114 SDL_COREMOTION_SensorGetDeviceNonPortableType(
int device_index)
120 SDL_COREMOTION_SensorGetDeviceInstanceID(
int device_index)
126 SDL_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];
151 SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor)
153 switch (sensor->type)
157 CMAccelerometerData *accelerometerData = SDL_motion_manager.accelerometerData;
158 if (accelerometerData) {
159 CMAcceleration acceleration = accelerometerData.acceleration;
164 if (
SDL_memcmp(data, sensor->hwdata->data,
sizeof(data)) != 0) {
166 SDL_memcpy(sensor->hwdata->data, data,
sizeof(data));
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;
180 if (
SDL_memcmp(data, sensor->hwdata->data,
sizeof(data)) != 0) {
182 SDL_memcpy(sensor->hwdata->data, data,
sizeof(data));
193 SDL_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;
213 SDL_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,
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
SDL_SensorID SDL_GetNextSensorInstanceID()
static SDL_Sensor * SDL_sensors
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)
#define SDL_OutOfMemory()
SDL_SensorDriver SDL_COREMOTION_SensorDriver
GLuint GLuint GLsizei GLenum type
#define SDL_arraysize(array)
#define SDL_STANDARD_GRAVITY