-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRetroSensors.cpp
More file actions
178 lines (163 loc) · 4.67 KB
/
Copy pathQRetroSensors.cpp
File metadata and controls
178 lines (163 loc) · 4.67 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "QRetroSensors.h"
QRetroSensors::QRetroSensors()
{
#if QRETRO_HAVE_SENSORS
/**
* Probe backend availability for each sensor type by attempting a start.
* On platforms without real hardware the backend may be absent or broken;
* this lets us skip sensor API calls later rather than crashing.
*/
m_AccelerometerAvailable = m_AccelerometerSensor.start();
m_AccelerometerSensor.stop();
m_GyroscopeAvailable = m_GyroscopeSensor.start();
m_GyroscopeSensor.stop();
m_IlluminanceAvailable = m_IlluminanceSensor.start();
m_IlluminanceSensor.stop();
/* Ignore the force of gravity for accelerometer */
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
if (m_AccelerometerAvailable)
{
m_AccelerometerSensor.stop();
m_AccelerometerSensor.setDataRate(static_cast<int>(rate));
m_AccelerometerSensor.start();
}
#endif
break;
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
m_AccelerometerEnabled = false;
#if QRETRO_HAVE_SENSORS
if (m_AccelerometerAvailable)
m_AccelerometerSensor.stop();
#endif
break;
case RETRO_SENSOR_GYROSCOPE_ENABLE:
m_GyroscopeEnabled = true;
m_GyroscopeRate = rate;
#if QRETRO_HAVE_SENSORS
if (m_GyroscopeAvailable)
{
m_GyroscopeSensor.stop();
m_GyroscopeSensor.setDataRate(static_cast<int>(rate));
m_GyroscopeSensor.start();
}
#endif
break;
case RETRO_SENSOR_GYROSCOPE_DISABLE:
m_GyroscopeEnabled = false;
#if QRETRO_HAVE_SENSORS
if (m_GyroscopeAvailable)
m_GyroscopeSensor.stop();
#endif
break;
case RETRO_SENSOR_ILLUMINANCE_ENABLE:
m_IlluminanceEnabled = true;
m_IlluminanceRate = rate;
#if QRETRO_HAVE_SENSORS
if (m_IlluminanceAvailable)
{
m_IlluminanceSensor.stop();
m_IlluminanceSensor.setDataRate(static_cast<int>(rate));
m_IlluminanceSensor.start();
}
#endif
break;
case RETRO_SENSOR_ILLUMINANCE_DISABLE:
m_IlluminanceEnabled = false;
#if QRETRO_HAVE_SENSORS
if (m_IlluminanceAvailable)
m_IlluminanceSensor.stop();
#endif
break;
default:
return false;
}
return true;
}
}
float QRetroSensors::getInput(unsigned port, unsigned id)
{
if (port)
return 0;
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
m_AccelXHasBeenRead = true;
if (m_SpoofAccelEnabled)
return m_SpoofAccel[0];
#if QRETRO_HAVE_SENSORS
if (m_AccelerometerEnabled && m_AccelerometerSensor.reading())
return static_cast<float>(m_AccelerometerSensor.reading()->x());
#endif
return 0;
case RETRO_SENSOR_ACCELEROMETER_Y:
m_AccelYHasBeenRead = true;
if (m_SpoofAccelEnabled)
return m_SpoofAccel[1];
#if QRETRO_HAVE_SENSORS
if (m_AccelerometerEnabled && m_AccelerometerSensor.reading())
return static_cast<float>(m_AccelerometerSensor.reading()->y());
#endif
return 0;
case RETRO_SENSOR_ACCELEROMETER_Z:
m_AccelZHasBeenRead = true;
if (m_SpoofAccelEnabled)
return m_SpoofAccel[2];
#if QRETRO_HAVE_SENSORS
if (m_AccelerometerEnabled && m_AccelerometerSensor.reading())
return static_cast<float>(m_AccelerometerSensor.reading()->z());
#endif
return 0;
case RETRO_SENSOR_GYROSCOPE_X:
m_GyroXHasBeenRead = true;
if (m_SpoofGyroEnabled)
return m_SpoofGyro[0];
#if QRETRO_HAVE_SENSORS
if (m_GyroscopeEnabled && m_GyroscopeSensor.reading())
return static_cast<float>(m_GyroscopeSensor.reading()->x());
#endif
return 0;
case RETRO_SENSOR_GYROSCOPE_Y:
m_GyroYHasBeenRead = true;
if (m_SpoofGyroEnabled)
return m_SpoofGyro[1];
#if QRETRO_HAVE_SENSORS
if (m_GyroscopeEnabled && m_GyroscopeSensor.reading())
return static_cast<float>(m_GyroscopeSensor.reading()->y());
#endif
return 0;
case RETRO_SENSOR_GYROSCOPE_Z:
m_GyroZHasBeenRead = true;
if (m_SpoofGyroEnabled)
return m_SpoofGyro[2];
#if QRETRO_HAVE_SENSORS
if (m_GyroscopeEnabled && m_GyroscopeSensor.reading())
return static_cast<float>(m_GyroscopeSensor.reading()->z());
#endif
return 0;
case RETRO_SENSOR_ILLUMINANCE:
m_IllumHasBeenRead = true;
if (m_SpoofIllumEnabled)
return m_SpoofIllum;
#if QRETRO_HAVE_SENSORS
if (m_IlluminanceEnabled && m_IlluminanceSensor.reading())
return static_cast<float>(m_IlluminanceSensor.reading()->lux());
#endif
return 0;
default:
return 0;
}
}