Skip to content

Commit

Permalink
Added the iOS sensor implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 22, 2018
1 parent bdbc06b commit c6647bf
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 6 deletions.
44 changes: 44 additions & 0 deletions Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
Expand Up @@ -195,6 +195,14 @@
AADC5A631FDA10C800960936 /* SDL_shaders_metal_ios.h in Headers */ = {isa = PBXBuildFile; fileRef = AADC5A611FDA10C800960936 /* SDL_shaders_metal_ios.h */; };
AADC5A641FDA10C800960936 /* SDL_render_metal.m in Sources */ = {isa = PBXBuildFile; fileRef = AADC5A621FDA10C800960936 /* SDL_render_metal.m */; };
AADC5A651FDA10CB00960936 /* SDL_render_metal.m in Sources */ = {isa = PBXBuildFile; fileRef = AADC5A621FDA10C800960936 /* SDL_render_metal.m */; };
F30D9C99212CD0360047DF2E /* SDL_sensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F30D9C98212CD0360047DF2E /* SDL_sensor.h */; };
F30D9C9E212CD0990047DF2E /* SDL_sensor_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F30D9C9B212CD0980047DF2E /* SDL_sensor_c.h */; };
F30D9C9F212CD0990047DF2E /* SDL_syssensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F30D9C9C212CD0990047DF2E /* SDL_syssensor.h */; };
F30D9CA0212CD0990047DF2E /* SDL_sensor.c in Sources */ = {isa = PBXBuildFile; fileRef = F30D9C9D212CD0990047DF2E /* SDL_sensor.c */; };
F30D9CA1212CD0990047DF2E /* SDL_sensor.c in Sources */ = {isa = PBXBuildFile; fileRef = F30D9C9D212CD0990047DF2E /* SDL_sensor.c */; };
F30D9CA5212CD0BF0047DF2E /* SDL_coremotionsensor.m in Sources */ = {isa = PBXBuildFile; fileRef = F30D9CA3212CD0BF0047DF2E /* SDL_coremotionsensor.m */; };
F30D9CA6212CD0BF0047DF2E /* SDL_coremotionsensor.m in Sources */ = {isa = PBXBuildFile; fileRef = F30D9CA3212CD0BF0047DF2E /* SDL_coremotionsensor.m */; };
F30D9CA7212CD0BF0047DF2E /* SDL_coremotionsensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F30D9CA4212CD0BF0047DF2E /* SDL_coremotionsensor.h */; };
F3BDD77620F51C3C004ECBF3 /* hid.mm in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD77520F51C3C004ECBF3 /* hid.mm */; };
F3BDD79220F51CB8004ECBF3 /* SDL_hidapi_xbox360.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */; };
F3BDD79320F51CB8004ECBF3 /* SDL_hidapi_xbox360.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */; };
Expand Down Expand Up @@ -521,6 +529,12 @@
AADA5B8E16CCAB7C00107CF7 /* SDL_bits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_bits.h; sourceTree = "<group>"; };
AADC5A611FDA10C800960936 /* SDL_shaders_metal_ios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_shaders_metal_ios.h; sourceTree = "<group>"; };
AADC5A621FDA10C800960936 /* SDL_render_metal.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_render_metal.m; sourceTree = "<group>"; };
F30D9C98212CD0360047DF2E /* SDL_sensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sensor.h; sourceTree = "<group>"; };
F30D9C9B212CD0980047DF2E /* SDL_sensor_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sensor_c.h; sourceTree = "<group>"; };
F30D9C9C212CD0990047DF2E /* SDL_syssensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_syssensor.h; sourceTree = "<group>"; };
F30D9C9D212CD0990047DF2E /* SDL_sensor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_sensor.c; sourceTree = "<group>"; };
F30D9CA3212CD0BF0047DF2E /* SDL_coremotionsensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_coremotionsensor.m; sourceTree = "<group>"; };
F30D9CA4212CD0BF0047DF2E /* SDL_coremotionsensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_coremotionsensor.h; sourceTree = "<group>"; };
F3BDD77520F51C3C004ECBF3 /* hid.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = hid.mm; sourceTree = "<group>"; };
F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_xbox360.c; sourceTree = "<group>"; };
F3BDD78C20F51CB8004ECBF3 /* SDL_hidapi_switch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_switch.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -814,6 +828,26 @@
path = metal;
sourceTree = "<group>";
};
F30D9C9A212CD0590047DF2E /* sensor */ = {
isa = PBXGroup;
children = (
F30D9CA2212CD09E0047DF2E /* coremotion */,
F30D9C9B212CD0980047DF2E /* SDL_sensor_c.h */,
F30D9C9D212CD0990047DF2E /* SDL_sensor.c */,
F30D9C9C212CD0990047DF2E /* SDL_syssensor.h */,
);
path = sensor;
sourceTree = "<group>";
};
F30D9CA2212CD09E0047DF2E /* coremotion */ = {
isa = PBXGroup;
children = (
F30D9CA4212CD0BF0047DF2E /* SDL_coremotionsensor.h */,
F30D9CA3212CD0BF0047DF2E /* SDL_coremotionsensor.m */,
);
path = coremotion;
sourceTree = "<group>";
};
F35CEA6E20F51B7F003ECE98 /* hidapi */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -976,6 +1010,7 @@
AA7558891595D55500BBD41B /* SDL_revision.h */,
AA75588A1595D55500BBD41B /* SDL_rwops.h */,
AA75588B1595D55500BBD41B /* SDL_scancode.h */,
F30D9C98212CD0360047DF2E /* SDL_sensor.h */,
AA75588C1595D55500BBD41B /* SDL_shape.h */,
AA75588D1595D55500BBD41B /* SDL_stdinc.h */,
AA75588E1595D55500BBD41B /* SDL_surface.h */,
Expand Down Expand Up @@ -1009,6 +1044,7 @@
FD8BD8150E27E25900B52CD5 /* loadso */,
56ED04DE118A8E9A00A56AA6 /* power */,
041B2CE312FA0F680087D585 /* render */,
F30D9C9A212CD0590047DF2E /* sensor */,
FD3F4A6F0DEA620800C5B771 /* stdlib */,
FD99B9E00DD52EDC00FB1D6B /* thread */,
FD99BA1E0DD52EDC00FB1D6B /* timer */,
Expand Down Expand Up @@ -1263,6 +1299,7 @@
AA75589C1595D55500BBD41B /* SDL_audio.h in Headers */,
55FFA91A2122302B00D7CBED /* SDL_syspower.h in Headers */,
AA75589D1595D55500BBD41B /* SDL_blendmode.h in Headers */,
F30D9C9E212CD0990047DF2E /* SDL_sensor_c.h in Headers */,
AA75589E1595D55500BBD41B /* SDL_clipboard.h in Headers */,
AA75589F1595D55500BBD41B /* SDL_config_iphoneos.h in Headers */,
AA7558A01595D55500BBD41B /* SDL_config.h in Headers */,
Expand All @@ -1277,13 +1314,15 @@
AA7558A71595D55500BBD41B /* SDL_haptic.h in Headers */,
AA7558A81595D55500BBD41B /* SDL_hints.h in Headers */,
566726461DF72CF5001DD3DB /* SDL_dataqueue.h in Headers */,
F30D9C9F212CD0990047DF2E /* SDL_syssensor.h in Headers */,
AA7558AA1595D55500BBD41B /* SDL_joystick.h in Headers */,
AA13B34B1FB8B27800D9FEE6 /* SDL_shape_internals.h in Headers */,
AA7558AB1595D55500BBD41B /* SDL_keyboard.h in Headers */,
A704172E20F7E74800A82227 /* controller_type.h in Headers */,
AA7558AC1595D55500BBD41B /* SDL_keycode.h in Headers */,
AA7558AD1595D55500BBD41B /* SDL_loadso.h in Headers */,
AA7558AE1595D55500BBD41B /* SDL_log.h in Headers */,
F30D9CA7212CD0BF0047DF2E /* SDL_coremotionsensor.h in Headers */,
AA7558AF1595D55500BBD41B /* SDL_main.h in Headers */,
AA7558B01595D55500BBD41B /* SDL_mouse.h in Headers */,
AA7558B11595D55500BBD41B /* SDL_mutex.h in Headers */,
Expand All @@ -1306,6 +1345,7 @@
FAD4F7021BA3C4E8008346CE /* SDL_sysjoystick_c.h in Headers */,
AA7558C11595D55500BBD41B /* SDL_surface.h in Headers */,
AA7558C21595D55500BBD41B /* SDL_system.h in Headers */,
F30D9C99212CD0360047DF2E /* SDL_sensor.h in Headers */,
AA7558C31595D55500BBD41B /* SDL_syswm.h in Headers */,
AA7558C41595D55500BBD41B /* SDL_thread.h in Headers */,
AA7558C51595D55500BBD41B /* SDL_timer.h in Headers */,
Expand Down Expand Up @@ -1495,9 +1535,11 @@
AADC5A651FDA10CB00960936 /* SDL_render_metal.m in Sources */,
FAB598561BB5C31600BE72C5 /* SDL_sysloadso.c in Sources */,
FAB598571BB5C31600BE72C5 /* SDL_power.c in Sources */,
F30D9CA1212CD0990047DF2E /* SDL_sensor.c in Sources */,
FAB598581BB5C31600BE72C5 /* SDL_syspower.m in Sources */,
56F9D5601DF73BA400C15B5D /* SDL_dataqueue.c in Sources */,
FAB598591BB5C31600BE72C5 /* SDL_render_gles.c in Sources */,
F30D9CA6212CD0BF0047DF2E /* SDL_coremotionsensor.m in Sources */,
FAB5985A1BB5C31600BE72C5 /* SDL_render_gles2.c in Sources */,
FAB5985B1BB5C31600BE72C5 /* SDL_shaders_gles2.c in Sources */,
FAB5985D1BB5C31600BE72C5 /* SDL_blendfillrect.c in Sources */,
Expand Down Expand Up @@ -1570,6 +1612,7 @@
files = (
FD6526810DE8FCDD002AD96B /* SDL_systimer.c in Sources */,
FD6526800DE8FCDD002AD96B /* SDL_timer.c in Sources */,
F30D9CA5212CD0BF0047DF2E /* SDL_coremotionsensor.m in Sources */,
FD3F4A7B0DEA620800C5B771 /* SDL_string.c in Sources */,
FD6526660DE8FCDD002AD96B /* SDL_dummyaudio.c in Sources */,
FD6526670DE8FCDD002AD96B /* SDL_audio.c in Sources */,
Expand Down Expand Up @@ -1667,6 +1710,7 @@
0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */,
04BAC09D1300C1290055DE28 /* SDL_log.c in Sources */,
56EA86FB13E9EC2B002E47EB /* SDL_coreaudio.m in Sources */,
F30D9CA0212CD0990047DF2E /* SDL_sensor.c in Sources */,
F3BDD79420F51CB8004ECBF3 /* SDL_hidapi_switch.c in Sources */,
93CB792613FC5F5300BD3E05 /* SDL_uikitviewcontroller.m in Sources */,
AA628ADB159369E3005138DD /* SDL_rotate.c in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_config_iphoneos.h
Expand Up @@ -139,8 +139,8 @@
#define SDL_JOYSTICK_MFI 1
#define SDL_JOYSTICK_HIDAPI 1

/* Enable the dummy sensor driver */
#define SDL_SENSOR_DUMMY 1
/* Enable the CoreMotion sensor driver */
#define SDL_SENSOR_COREMOTION 1

/* Enable Unix style SO loading */
#define SDL_LOADSO_DLOPEN 1
Expand Down
3 changes: 3 additions & 0 deletions src/sensor/SDL_sensor.c
Expand Up @@ -36,6 +36,9 @@ static SDL_SensorDriver *SDL_sensor_drivers[] = {
#ifdef SDL_SENSOR_ANDROID
&SDL_ANDROID_SensorDriver,
#endif
#ifdef SDL_SENSOR_COREMOTION
&SDL_COREMOTION_SensorDriver,
#endif
#if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED)
&SDL_DUMMY_SensorDriver
#endif
Expand Down
1 change: 1 addition & 0 deletions src/sensor/SDL_syssensor.h
Expand Up @@ -93,6 +93,7 @@ typedef struct _SDL_SensorDriver

/* The available sensor drivers */
extern SDL_SensorDriver SDL_ANDROID_SensorDriver;
extern SDL_SensorDriver SDL_COREMOTION_SensorDriver;
extern SDL_SensorDriver SDL_DUMMY_SensorDriver;

/* vi: set ts=4 sw=4 expandtab: */
4 changes: 2 additions & 2 deletions src/sensor/android/SDL_androidsensor.c
Expand Up @@ -156,7 +156,7 @@ SDL_ANDROID_SensorOpen(SDL_Sensor *sensor, int device_index)
}

static void
SDL_ANDROID_SensorUpdate(SDL_Sensor* sensor)
SDL_ANDROID_SensorUpdate(SDL_Sensor *sensor)
{
int events;
ASensorEvent event;
Expand All @@ -171,7 +171,7 @@ SDL_ANDROID_SensorUpdate(SDL_Sensor* sensor)
}

static void
SDL_ANDROID_SensorClose(SDL_Sensor * sensor)
SDL_ANDROID_SensorClose(SDL_Sensor *sensor)
{
if (sensor->hwdata) {
ASensorEventQueue_disableSensor(sensor->hwdata->eventqueue, sensor->hwdata->asensor);
Expand Down
30 changes: 30 additions & 0 deletions src/sensor/coremotion/SDL_coremotionsensor.h
@@ -0,0 +1,30 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"

/* The private structure used to keep track of a sensor */
struct sensor_hwdata
{
float data[3];
};


/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit c6647bf

Please sign in to comment.