diff -r 177f29ae5279 Android.mk --- a/Android.mk Sat Feb 16 23:09:10 2013 -0800 +++ b/Android.mk Fri Mar 22 17:56:11 2013 +0100 @@ -28,6 +28,8 @@ $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/sensor/*.c) \ + $(wildcard $(LOCAL_PATH)/src/sensor/android/*.c) \ $(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \ $(wildcard $(LOCAL_PATH)/src/power/*.c) \ $(wildcard $(LOCAL_PATH)/src/power/android/*.c) \ @@ -42,6 +44,6 @@ $(wildcard $(LOCAL_PATH)/src/video/android/*.c)) LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog +LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid include $(BUILD_SHARED_LIBRARY) diff -r 177f29ae5279 android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Sat Feb 16 23:09:10 2013 -0800 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Fri Mar 22 17:56:11 2013 +0100 @@ -34,6 +34,9 @@ // Keep track of the paused state public static boolean mIsPaused; + // Does this device have an accelerometer? + public static boolean mHasAccel; + // Main components private static SDLActivity mSingleton; private static SDLSurface mSurface; @@ -180,6 +183,10 @@ mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title); } + public static boolean hasAccel() { + return mHasAccel; + } + public static void sendMessage(int command, int param) { mSingleton.sendCommand(command, Integer.valueOf(param)); } @@ -481,6 +488,11 @@ setOnTouchListener(this); mSensorManager = (SensorManager)context.getSystemService("sensor"); + if(mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) { + SDLActivity.mHasAccel = true; + } else { + SDLActivity.mHasAccel = false; + } // Some arbitrary defaults to avoid a potential division by zero mWidth = 1.0f; @@ -618,14 +630,20 @@ // Sensor events public void enableSensor(int sensortype, boolean enabled) { - // TODO: This uses getDefaultSensor - what if we have >1 accels? - if (enabled) { - mSensorManager.registerListener(this, - mSensorManager.getDefaultSensor(sensortype), - SensorManager.SENSOR_DELAY_GAME, null); - } else { - mSensorManager.unregisterListener(this, - mSensorManager.getDefaultSensor(sensortype)); + Sensor mSensor; + + // First, try to determine if the device actually has that kind of sensor + mSensor = mSensorManager.getDefaultSensor(sensortype); + if(mSensor != null) { + // TODO: This uses getDefaultSensor - what if we have >1 accels? + if (enabled) { + mSensorManager.registerListener(this, + mSensor, + SensorManager.SENSOR_DELAY_GAME, null); + } else { + mSensorManager.unregisterListener(this, + mSensor); + } } } diff -r 177f29ae5279 include/SDL.h --- a/include/SDL.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL.h Fri Mar 22 17:56:11 2013 +0100 @@ -74,6 +74,7 @@ #include "SDL_error.h" #include "SDL_events.h" #include "SDL_gamecontroller.h" +#include "SDL_sensor.h" #include "SDL_hints.h" #include "SDL_loadso.h" #include "SDL_log.h" @@ -111,6 +112,7 @@ #define SDL_INIT_JOYSTICK 0x00000200 #define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_GAMECONTROLLER 0x00002000 /**< turn on game controller also implicitly does JOYSTICK */ +#define SDL_INIT_SENSOR 0x00004000 #define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ #define SDL_INIT_EVERYTHING 0x0000FFFF /*@}*/ diff -r 177f29ae5279 include/SDL_config_android.h --- a/include/SDL_config_android.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_android.h Fri Mar 22 17:56:11 2013 +0100 @@ -111,6 +111,7 @@ /* Enable various input drivers */ #define SDL_JOYSTICK_ANDROID 1 #define SDL_HAPTIC_DUMMY 1 +#define SDL_SENSOR_ANDROID 1 /* Enable various shared object loading systems */ #define SDL_LOADSO_DLOPEN 1 diff -r 177f29ae5279 include/SDL_config_iphoneos.h --- a/include/SDL_config_iphoneos.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_iphoneos.h Fri Mar 22 17:56:11 2013 +0100 @@ -143,6 +143,9 @@ /* enable joystick subsystem */ #define SDL_JOYSTICK_DISABLED 0 +/* use dummy sensor driver */ +#define SDL_SENSOR_DUMMY 1 + /* Set max recognized G-force from accelerometer See src/joystick/uikit/SDLUIAccelerationDelegate.m for notes on why this is needed */ diff -r 177f29ae5279 include/SDL_config_macosx.h --- a/include/SDL_config_macosx.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_macosx.h Fri Mar 22 17:56:11 2013 +0100 @@ -115,6 +115,9 @@ /* Enable various input drivers */ #define SDL_JOYSTICK_IOKIT 1 +/* use dummy sensor driver */ +#define SDL_SENSOR_DUMMY 1 + #define SDL_HAPTIC_IOKIT 1 /* Enable various shared object loading systems */ diff -r 177f29ae5279 include/SDL_config_nintendods.h --- a/include/SDL_config_nintendods.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_nintendods.h Fri Mar 22 17:56:11 2013 +0100 @@ -100,6 +100,9 @@ #define SDL_JOYSTICK_NDS 1 /*#define SDL_JOYSTICK_DUMMY 1 TODO: uncomment this later*/ +/* use dummy sensor driver */ +#define SDL_SENSOR_DUMMY 1 + /* DS has no dynamic linking afaik */ #define SDL_LOADSO_DISABLED 1 diff -r 177f29ae5279 include/SDL_config_pandora.h --- a/include/SDL_config_pandora.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_pandora.h Fri Mar 22 17:56:11 2013 +0100 @@ -107,6 +107,7 @@ #define SDL_INPUT_TSLIB 1 #define SDL_JOYSTICK_LINUX 1 #define SDL_HAPTIC_LINUX 1 +#define SDL_SENSOR_DUMMY 1 #define SDL_LOADSO_DLOPEN 1 diff -r 177f29ae5279 include/SDL_config_windows.h --- a/include/SDL_config_windows.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_windows.h Fri Mar 22 17:56:11 2013 +0100 @@ -153,6 +153,9 @@ #define SDL_JOYSTICK_DINPUT 1 #define SDL_HAPTIC_DINPUT 1 +/* Enable dummy sensor driver */ +#define SDL_SENSOR_DUMMY 1 + /* Enable various shared object loading systems */ #define SDL_LOADSO_WINDOWS 1 diff -r 177f29ae5279 include/SDL_config_wiz.h --- a/include/SDL_config_wiz.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_config_wiz.h Fri Mar 22 17:56:11 2013 +0100 @@ -103,6 +103,7 @@ #define SDL_INPUT_TSLIB 1 #define SDL_JOYSTICK_LINUX 1 #define SDL_HAPTIC_LINUX 1 +#define SDL_SENSOR_DUMMY 1 #define SDL_LOADSO_DLOPEN 1 diff -r 177f29ae5279 include/SDL_hints.h --- a/include/SDL_hints.h Sat Feb 16 23:09:10 2013 -0800 +++ b/include/SDL_hints.h Fri Mar 22 17:56:11 2013 +0100 @@ -214,6 +214,18 @@ */ #define SDL_HINT_ALLOW_TOPMOST "SDL_ALLOW_TOPMOST" +/** + * \brief If set to 0 then SDL won't fake your Android system's accelerometer as a joystick. + * + * By default SDL creates a virtual joystick device that actually contains accelerometer data. + * Setting this variable to "0" disables that behaviour. The default it "1" + * + * This variable can be set to the following values: + * "0" - Accelerometer won't be presented as a joystick + * "1" - Accelerometer will be presented as a joystick + */ +#define SDL_HINT_ACCELASJOY "SDL_ACCELASJOY" + /** diff -r 177f29ae5279 include/SDL_sensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SDL_sensor.h Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,173 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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. +*/ + +/** + * \file SDL_sensor.h + * + * Include file for SDL sensor event handling + * + */ + +#ifndef _SDL_sensor_h +#define _SDL_sensor_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \file SDL_sensor.h + * + * In order to use these functions, SDL_Init() must have been called + * with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system + * for sensors, and load appropriate drivers. + */ + +/* The sensor structure used to identify an SDL sensor */ +struct _SDL_Sensor; +typedef struct _SDL_Sensor SDL_Sensor; + +/* A structure that encodes the stable unique id for a sensor device */ +typedef struct { + Uint8 data[16]; +} SDL_SensorGUID; + +typedef int SDL_SensorID; + +/* The different sensor types */ +typedef enum +{ + SDL_SENSOR_UNKNOWN = 0x00000000, /**< unknown sensor type */ + SDL_SENSOR_ACCEL = 0x00000001, /**< accelerometer */ + SDL_SENSOR_MAGNET = 0x00000002, /**< magnetometer */ + SDL_SENSOR_ORIENTATION = 0x00000003, /**< orientation sensor */ + SDL_SENSOR_GYRO = 0x00000004, /**< gyroscope */ + SDL_SENSOR_LIGHT = 0x00000005, /**< light sensor */ + SDL_SENSOR_PRESSURE = 0x00000006, /**< pressure sensor */ + SDL_SENSOR_TEMPERATURE = 0x00000007, /**< temperature sensor */ + SDL_SENSOR_PROXIMITY = 0x00000008, /**< proximity sensor */ + SDL_SENSOR_GRAVITY = 0x00000009, /**< gravity sensor */ + SDL_SENSOR_LACCEL = 0x0000000a, /**< linear acceleration sensor */ + SDL_SENSOR_ROTVECTOR = 0x0000000b, /**< rotation vector sensor */ + SDL_SENSOR_RHUMIDITY = 0x0000000c /**< relative humidity sensor */ +} SDL_SensorFlags; + +/* Function prototypes */ +/** + * Count the number of sensors attached to the system right now + */ +extern DECLSPEC int SDLCALL SDL_NumSensors(void); + +/** + * Get the implementation dependent name of a sensor. + * This can be called before any sensors are opened. + * If no name can be found, this function returns NULL. + */ +extern DECLSPEC const char *SDLCALL SDL_SensorNameForIndex(int device_index); + +/** + * Open a sensor for use. + * The index passed as an argument refers tothe N'th sensor on the system. + * This index is the value which will identify this sensor in future sensor + * events. + * + * \return A sensor identifier, or NULL if an error occurred. + */ +extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorOpen(int device_index); + +/** + * Return the name for this currently opened sensor. + * If no name can be found, this function returns NULL. + */ +extern DECLSPEC const char *SDLCALL SDL_SensorName(SDL_Sensor * sensor); + +/** + * Returns SDL_TRUE if the sensor has been opened and currently connected, or SDL_FALSE if it has not. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_SensorGetAttached(SDL_Sensor * sensor); + +/** + * Get the instance ID of an opened sensor. + */ +extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorInstanceID(SDL_Sensor * sensor); + +/** + * Get the number of general axis controls on a sensor. + */ +extern DECLSPEC int SDLCALL SDL_SensorNumAxes(SDL_Sensor * sensor); + +/** + * Get the sensor type for an opened sensor. + */ +extern DECLSPEC SDL_SensorFlags SDLCALL SDL_SensorType(SDL_Sensor * sensor); + +/** + * Update the current state of the open sensors. + * + * This is called automatically by the event loop if any sensor + * events are enabled. + */ +extern DECLSPEC void SDLCALL SDL_SensorUpdate(void); + +/** + * Get the current state of an axis on a sensor. + * + * The returned value is a physical magnitude dependant on the + * type of sensor. + * + * The axis indices start at index 0. + */ +extern DECLSPEC float SDLCALL SDL_SensorGetAxis(SDL_Sensor * sensor, + int axis); + +/** + * Get the current resolution of an axis on a sensor. + * + * The returned value is the resolution for that sensor + * (the minimum change in the measured magnitude discernible + * by the sensor). + */ +extern DECLSPEC float SDLCALL SDL_SensorGetResolution(SDL_Sensor * sensor); + +/** + * Close a sensor previously opened with SDL_SensorOpen(). + */ +extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor * sensor); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_sensor_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/SDL.c --- a/src/SDL.c Sat Feb 16 23:09:10 2013 -0800 +++ b/src/SDL.c Fri Mar 22 17:56:11 2013 +0100 @@ -173,6 +173,18 @@ #endif } + if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_SENSOR)) { +#if !SDL_SENSOR_DISABLED + if (SDL_SensorInit() < 0) { + return (-1); + } + SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR); +#else + SDL_SetError("SDL not built with sensor support"); + return (-1); +#endif + } + /* Initialize the haptic subsystem */ if (SDL_PrivateShouldInitSubsystem(flags, SDL_INIT_HAPTIC)) { #if !SDL_HAPTIC_DISABLED @@ -241,6 +253,15 @@ } #endif +#if !SDL_SENSOR_DISABLED + if ((flags & SDL_INIT_SENSOR)) { + if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) { + SDL_SensorQuit(); + } + SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR); + } +#endif + #if !SDL_HAPTIC_DISABLED if ((flags & SDL_INIT_HAPTIC)) { if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) { diff -r 177f29ae5279 src/core/android/SDL_android.cpp --- a/src/core/android/SDL_android.cpp Sat Feb 16 23:09:10 2013 -0800 +++ b/src/core/android/SDL_android.cpp Fri Mar 22 17:56:11 2013 +0100 @@ -363,6 +363,19 @@ return retval; } +extern "C" SDL_bool Android_JNI_HasAccelerometer() +{ + jmethodID mid; + jboolean has = JNI_FALSE; + JNIEnv *mEnv = Android_JNI_GetEnv(); + mid = mEnv->GetStaticMethodID(mActivityClass,"hasAccel","()Z"); + if (mid) { + has = mEnv->CallBooleanMethod(mActivityClass, mid); + } + + return has ? SDL_TRUE : SDL_FALSE; +} + static void Android_JNI_ThreadDestroyed(void* value) { /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */ JNIEnv *env = (JNIEnv*) value; diff -r 177f29ae5279 src/core/android/SDL_android.h --- a/src/core/android/SDL_android.h Sat Feb 16 23:09:10 2013 -0800 +++ b/src/core/android/SDL_android.h Fri Mar 22 17:56:11 2013 +0100 @@ -34,6 +34,7 @@ extern void Android_JNI_SwapWindow(); extern void Android_JNI_SetActivityTitle(const char *title); extern SDL_bool Android_JNI_GetAccelerometerValues(float values[3]); +extern SDL_bool Android_JNI_HasAccelerometer(); extern void Android_JNI_ShowTextInput(SDL_Rect *inputRect); extern void Android_JNI_HideTextInput(); diff -r 177f29ae5279 src/joystick/SDL_joystick.c --- a/src/joystick/SDL_joystick.c Sat Feb 16 23:09:10 2013 -0800 +++ b/src/joystick/SDL_joystick.c Fri Mar 22 17:56:11 2013 +0100 @@ -25,6 +25,7 @@ #include "SDL_events.h" #include "SDL_sysjoystick.h" #include "SDL_assert.h" +#include "SDL_hints.h" #if !SDL_EVENTS_DISABLED #include "../events/SDL_events_c.h" @@ -768,5 +769,24 @@ return guid; } +/* Function to determine if SDL should fake the accelerometer as the last joystick + * based on SDL_HINT_ACCELASJOY value and compilation preprocessor options. + */ +SDL_bool SDL_PrivateAccelAsJoy() +{ +#ifdef SDL_SENSOR_DISABLED + return SDL_FALSE; +#else + const char *hint = SDL_GetHint(SDL_HINT_ACCELASJOY); + if (hint) { + if (*hint == '0') { + return SDL_FALSE; + } else { + return SDL_TRUE; + } + } + return SDL_TRUE; +#endif +} /* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/joystick/SDL_joystick_c.h --- a/src/joystick/SDL_joystick_c.h Sat Feb 16 23:09:10 2013 -0800 +++ b/src/joystick/SDL_joystick_c.h Fri Mar 22 17:56:11 2013 +0100 @@ -48,4 +48,7 @@ /* Internal sanity checking functions */ extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick); +/* Should SDL fake a joystick for accelerometer data? */ +extern SDL_bool SDL_PrivateAccelAsJoy(); + /* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/joystick/android/SDL_sysjoystick.c --- a/src/joystick/android/SDL_sysjoystick.c Sat Feb 16 23:09:10 2013 -0800 +++ b/src/joystick/android/SDL_sysjoystick.c Fri Mar 22 17:56:11 2013 +0100 @@ -34,6 +34,7 @@ #include "../../core/android/SDL_android.h" static const char *accelerometerName = "Android accelerometer"; +static SDL_bool hasAccel = SDL_FALSE; /* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available @@ -43,12 +44,22 @@ int SDL_SYS_JoystickInit(void) { - return (1); + // The whole emulation code only has sense if the device has + // an accelerometer + if(Android_JNI_HasAccelerometer()) { + hasAccel = SDL_TRUE; + } + + return 0; } int SDL_SYS_NumJoysticks() { - return 1; + if(hasAccel && SDL_PrivateAccelAsJoy()) { + return 1; + } + + return 0; } void SDL_SYS_JoystickDetect() @@ -64,7 +75,12 @@ const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index) { - return accelerometerName; + if(hasAccel && SDL_PrivateAccelAsJoy()) { + return accelerometerName; + } + + SDL_SetError("Logic error: No joysticks available"); + return (NULL); } /* Function to perform the mapping from device index to the instance id for this index */ @@ -81,16 +97,16 @@ int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { - if (device_index == 0) { + if (device_index == 0 && hasAccel && SDL_PrivateAccelAsJoy()) { joystick->nbuttons = 0; joystick->nhats = 0; joystick->nballs = 0; joystick->naxes = 3; return 0; - } else { - SDL_SetError("No joystick available with that index"); - return (-1); - } + } else { + SDL_SetError("No joystick available with that index"); + return (-1); + } } /* Function to determine is this joystick is attached to the system right now */ @@ -111,10 +127,12 @@ Sint16 value; float values[3]; - if (Android_JNI_GetAccelerometerValues(values)) { - for ( i = 0; i < 3; i++ ) { - value = (Sint16)(values[i] * 32767.0f); - SDL_PrivateJoystickAxis(joystick, i, value); + if(hasAccel && SDL_PrivateAccelAsJoy()) { + if (Android_JNI_GetAccelerometerValues(values)) { + for ( i = 0; i < 3; i++ ) { + value = (Sint16)(values[i] * 32767.0f); + SDL_PrivateJoystickAxis(joystick, i, value); + } } } } diff -r 177f29ae5279 src/joystick/iphoneos/SDL_sysjoystick.m --- a/src/joystick/iphoneos/SDL_sysjoystick.m Sat Feb 16 23:09:10 2013 -0800 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m Fri Mar 22 17:56:11 2013 +0100 @@ -42,7 +42,11 @@ int SDL_SYS_NumJoysticks() { - return 1; + if(SDL_PrivateAccelAsJoy()) { + return 1; + } + + return 0; } void SDL_SYS_JoystickDetect() @@ -58,7 +62,12 @@ const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index) { - return accelerometerName; + if(SDL_PrivateAccelAsJoy()) { + return accelerometerName; + } + + SDL_SetError("Logic error: No joysticks available"); + return (NULL); } /* Function to perform the mapping from device index to the instance id for this index */ @@ -75,12 +84,17 @@ int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index) { - joystick->naxes = 3; - joystick->nhats = 0; - joystick->nballs = 0; - joystick->nbuttons = 0; - [[SDLUIAccelerationDelegate sharedDelegate] startup]; - return 0; + if (device_index == 0 && SDL_PrivateAccelAsJoy()) { + joystick->naxes = 3; + joystick->nhats = 0; + joystick->nballs = 0; + joystick->nbuttons = 0; + [[SDLUIAccelerationDelegate sharedDelegate] startup]; + return 0; + } else { + SDL_SetError("No joystick available with that index"); + return (-1); + } } /* Function to determine is this joystick is attached to the system right now */ @@ -99,17 +113,19 @@ { Sint16 orientation[3]; + + if(SDL_PrivateAccelAsJoy()) { + if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) { - if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) { - - [[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation]; - [[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO]; + [[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation]; + [[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO]; - SDL_PrivateJoystickAxis(joystick, 0, orientation[0]); - SDL_PrivateJoystickAxis(joystick, 1, orientation[1]); - SDL_PrivateJoystickAxis(joystick, 2, orientation[2]); + SDL_PrivateJoystickAxis(joystick, 0, orientation[0]); + SDL_PrivateJoystickAxis(joystick, 1, orientation[1]); + SDL_PrivateJoystickAxis(joystick, 2, orientation[2]); - } + } + } return; } diff -r 177f29ae5279 src/sensor/SDL_sensor.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/SDL_sensor.c Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,410 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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" + +/* This is the sensor API for Simple DirectMedia Layer. + * It calls the platform-specific SDL_SYS_* functions. + * It's a design requirement that the data passed to those SDL_SYS_* + * functions must not be NULL. + */ + +#include "SDL_events.h" +#include "SDL_syssensor.h" +#include "SDL_assert.h" + +#if !SDL_EVENTS_DISABLED +#include "../events/SDL_events_c.h" +#endif + +static SDL_Sensor *SDL_sensors = NULL; +static SDL_Sensor *SDL_updating_sensor = NULL; + +int +SDL_SensorInit(void) +{ + int status; + + status = SDL_SYS_SensorInit(); + if (status >= 0) { + status = 0; + } + return (status); +} + +/* + * Count the number of sensors attached to the system + */ +int +SDL_NumSensors(void) +{ + return SDL_SYS_NumSensors(); +} + +/* + * Get the implementation dependent name of a sensor + */ +const char * +SDL_SensorNameForIndex(int device_index) +{ + if ((device_index < 0) || (device_index >= SDL_NumSensors())) { + SDL_SetError("There are %d sensors available", SDL_NumSensors()); + return (NULL); + } + return (SDL_SYS_SensorNameForDeviceIndex(device_index)); +} + +/* + * Open a sensor for use - the index passed as an argument refers to + * the N'th sensor on the system. This index is the value which will + * identify this sensor in future sensor events. + * + * This function returns a sensor identifier, or NULL if an error occurred. + */ +SDL_Sensor * +SDL_SensorOpen(int device_index) +{ + SDL_Sensor *sensor; + SDL_Sensor *sensorlist; + const char *sensorname = NULL; + + if ((device_index < 0) || (device_index >= SDL_NumSensors())) { + SDL_SetError("There are %d sensors available", SDL_NumSensors()); + return (NULL); + } + + sensorlist = SDL_sensors; + /* If the sensor is already open, return it + * it is important that we have a single sensor * for each instance id + */ + while ( sensorlist ) + { + if ( SDL_SYS_SensorGetInstanceIdOfDeviceIndex(device_index) == sensorlist->instance_id ) { + sensor = sensorlist; + ++sensor->ref_count; + return (sensor); + } + sensorlist = sensorlist->next; + } + + /* Create and initialize the sensor */ + sensor = (SDL_Sensor *) SDL_malloc((sizeof *sensor)); + if (sensor == NULL) { + SDL_OutOfMemory(); + return NULL; + } + + SDL_memset(sensor, 0, (sizeof *sensor)); + if (SDL_SYS_SensorOpen(sensor, device_index) < 0) { + SDL_free(sensor); + return NULL; + } + + sensorname = SDL_SYS_SensorNameForDeviceIndex( device_index ); + if ( sensorname ) + sensor->name = SDL_strdup( sensorname ); + else + sensor->name = NULL; + + if (sensor->naxes > 0) { + sensor->axes = (float *) SDL_malloc + (sensor->naxes * sizeof(float)); + } + if ( (sensor->naxes > 0) && (!sensor->axes) ) { + SDL_OutOfMemory(); + SDL_SensorClose(sensor); + return NULL; + } + if (sensor->axes) { + SDL_memset(sensor->axes, 0, sensor->naxes * sizeof(float)); + } + + /* Add sensor to list */ + ++sensor->ref_count; + /* Link the sensor in the list */ + sensor->next = SDL_sensors; + SDL_sensors = sensor; + + SDL_SYS_SensorUpdate( sensor ); + + return (sensor); +} + + +/* + * Checks to make sure the sensor is valid. + */ +int +SDL_PrivatesensorValid(SDL_Sensor * sensor) +{ + int valid; + + if ( sensor == NULL ) { + SDL_SetError("sensor hasn't been opened yet"); + valid = 0; + } else { + valid = 1; + } + + if ( sensor && sensor->closed ) + { + valid = 0; + } + + return valid; +} + +/* + * Get the number of multi-dimensional axis controls on a sensor + */ +int +SDL_SensorNumAxes(SDL_Sensor * sensor) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return (-1); + } + return (sensor->naxes); +} + +/* + * Get the number of multi-dimensional axis controls on a sensor + */ +SDL_SensorFlags +SDL_SensorType(SDL_Sensor * sensor) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return (-1); + } + return (sensor->type); +} + +/* + * Get the current state of an axis control on a sensor + */ +float +SDL_SensorGetAxis(SDL_Sensor * sensor, int axis) +{ + float state; + + if (!SDL_PrivatesensorValid(sensor)) { + return (0.0); + } + if (axis < sensor->naxes) { + state = sensor->axes[axis]; + } else { + state = 0.0; + } + return (state); +} + +/* + * Get the current resolution of an axis control on a sensor + */ +float +SDL_SensorGetResolution(SDL_Sensor * sensor) +{ + float state; + + if (!SDL_PrivatesensorValid(sensor)) { + return (0.0); + } + + return sensor->resolution; +} + +/* + * Return if the sensor in question is currently attached to the system, + * \return SDL_FALSE if not plugged in, SDL_TRUE if still present. + */ +SDL_bool +SDL_SensorGetAttached(SDL_Sensor * sensor) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return SDL_FALSE; + } + + return SDL_SYS_SensorAttached(sensor); +} + +/* + * Get the instance id for this opened sensor + */ +SDL_SensorID +SDL_SensorInstanceID(SDL_Sensor * sensor) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return (-1); + } + + return (sensor->instance_id); +} + +/* + * Get the friendly name of this sensor + */ +const char * +SDL_SensorName(SDL_Sensor * sensor) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return (NULL); + } + + return (sensor->name); +} + +/* + * Close a sensor previously opened with SDL_SensorOpen() + */ +void +SDL_SensorClose(SDL_Sensor * sensor) +{ + SDL_Sensor *sensorlist; + SDL_Sensor *sensorlistprev; + + if (!SDL_PrivatesensorValid(sensor)) { + return; + } + + /* First decrement ref count */ + if (--sensor->ref_count > 0) { + return; + } + + if (sensor == SDL_updating_sensor) { + return; + } + + SDL_SYS_SensorClose(sensor); + + sensorlist = SDL_sensors; + sensorlistprev = NULL; + while ( sensorlist ) + { + if (sensor == sensorlist) + { + if ( sensorlistprev ) + { + // unlink this entry + sensorlistprev->next = sensorlist->next; + } + else + { + SDL_sensors = sensor->next; + } + + break; + } + sensorlistprev = sensorlist; + sensorlist = sensorlist->next; + } + + if (sensor->name) + SDL_free(sensor->name); + + /* Free the data associated with this sensor */ + if (sensor->axes) { + SDL_free(sensor->axes); + } + SDL_free(sensor); +} + +void +SDL_SensorQuit(void) +{ + /* Make sure we're not getting called in the middle of updating sensors */ + SDL_assert(!SDL_updating_sensor); + + /* Stop the event polling */ + while ( SDL_sensors ) + { + SDL_sensors->ref_count = 1; + SDL_SensorClose(SDL_sensors); + } + + /* Quit the sensor setup */ + SDL_SYS_SensorQuit(); +} + + +/* These are global for SDL_syssensor.c and SDL_events.c */ + +int +SDL_PrivateSensorAxis(SDL_Sensor * sensor, Uint8 axis, float value) +{ + if (!SDL_PrivatesensorValid(sensor)) { + return 0; + } + + /* Make sure we're not getting garbage events */ + if (axis >= sensor->naxes) { + return 0; + } + + /* Update internal sensor state */ + if (value == sensor->axes[axis]) { + return 0; + } + sensor->axes[axis] = value; + + return 0; +} + +void +SDL_SensorUpdate(void) +{ + SDL_Sensor *sensor; + + sensor = SDL_sensors; + while ( sensor ) + { + SDL_Sensor *sensornext; + /* save off the next pointer, the Update call may cause a sensor removed event + * and cause our sensor pointer to be freed + */ + sensornext = sensor->next; + + SDL_updating_sensor = sensor; + + SDL_SYS_SensorUpdate( sensor ); + + if ( sensor->closed && sensor->uncentered ) + { + int i; + sensor->uncentered = 0; + + /* Tell the app that everything is centered/unpressed... */ + for (i = 0; i < sensor->naxes; i++) + { + SDL_PrivateSensorAxis(sensor, i, 0.0); + } + } + + SDL_updating_sensor = NULL; + + /* If the sensor was closed while updating, free it here */ + if ( sensor->ref_count <= 0 ) { + SDL_SensorClose(sensor); + } + + sensor = sensornext; + } +} + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/sensor/SDL_sensor_c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/SDL_sensor_c.h Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,37 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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" + +/* Useful functions and variables from SDL_sensor.c */ +#include "SDL_sensor.h" + +/* Initialization and shutdown functions */ +extern int SDL_SensorInit(void); +extern void SDL_SensorQuit(void); + +/* Internal event queueing functions */ +extern int SDL_PrivateSensorAxis(SDL_Sensor * sensor, + Uint8 axis, float value); + +/* Internal sanity checking functions */ +extern int SDL_PrivateSensorValid(SDL_Sensor * sensor); + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/sensor/SDL_syssensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/SDL_syssensor.h Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,89 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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" + +/* This is the system specific header for the SDL sensor API */ + +#include "SDL_sensor.h" +#include "SDL_sensor_c.h" + +/* The SDL sensor structure */ +struct _SDL_Sensor +{ + int instance_id; /* Device instance, monotonically increasing from 0 */ + char *name; /* Sensor name - system dependent */ + Uint8 type; /* Type of sensor */ + + int naxes; /* Number of axis controls on the sensor */ + float *axes; /* Current axis states */ + float resolution; /* Resolution for this sensor */ + + struct sensor_hwdata *hwdata; /* Driver dependent information */ + + int ref_count; /* Reference count for multiple opens */ + + Uint8 closed; /* 1 if this device is no longer valid */ + Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */ + struct _SDL_Sensor *next; /* pointer to next sensor we have allocated */ +}; + +/* Function to scan the system for sensors. + * sensor 0 should be the system default sensor. + * This function should return the number of available sensors, or -1 + * on an unrecoverable fatal error. + */ +extern int SDL_SYS_SensorInit(void); + +/* Function to return the number of sensor devices plugged in right now */ +extern int SDL_SYS_NumSensors(); + +/* Function to get the device-dependent name of a sensor */ +extern const char *SDL_SYS_SensorNameForDeviceIndex(int device_index); + +/* Function to get the current instance id of the sensor located at device_index */ +extern SDL_SensorID SDL_SYS_SensorGetInstanceIdOfDeviceIndex(int device_index); + +/* Function to open a sensor for use. + The sensor to open is specified by the index field of the sensor. + This should fill the nbuttons and naxes fields of the sensor structure. + It returns 0, or -1 if there is an error. + */ +extern int SDL_SYS_SensorOpen(SDL_Sensor * sensor, int device_index); + +/* Function to query if the sensor is currently attached + * It returns SDL_TRUE if attached, SDL_FALSE otherwise. + */ +extern SDL_bool SDL_SYS_SensorAttached(SDL_Sensor * sensor); + +/* Function to update the state of a sensor - called as a device poll. + * This function shouldn't update the sensor structure directly, + * but instead should call SDL_PrivateSensor*() to deliver events + * and update sensor device state. + */ +extern void SDL_SYS_SensorUpdate(SDL_Sensor * sensor); + +/* Function to close a sensor after use */ +extern void SDL_SYS_SensorClose(SDL_Sensor * sensor); + +/* Function to perform any system-specific sensor related cleanup */ +extern void SDL_SYS_SensorQuit(void); + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/sensor/android/SDL_androidsensor.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/android/SDL_androidsensor.c Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,294 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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" + +#ifdef SDL_SENSOR_ANDROID + +/* This is the system specific header for the SDL sensor API */ +#include /* For the definition of NULL */ +#include + +#include "SDL_error.h" +#include "SDL_events.h" +#include "SDL_sensor.h" +#include "SDL_androidsensor.h" +#include "../SDL_syssensor.h" +#include "../SDL_sensor_c.h" +#include "../../core/android/SDL_android.h" + +static ASensorManager* mSensorManager; +static ASensorEventQueue* eventqueue; +static ALooper* looper; +static int open_sensors=0; + +/* Function to scan the system for sensors. + * Sensor 0 should be the system default sensor. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int +SDL_SYS_SensorInit(void) +{ + mSensorManager = ASensorManager_getInstance(); + looper = ALooper_forThread(); + if(! looper) { + looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); + if(! looper) { + return -1; + } + } + + return 0; +} + +int SDL_SYS_NumSensors() +{ + return ASensorManager_getSensorList(mSensorManager, NULL); +} + +/* Function to get the device-dependent name of a sensor + * Should be callable even before opening the sensor */ +const char * +SDL_SYS_SensorNameForDeviceIndex(int device_index) +{ + int n=0; + ASensorList list; + + n = ASensorManager_getSensorList(mSensorManager, &list); + if (device_index > n || ! list) { + SDL_SetError("Sensor index higher than available sensor number"); + return NULL; + } + + return ASensor_getName(list[device_index]); +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_SensorID SDL_SYS_SensorGetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to open a sensor for use. + The sensor to open is specified by the index field of the sensor. + This should fill the naxes fields of the sensor structure. + It returns 0, or -1 if there is an error. + */ +int +SDL_SYS_SensorOpen(SDL_Sensor *sensor, int device_index) +{ + int type=0; + ASensorList list; + + if (device_index > ASensorManager_getSensorList(mSensorManager, &list) || ! list) { + return -1; + } + + sensor->hwdata = (struct sensor_hwdata *) + SDL_malloc(sizeof(*sensor->hwdata)); + if (sensor->hwdata == NULL) { + SDL_OutOfMemory(); + return -1; + } + + sensor->hwdata->asensor = list[device_index]; + + type = ASensor_getType(list[device_index]); + switch(type) { + case 0x00000001: + sensor->type = SDL_SENSOR_ACCEL; + sensor->naxes = 3; + break; + case 0x00000002: + sensor->type = SDL_SENSOR_MAGNET; + sensor->naxes = 3; + break; + case 0x00000003: + sensor->type = SDL_SENSOR_ORIENTATION; + sensor->naxes = 3; + break; + case 0x00000004: + sensor->type = SDL_SENSOR_GYRO; + sensor->naxes = 3; + break; + case 0x00000005: + sensor->type = SDL_SENSOR_LIGHT; + sensor->naxes = 1; + break; + case 0x00000006: + sensor->type = SDL_SENSOR_PRESSURE; + sensor->naxes = 1; + break; + case 0x00000007: + sensor->type = SDL_SENSOR_TEMPERATURE; + sensor->naxes = 1; + break; + case 0x00000008: + sensor->type = SDL_SENSOR_PROXIMITY; + sensor->naxes = 1; + break; + case 0x00000009: + sensor->type = SDL_SENSOR_GRAVITY; + sensor->naxes = 1; + break; + case 0x0000000a: + sensor->type = SDL_SENSOR_LACCEL; + sensor->naxes = 3; + break; + case 0x0000000b: + sensor->type = SDL_SENSOR_ROTVECTOR; + sensor->naxes = 3; + break; + case 0x0000000c: + sensor->type = SDL_SENSOR_RHUMIDITY; + sensor->naxes = 1; + break; + default: + sensor->type = SDL_SENSOR_UNKNOWN; + sensor->naxes = 3; // Just in case + } + + sensor->resolution = ASensor_getResolution(list[device_index]); + + sensor->instance_id = device_index; + + // If there were no open sensors, open the event queue and associate + // it to the looper + if(open_sensors == 0) { + eventqueue = ASensorManager_createEventQueue(mSensorManager, looper, 3 /* LOOPER_ID_USER */, NULL, NULL); + } + open_sensors++; + + ASensorEventQueue_enableSensor(eventqueue, list[device_index]); + + return 0; +} + +/* Function to update the state of a sensor - called as a device poll. + * This function shouldn't update the sensor structure directly, + * but instead should call SDL_PrivateSensor*() to deliver events + * and update sensor device state. + * There's some useful information on what the Android sensors give you at: + * http://developer.android.com/reference/android/hardware/SensorEvent.html + */ +void +SDL_SYS_SensorUpdate(SDL_Sensor* sensor) +{ + int events; + ASensorEvent event; + struct android_poll_source* source; + + while (ALooper_pollAll(0, NULL, &events, (void**)&source) == 3 /* LOOPER_ID_USER */ ) { + // If a sensor has data, process it now. + while (ASensorEventQueue_getEvents(eventqueue, + &event, 1) > 0) { + switch(event.type) { + case 0x00000001: + SDL_PrivateSensorAxis(sensor, 0, event.acceleration.x); + SDL_PrivateSensorAxis(sensor, 1, event.acceleration.y); + SDL_PrivateSensorAxis(sensor, 2, event.acceleration.z); + break; + case 0x00000002: + SDL_PrivateSensorAxis(sensor, 0, event.magnetic.x); + SDL_PrivateSensorAxis(sensor, 1, event.magnetic.y); + SDL_PrivateSensorAxis(sensor, 2, event.magnetic.z); + break; + case 0x00000003: + SDL_PrivateSensorAxis(sensor, 0, event.vector.azimuth); + SDL_PrivateSensorAxis(sensor, 1, event.vector.pitch); + SDL_PrivateSensorAxis(sensor, 2, event.vector.roll); + break; + case 0x00000004: + SDL_PrivateSensorAxis(sensor, 0, event.vector.x); + SDL_PrivateSensorAxis(sensor, 1, event.vector.y); + SDL_PrivateSensorAxis(sensor, 2, event.vector.z); + break; + case 0x00000005: + SDL_PrivateSensorAxis(sensor, 0, event.light); + break; + case 0x00000006: + SDL_PrivateSensorAxis(sensor, 0, event.pressure); + break; + case 0x00000007: + SDL_PrivateSensorAxis(sensor, 0, event.temperature); + break; + case 0x00000008: + SDL_PrivateSensorAxis(sensor, 0, event.distance); + break; + case 0x00000009: + SDL_PrivateSensorAxis(sensor, 0, event.vector.x); + SDL_PrivateSensorAxis(sensor, 1, event.vector.y); + SDL_PrivateSensorAxis(sensor, 2, event.vector.z); + break; + case 0x0000000a: + SDL_PrivateSensorAxis(sensor, 0, event.acceleration.x); + SDL_PrivateSensorAxis(sensor, 1, event.acceleration.y); + SDL_PrivateSensorAxis(sensor, 2, event.acceleration.z); + break; + case 0x0000000b: + SDL_PrivateSensorAxis(sensor, 0, event.vector.x); + SDL_PrivateSensorAxis(sensor, 1, event.vector.y); + SDL_PrivateSensorAxis(sensor, 2, event.vector.z); + break; + case 0x0000000c: + // Is this OK? + SDL_PrivateSensorAxis(sensor, 0, event.data[0]); + break; + default: + break; + } + } + } +} + +/* Function to determine is this sensor is attached to the system right now + * Right now we're assuming Android sensors are always attached. + * TODO: Is there any way to know this info in Android? + */ +SDL_bool SDL_SYS_SensorAttached(SDL_Sensor *sensor) +{ + return SDL_TRUE; +} + +/* Function to close a sensor after use */ +void +SDL_SYS_SensorClose(SDL_Sensor * sensor) +{ + ASensorEventQueue_disableSensor(eventqueue, sensor->hwdata->asensor); + + SDL_free(sensor->hwdata); + open_sensors--; + + // Don't read the sensors if no SDL_Sensor is open + if(! open_sensors) { + ASensorManager_destroyEventQueue(mSensorManager, eventqueue); + } +} + +/* Function to perform any system-specific sensor related cleanup */ +void +SDL_SYS_SensorQuit(void) +{ +} + +#endif /* SDL_SENSOR_ANDROID */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/sensor/android/SDL_androidsensor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/android/SDL_androidsensor.h Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,30 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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 +{ + ASensor const* asensor; +}; + + +/* vi: set ts=4 sw=4 expandtab: */ diff -r 177f29ae5279 src/sensor/dummy/SDL_syssensor.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sensor/dummy/SDL_syssensor.c Fri Mar 22 17:56:11 2013 +0100 @@ -0,0 +1,104 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + 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" + +#if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED) + +/* This is the system specific header for the SDL sensor API */ + +#include "SDL_sensor.h" +#include "../SDL_syssensor.h" +#include "../SDL_sensor_c.h" + +/* Function to scan the system for sensors. + * It should return 0, or -1 on an unrecoverable fatal error. + */ +int +SDL_SYS_SensorInit(void) +{ + return (0); +} + +int SDL_SYS_NumSensors() +{ + return 0; +} + +/* Function to get the device-dependent name of a sensor */ +const char * +SDL_SYS_SensorNameForDeviceIndex(int device_index) +{ + SDL_SetError("Logic error: No sensors available"); + return (NULL); +} + +/* Function to perform the mapping from device index to the instance id for this index */ +SDL_SensorID SDL_SYS_SensorGetInstanceIdOfDeviceIndex(int device_index) +{ + return device_index; +} + +/* Function to determine is this sensor is attached to the system right now */ +SDL_bool SDL_SYS_SensorAttached(SDL_Sensor *sensor) +{ + return SDL_FALSE; +} + +/* Function to open a sensor for use. + The sensor to open is specified by the index field of the sensor. + This should fill the naxes fields of the sensor structure. + It returns 0, or -1 if there is an error. + */ +int +SDL_SYS_SensorOpen(SDL_Sensor *sensor, int device_index) +{ + SDL_SetError("Logic error: No sensors available"); + return (-1); +} + +/* Function to update the state of a sensor - called as a device poll. + * This function shouldn't update the sensor structure directly, + * but instead should call SDL_PrivateSensor*() to deliver events + * and update sensor device state. + */ +void +SDL_SYS_SensorUpdate(SDL_Sensor* sensor) +{ + return; +} + +/* Function to close a sensor after use */ +void +SDL_SYS_SensorClose(SDL_Sensor * sensor) +{ + return; +} + +/* Function to perform any system-specific sensor related cleanup */ +void +SDL_SYS_SensorQuit(void) +{ + return; +} + +#endif /* SDL_SENSOR_DUMMY || SDL_SENSOR_DISABLED */ + +/* vi: set ts=4 sw=4 expandtab: */