-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRetroSensors.cpp
125 lines (121 loc) · 3.17 KB
/
QRetroSensors.cpp
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
120
121
122
123
124
125
#include "QRetroSensors.h"
QRetroSensors::QRetroSensors()
{
/* Ignore force of gravity */
#if QRETRO_HAVE_SENSORS
m_AccelerometerSensor.setAccelerationMode(QAccelerometer::User);
#endif
}
bool QRetroSensors::setState(unsigned port, retro_sensor_action action,
unsigned rate)
{
if (port)
return false;
else
{
switch (action)
{
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
m_AccelerometerEnabled = true;
m_AccelerometerRate = rate;
#if QRETRO_HAVE_SENSORS
m_AccelerometerSensor.setDataRate(static_cast<int>(rate));
m_AccelerometerSensor.start();
#endif
break;
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
m_AccelerometerEnabled = false;
#if QRETRO_HAVE_SENSORS
m_AccelerometerSensor.stop();
#endif
break;
case RETRO_SENSOR_GYROSCOPE_ENABLE:
m_GyroscopeEnabled = true;
m_GyroscopeRate = rate;
#if QRETRO_HAVE_SENSORS
m_GyroscopeSensor.setDataRate(static_cast<int>(rate));
m_GyroscopeSensor.start();
#endif
break;
case RETRO_SENSOR_GYROSCOPE_DISABLE:
m_GyroscopeEnabled = false;
#if QRETRO_HAVE_SENSORS
m_GyroscopeSensor.stop();
#endif
break;
case RETRO_SENSOR_ILLUMINANCE_ENABLE:
m_IlluminanceEnabled = true;
m_IlluminanceRate = rate;
#if QRETRO_HAVE_SENSORS
m_IlluminanceSensor.setDataRate(static_cast<int>(rate));
m_IlluminanceSensor.start();
#endif
break;
case RETRO_SENSOR_ILLUMINANCE_DISABLE:
m_IlluminanceEnabled = false;
#if QRETRO_HAVE_SENSORS
m_IlluminanceSensor.stop();
#endif
break;
default:
return false;
}
return true;
}
}
float QRetroSensors::getInput(unsigned port, unsigned id)
{
if (port)
return 0;
else
{
#if QRETRO_HAVE_SENSORS
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
return m_AccelerometerEnabled ?
static_cast<float>(m_AccelerometerSensor.reading()->x()) : 0;
case RETRO_SENSOR_ACCELEROMETER_Y:
return m_AccelerometerEnabled ?
static_cast<float>(m_AccelerometerSensor.reading()->y()) : 0;
case RETRO_SENSOR_ACCELEROMETER_Z:
return m_AccelerometerEnabled ?
static_cast<float>(m_AccelerometerSensor.reading()->z()) : 0;
case RETRO_SENSOR_GYROSCOPE_X:
return m_GyroscopeEnabled ?
static_cast<float>(m_GyroscopeSensor.reading()->x()) : 0;
case RETRO_SENSOR_GYROSCOPE_Y:
return m_GyroscopeEnabled ?
static_cast<float>(m_GyroscopeSensor.reading()->y()) : 0;
case RETRO_SENSOR_GYROSCOPE_Z:
return m_GyroscopeEnabled ?
static_cast<float>(m_GyroscopeSensor.reading()->z()) : 0;
case RETRO_SENSOR_ILLUMINANCE:
if (m_IlluminanceEnabled)
{
switch (m_IlluminanceSensor.reading()->lightLevel())
{
case QAmbientLightReading::Dark:
return 1/5;
case QAmbientLightReading::Twilight:
return 2/5;
case QAmbientLightReading::Light:
return 3/5;
case QAmbientLightReading::Bright:
return 4/5;
case QAmbientLightReading::Sunny:
return 5/5;
default:
return 0;
}
}
else
return 0;
default:
return 0;
}
#else
return 0;
#endif
}
}