Fix sensors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c
index 286ab12..5e74397 100644
--- a/src/sensor/vita/SDL_vitasensor.c
+++ b/src/sensor/vita/SDL_vitasensor.c
@@ -45,8 +45,8 @@ SDL_VITA_SensorInit(void)
sceMotionReset();
sceMotionStartSampling();
// sceMotionMagnetometerOn();
- sceMotionSetAngleThreshold(40);
- sceMotionSetGyroBiasCorrection(SCE_TRUE);
+ sceMotionSetAngleThreshold(0);
+ sceMotionSetGyroBiasCorrection(SCE_FALSE);
SDL_sensors_count = 2;
@@ -122,39 +122,65 @@ SDL_VITA_SensorGetDeviceInstanceID(int device_index)
static int
SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index)
{
+ struct sensor_hwdata *hwdata;
+
+ hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata));
+ if (hwdata == NULL) {
+ return SDL_OutOfMemory();
+ }
+ sensor->hwdata = hwdata;
+
return 0;
}
static void
SDL_VITA_SensorUpdate(SDL_Sensor *sensor)
{
- SceMotionState motionState;
+ SceMotionSensorState motionState[SCE_MOTION_MAX_NUM_STATES];
+ SDL_memset(motionState, 0, sizeof(motionState));
+
int err = SCE_OK;
- err = sceMotionGetState(&motionState);
- if (err != SCE_OK) return;
+ err = sceMotionGetSensorState(motionState, SCE_MOTION_MAX_NUM_STATES);
+ if (err != SCE_OK)
+ {
+ return;
+ }
- switch (sensor->type)
+ for (int i = 0; i < SCE_MOTION_MAX_NUM_STATES; i++)
{
- case SDL_SENSOR_ACCEL:
- {
- float data[3];
- data[0] = motionState.acceleration.x * SDL_STANDARD_GRAVITY;
- data[1] = motionState.acceleration.y * SDL_STANDARD_GRAVITY;
- data[2] = motionState.acceleration.z * SDL_STANDARD_GRAVITY;
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
- }
- break;
- case SDL_SENSOR_GYRO:
+ if (sensor->hwdata->counter < motionState[i].counter)
{
- float data[3];
- data[0] = motionState.angularVelocity.x;
- data[1] = motionState.angularVelocity.y;
- data[2] = motionState.angularVelocity.z;
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
+ sensor->hwdata->counter = motionState[i].counter;
+ switch (sensor->type)
+ {
+ case SDL_SENSOR_ACCEL:
+ {
+ float data[3];
+ data[0] = motionState[i].accelerometer.x * SDL_STANDARD_GRAVITY;
+ data[1] = motionState[i].accelerometer.y * SDL_STANDARD_GRAVITY;
+ data[2] = motionState[i].accelerometer.z * SDL_STANDARD_GRAVITY;
+ if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
+ SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
+ SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
+ }
+ }
+ break;
+ case SDL_SENSOR_GYRO:
+ {
+ float data[3];
+ data[0] = motionState[i].gyro.x;
+ data[1] = motionState[i].gyro.y;
+ data[2] = motionState[i].gyro.z;
+ if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
+ SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
+ SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
- break;
- default:
- break;
}
}
diff --git a/src/sensor/vita/SDL_vitasensor.h b/src/sensor/vita/SDL_vitasensor.h
index ee66f2f..0c16044 100644
--- a/src/sensor/vita/SDL_vitasensor.h
+++ b/src/sensor/vita/SDL_vitasensor.h
@@ -20,4 +20,11 @@
*/
#include "SDL_config.h"
+/* The private structure used to keep track of a sensor */
+struct sensor_hwdata
+{
+ float data[3];
+ int counter;
+};
+
/* vi: set ts=4 sw=4 expandtab: */