@@ -204,11 +204,22 @@ class NoloDevice {
204
204
osvrQuatSetZ (quat, -j);
205
205
}
206
206
void decodeControllerCV1 (int idx, unsigned char *data) {
207
+ enum ControllerOffsets {
208
+ hwversion = 0 , // guessed!
209
+ fwversion = 1 ,
210
+ position = 3 ,
211
+ orientation = 3 +3 *2 ,
212
+ ofsbuttons = 3 +3 *2 +4 *2 ,
213
+ touchid = 3 +3 *2 +4 *2 +1 ,
214
+ touchx = 3 +3 *2 +4 *2 +2 ,
215
+ touchy = 3 +3 *2 +4 *2 +3 ,
216
+ battery = 3 +3 *2 +4 *2 +4 ,
217
+ };
207
218
OSVR_PoseState pose;
208
219
uint8_t buttons, bit;
209
220
int trigger_pressed = 0 ;
210
221
211
- if (data[0 ] != 2 || data[1 ] != 1 ) {
222
+ if (data[hwversion ] != 2 || data[fwversion ] != 1 ) {
212
223
// Unknown version
213
224
/* Happens when controllers aren't on.
214
225
std::cout << "Nolo: Unknown controller " << idx
@@ -218,12 +229,12 @@ class NoloDevice {
218
229
return ;
219
230
}
220
231
221
- decodePosition (data+3 , &pose.translation );
222
- decodeOrientation (data+3 + 3 * 2 , &pose.rotation );
232
+ decodePosition (data+position , &pose.translation );
233
+ decodeOrientation (data+orientation , &pose.rotation );
223
234
224
235
osvrDeviceTrackerSendPoseTimestamped (m_dev, m_tracker, &pose, 2 +idx, &m_lastreport_time);
225
236
226
- buttons = data[3 + 3 * 2 + 4 * 2 ];
237
+ buttons = data[ofsbuttons ];
227
238
// TODO: report buttons for both controllers in one call?
228
239
for (bit=0 ; bit<NUM_BUTTONS; bit++){
229
240
osvrDeviceButtonSetValueTimestamped (m_dev, m_button,
@@ -249,23 +260,30 @@ class NoloDevice {
249
260
// normalize 0 to 1
250
261
// x/255
251
262
double axis_value;
252
- if (data[3 + 3 * 2 + 4 * 2 + 1 ]) { // Only report touch if there is one
253
- axis_value = 2 *data[3 + 3 * 2 + 4 * 2 + 2 ]/255.0 - 1 ;
263
+ if (data[touchid ]) { // Only report touch if there is one
264
+ axis_value = 2 *data[touchx ]/255.0 - 1 ;
254
265
// invert axis
255
266
axis_value *= -1 ;
256
267
osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, axis_value, idx*NUM_AXIS+0 , &m_lastreport_time);
257
- axis_value = 2 *((int )data[3 + 3 * 2 + 4 * 2 + 2 + 1 ])/255.0 -1 ;
268
+ axis_value = 2 *((int )data[touchy ])/255.0 -1 ;
258
269
axis_value *= -1 ;
259
270
osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, axis_value, idx*NUM_AXIS+1 , &m_lastreport_time);
260
271
}
261
- // trigger
272
+ // trigger (emulated analog axis)
262
273
osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, trigger_pressed, idx*NUM_AXIS+2 , &m_lastreport_time);
263
274
// battery level
264
- axis_value = data[3 + 3 * 2 + 4 * 2 + 2 + 2 ]/255.0 ;
275
+ axis_value = data[battery ]/255.0 ;
265
276
osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, axis_value, idx*NUM_AXIS+3 , &m_lastreport_time);
266
277
}
267
278
void decodeHeadsetMarkerCV1 (unsigned char *data) {
268
- if (data[0 ] != 2 || data[1 ] != 1 ) {
279
+ enum MarkerOffsets {
280
+ hwversion = 0 , // guessed!
281
+ fwversion = 1 ,
282
+ position = 3 ,
283
+ homeposition = 3 +3 *2 ,
284
+ orientation = 3 +2 *3 *2 +1 ,
285
+ };
286
+ if (data[hwversion] != 2 || data[fwversion] != 1 ) {
269
287
/* Happens with corrupt packages (mixed with controller data)
270
288
std::cout << "Nolo: Unknown headset marker"
271
289
<< " version " << (int)data[0] << " " << (int)data[1]
@@ -278,9 +296,9 @@ class NoloDevice {
278
296
OSVR_PositionState home;
279
297
OSVR_PoseState hmd;
280
298
281
- decodePosition (data+3 , &hmd.translation );
282
- decodePosition (data+3 + 3 * 2 , &home);
283
- decodeOrientation (data+3 + 2 * 3 * 2 + 1 , &hmd.rotation );
299
+ decodePosition (data+position , &hmd.translation );
300
+ decodePosition (data+homeposition , &home);
301
+ decodeOrientation (data+orientation , &hmd.rotation );
284
302
285
303
// Tracker viewer kept using the home for head.
286
304
// Something wrong with how they handle the descriptors.
@@ -291,11 +309,16 @@ class NoloDevice {
291
309
&m_lastreport_time);
292
310
}
293
311
void decodeBaseStationCV1 (unsigned char *data) {
294
- if (data[0 ] != 2 || data[1 ] != 1 )
312
+ enum MarkerOffsets {
313
+ hwversion = 0 , // guessed!
314
+ fwversion = 1 ,
315
+ battery = 2
316
+ };
317
+ if (data[hwversion] != 2 || data[fwversion] != 1 )
295
318
// Unknown version
296
319
return ;
297
320
298
- osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, data[2 ], 2 *NUM_AXIS,
321
+ osvrDeviceAnalogSetValueTimestamped (m_dev, m_analog, data[battery ], 2 *NUM_AXIS,
299
322
&m_lastreport_time);
300
323
}
301
324
0 commit comments