-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathOculusRift.cpp
More file actions
473 lines (405 loc) · 19.7 KB
/
OculusRift.cpp
File metadata and controls
473 lines (405 loc) · 19.7 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
/** @file
@brief Handle for Oculus Rift HMD
@date 2015
@author
Sensics, Inc.
<http://sensics.com>
*/
// Copyright 2015 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Internal Includes
#include "OculusRift.h"
#include "osvr_compiler_detection.h"
#include "OculusRiftException.h"
#include "GetLastError.h"
// Library/third-party includes
#include <json/json.h>
// Standard includes
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
OSVR_CONSTEXPR double OSVR_PI = 3.1415926535897932385;
OculusRift::OculusRift(OSVR_PluginRegContext ctx, int index)
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
// Connect HMD
ovrResult result = ovr_Create(&hmd_, &luid_);
if (OVR_FAILURE(result)) {
const auto msg = "Error creatinng HMD: " + getLastErrorMessage() + ".";
osvrPluginLog(ctx, OSVR_LOGLEVEL_ERROR, msg.c_str());
throw OculusRiftException(msg);
}
#elif OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,6,0,0)
// Connect to HMD
ovrResult result = ovrHmd_Create(index, &hmd_);
if (OVR_FAILURE(result)) {
const auto msg = "Error creatinng HMD: " + getLastErrorMessage() + ".";
osvrPluginLog(ctx, OSVR_LOGLEVEL_ERROR, msg.c_str());
throw OculusRiftException(msg);
}
#else
// Connect to HMD
hmd_ = ovrHmd_Create(index);
if (!hmd_) {
osvrPluginLog(ctx, OSVR_LOGLEVEL_ERROR, "Error creating HMD handle.");
throw OculusRiftException("Error creating HMD handle.");
}
#endif
// Initialize tracking and sensor fusion
const unsigned int supported_tracking_capabilities = ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position; // the tracking capabilities this driver will report
const unsigned int required_tracking_capabilities = 0; // the tracking capabilities which must be supported by the HMD
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(1,1,3,0)
// do nothing as tracking is automatically configured in SDK version 1.3.0 and above
#elif OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const ovrBool tracking_configured = ovr_ConfigureTracking(hmd_, supported_tracking_capabilities, required_tracking_capabilities);
// returns FALSE if the required tracking capabilities are not supported (e.g., camera isn't plugged in)
#else
const ovrBool tracking_configured = ovrHmd_ConfigureTracking(hmd_, supported_tracking_capabilities, required_tracking_capabilities);
// returns FALSE if the required tracking capabilities are not supported (e.g., camera isn't plugged in)
#endif
detectTrackers();
OSVR_DeviceInitOptions opts = osvrDeviceCreateInitOptions(ctx);
osvrDeviceTrackerConfigure(opts, &tracker_);
#if OSVR_OVR_VERSION_LESS_THAN(1,1,3,0)
// Raw sensor data is no longer available in SDK > 1.3.0
osvrDeviceAnalogConfigure(opts, &analog_, static_cast<OSVR_ChannelCount>(AnalogChannels::NUM_CHANNELS));
#endif
// Create the sync device token with the options
std::string device_name = "OculusRift" + std::to_string(index);
deviceToken_.initSync(ctx, device_name.c_str(), opts);
deviceToken_.sendJsonDescriptor(getDeviceDescriptorJson());
deviceToken_.registerUpdateCallback(this);
}
OculusRift::~OculusRift() OSVR_NOEXCEPT
{
destroy();
}
void OculusRift::destroy()
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
ovr_Destroy(hmd_);
#else
ovrHmd_Destroy(hmd_);
#endif
}
std::string OculusRift::getProductName() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const auto hmd_desc = ovr_GetHmdDesc(hmd_);
return hmd_desc.ProductName;
#else
return hmd_->ProductName;
#endif
}
std::string OculusRift::getManufacturer() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const auto hmd_desc = ovr_GetHmdDesc(hmd_);
return hmd_desc.Manufacturer;
#else
return hmd_->Manufacturer;
#endif
}
std::string OculusRift::getSerialNumber() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const auto hmd_desc = ovr_GetHmdDesc(hmd_);
return hmd_desc.SerialNumber;
#else
return hmd_->SerialNumber;
#endif
}
std::string OculusRift::getFirmwareVersion() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const auto hmd_desc = ovr_GetHmdDesc(hmd_);
const auto fw_major = std::to_string(hmd_desc.FirmwareMajor);
const auto fw_minor = std::to_string(hmd_desc.FirmwareMinor);
return fw_major + "." + fw_minor;
#else
return std::to_string(hmd_->FirmwareMajor) + "." + std::to_string(hmd_->FirmwareMinor);
#endif
}
unsigned int OculusRift::detectTrackers()
{
int num_trackers = 0;
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,8,0,0)
const ovrTrackingState ts = ovr_GetTrackingState(hmd_, 0.0, ovrFalse);
#elif OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const ovrTrackingState ts = ovr_GetTrackingState(hmd_, 0.0);
#else
const ovrTrackingState ts = ovrHmd_GetTrackingState(hmd_, ovr_GetTimeInSeconds());
#endif
// Can we track the HMD?
if (ts.StatusFlags & ovrStatus_OrientationTracked) {
num_trackers++;
}
// Get number of trackers/cameras (and multiple by two: one for normal pose, and once again for the leveled pose)
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(1,1,3,0)
num_trackers += 2 * ovr_GetTrackerCount(hmd_);
#else
const bool camera_tracked = static_cast<bool>(ts.StatusFlags & ovrStatus_CameraPoseTracked);
if (camera_tracked) {
num_trackers += 2; // first for camera, second for leveled camera
}
#endif
numTrackers_ = num_trackers;
return numTrackers_;
}
unsigned int OculusRift::getTrackerCount() const
{
return numTrackers_;
}
std::string OculusRift::getDeviceDescriptorJson() const
{
Json::Value root;
root["deviceVender"] = getManufacturer();
root["deviceName"] = getProductName();
root["author"] = "Kevin M. Godby <kevin@godby.org>";
root["version"] = 1;
root["lastModified"] = "2015-06-14T20:42:13Z";
root["interfaces"]["tracker"]["count"] = getTrackerCount();
root["interfaces"]["tracker"]["position"] = true; // FIXME
root["interfaces"]["tracker"]["orientation"] = true; // FIXME
#if OSVR_OVR_VERSION_LESS_THAN(1,1,3,0)
root["interfaces"]["analog"]["count"] = static_cast<int>(AnalogChannels::NUM_CHANNELS);
//root["interfaces"]["analog"]["traits"] = {}; // FIXME
#endif
root["semantic"]["hmd"]["$target"] = "tracker/0";
#if OSVR_OVR_VERSION_LESS_THAN(1,1,3,0)
root["semantic"]["hmd"]["accelerometer"]["x"] = "analog/0";
root["semantic"]["hmd"]["accelerometer"]["y"] = "analog/1";
root["semantic"]["hmd"]["accelerometer"]["z"] = "analog/2";
root["semantic"]["hmd"]["gyroscope"]["x"] = "analog/3";
root["semantic"]["hmd"]["gyroscope"]["y"] = "analog/4";
root["semantic"]["hmd"]["gyroscope"]["z"] = "analog/5";
root["semantic"]["hmd"]["magnetometer"]["x"] = "analog/6";
root["semantic"]["hmd"]["magnetometer"]["y"] = "analog/7";
root["semantic"]["hmd"]["magnetometer"]["z"] = "analog/8";
root["semantic"]["hmd"]["temperature"] = "analog/9";
#endif
root["semantic"]["camera"]["$target"] = "tracker/1";
root["semantic"]["leveled_camera"]["$target"] = "tracker/2";
root["automaticAliases"]["/me/head"] = "semantic/hmd";
std::ostringstream ostr;
ostr << root;
return ostr.str();
}
std::string OculusRift::getDisplayJson() const
{
// Field of view
const double monocular_horizontal = getMonocularHorizontalFovDegrees();
const double monocular_vertical = getMonocularVerticalFovDegrees();
const double overlap_percent = 0.0; // TODO
const double pitch_tilt = 0.0; // TODO
// Resolution
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const double width = ovr_GetHmdDesc(hmd_).Resolution.w;
const double height = ovr_GetHmdDesc(hmd_).Resolution.h;
#else
const double width = hmd_->Resolution.w;
const double height = hmd_->Resolution.h;
#endif
const double video_inputs = 1;
const std::string display_mode = "horz_side_by_side";
// Distortion
const double k1_red = 0.0; // TODO
const double k1_green = 0.0; // TODO
const double k1_blue = 0.0; // TODO
// Rendering
const double right_roll = 0.0;
const double left_roll = 0.0;
// Eyes
const double center_proj_x = 0.5; // TODO
const double center_proj_y = 0.5; // TODO
const bool rotate_180 = false; // TODO
Json::Value root;
root["hmd"]["field_of_view"]["monocular_horizontal"] = monocular_horizontal;
root["hmd"]["field_of_view"]["monocular_vertical"] = monocular_vertical;
root["hmd"]["field_of_view"]["overlap_percent"] = overlap_percent;
root["hmd"]["field_of_view"]["pitch_tilt"] = pitch_tilt;
root["hmd"]["resolutions"][0]["width"] = width;
root["hmd"]["resolutions"][0]["height"] = height;
root["hmd"]["resolutions"][0]["video_inputs"] = video_inputs;
root["hmd"]["resolutions"][0]["display_mode"] = display_mode;
root["hmd"]["distortion"]["k1_red"] = k1_red;
root["hmd"]["distortion"]["k1_blue"] = k1_blue;
root["hmd"]["distortion"]["k1_green"] = k1_green;
root["hmd"]["rendering"]["right_roll"] = right_roll;
root["hmd"]["rendering"]["left_roll"] = left_roll;
root["hmd"]["eyes"][0]["center_proj_x"] = center_proj_x;
root["hmd"]["eyes"][0]["center_proj_y"] = center_proj_y;
root["hmd"]["eyes"][0]["rotate_180"] = rotate_180;
std::ostringstream ostr;
ostr << root;
return ostr.str();
}
double OculusRift::getMonocularHorizontalFovDegrees() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const double left_eye_left_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Left].LeftTan;
const double left_eye_right_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Left].RightTan;
const double right_eye_left_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Right].LeftTan;
const double right_eye_right_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Right].RightTan;
#else
const double left_eye_left_tan = hmd_->DefaultEyeFov[ovrEye_Left].LeftTan;
const double left_eye_right_tan = hmd_->DefaultEyeFov[ovrEye_Left].RightTan;
const double right_eye_left_tan = hmd_->DefaultEyeFov[ovrEye_Right].LeftTan;
const double right_eye_right_tan = hmd_->DefaultEyeFov[ovrEye_Right].RightTan;
#endif
const double left_eye_left_degrees = std::atan(left_eye_left_tan) * 180.0 / OSVR_PI;
const double left_eye_right_degrees = std::atan(left_eye_right_tan) * 180.0 / OSVR_PI;
const double right_eye_left_degrees = std::atan(right_eye_left_tan) * 180.0 / OSVR_PI;
const double right_eye_right_degrees = std::atan(right_eye_right_tan) * 180.0 / OSVR_PI;
const double left_eye_fov = left_eye_left_degrees + left_eye_right_degrees;
const double right_eye_fov = right_eye_left_degrees + right_eye_right_degrees;
return left_eye_fov + right_eye_fov;
}
double OculusRift::getMonocularVerticalFovDegrees() const
{
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const double left_eye_up_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Left].LeftTan;
const double left_eye_down_tan = ovr_GetHmdDesc(hmd_).DefaultEyeFov[ovrEye_Left].RightTan;
#else
const double left_eye_up_tan = hmd_->DefaultEyeFov[ovrEye_Left].LeftTan;
const double left_eye_down_tan = hmd_->DefaultEyeFov[ovrEye_Left].RightTan;
#endif
const double left_eye_up_degrees = std::atan(left_eye_up_tan) * 180.0 / OSVR_PI;
const double left_eye_down_degrees = std::atan(left_eye_down_tan) * 180.0 / OSVR_PI;
const double left_eye_fov = left_eye_up_degrees + left_eye_down_degrees;
return left_eye_fov;
}
OSVR_ReturnCode OculusRift::update()
{
// Poll tracking data
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,8,0,0)
const ovrTrackingState ts = ovr_GetTrackingState(hmd_, 0.0, ovrFalse);
#elif OSVR_OVR_VERSION_GREATER_OR_EQUAL(0,7,0,0)
const ovrTrackingState ts = ovr_GetTrackingState(hmd_, 0.0);
#else
const ovrTrackingState ts = ovrHmd_GetTrackingState(hmd_, ovr_GetTimeInSeconds());
#endif
const bool head_orientation_tracked = (ts.StatusFlags & ovrStatus_OrientationTracked) != 0;
const bool head_position_tracked = (ts.StatusFlags & ovrStatus_PositionTracked) != 0;
if (head_position_tracked && head_orientation_tracked) {
// Both orientation and position are known
const ovrPoseStatef head_state = ts.HeadPose;
const ovrPosef head_pose = head_state.ThePose;
OSVR_Pose3 hmd_pose;
hmd_pose.translation.data[0] = head_pose.Position.x;
hmd_pose.translation.data[1] = head_pose.Position.y;
hmd_pose.translation.data[2] = head_pose.Position.z;
hmd_pose.rotation.data[0] = head_pose.Orientation.w;
hmd_pose.rotation.data[1] = head_pose.Orientation.x;
hmd_pose.rotation.data[2] = head_pose.Orientation.y;
hmd_pose.rotation.data[3] = head_pose.Orientation.z;
osvrDeviceTrackerSendPose(deviceToken_, tracker_, &hmd_pose, static_cast<OSVR_ChannelCount>(TrackerChannels::HMD));
} else if (head_orientation_tracked) {
// Only the orientation is known
const ovrPoseStatef head_state = ts.HeadPose;
const ovrPosef head_pose = head_state.ThePose;
OSVR_OrientationState hmd_orientation;
hmd_orientation.data[0] = head_pose.Orientation.w;
hmd_orientation.data[1] = head_pose.Orientation.x;
hmd_orientation.data[2] = head_pose.Orientation.y;
hmd_orientation.data[3] = head_pose.Orientation.z;
osvrDeviceTrackerSendOrientation(deviceToken_, tracker_, &hmd_orientation, static_cast<OSVR_ChannelCount>(TrackerChannels::HMD));
} else if (head_position_tracked) {
// Only the position is known
const ovrPoseStatef head_state = ts.HeadPose;
const ovrPosef head_pose = head_state.ThePose;
OSVR_PositionState hmd_position;
hmd_position.data[0] = head_pose.Position.x;
hmd_position.data[1] = head_pose.Position.y;
hmd_position.data[2] = head_pose.Position.z;
osvrDeviceTrackerSendPosition(deviceToken_, tracker_, &hmd_position, static_cast<OSVR_ChannelCount>(TrackerChannels::HMD));
}
#if OSVR_OVR_VERSION_GREATER_OR_EQUAL(1,1,3,0)
const unsigned int tracker_count = ovr_GetTrackerCount(hmd_);
for (unsigned int i = 0; i < tracker_count; ++i) {
ovrTrackerPose tracker_pose = ovr_GetTrackerPose(hmd_, i);
const bool is_connected = (tracker_pose.TrackerFlags & ovrTracker_Connected) != 0;
const bool is_pose_tracked = (tracker_pose.TrackerFlags & ovrTracker_PoseTracked) != 0;
if (!is_connected) // sensor is offline or absent
continue;
if (!is_pose_tracked) // pose is unavailable
continue;
OSVR_Pose3 camera_pose;
camera_pose.translation.data[0] = tracker_pose.Pose.Position.x;
camera_pose.translation.data[1] = tracker_pose.Pose.Position.y;
camera_pose.translation.data[2] = tracker_pose.Pose.Position.z;
camera_pose.rotation.data[0] = tracker_pose.Pose.Orientation.w;
camera_pose.rotation.data[1] = tracker_pose.Pose.Orientation.x;
camera_pose.rotation.data[2] = tracker_pose.Pose.Orientation.y;
camera_pose.rotation.data[3] = tracker_pose.Pose.Orientation.z;
osvrDeviceTrackerSendPose(deviceToken_, tracker_, &camera_pose, static_cast<OSVR_ChannelCount>(2*i + 1));
OSVR_Pose3 leveled_camera_pose;
leveled_camera_pose.translation.data[0] = tracker_pose.LeveledPose.Position.x;
leveled_camera_pose.translation.data[1] = tracker_pose.LeveledPose.Position.y;
leveled_camera_pose.translation.data[2] = tracker_pose.LeveledPose.Position.z;
leveled_camera_pose.rotation.data[0] = tracker_pose.LeveledPose.Orientation.w;
leveled_camera_pose.rotation.data[1] = tracker_pose.LeveledPose.Orientation.x;
leveled_camera_pose.rotation.data[2] = tracker_pose.LeveledPose.Orientation.y;
leveled_camera_pose.rotation.data[3] = tracker_pose.LeveledPose.Orientation.z;
osvrDeviceTrackerSendPose(deviceToken_, tracker_, &leveled_camera_pose, static_cast<OSVR_ChannelCount>(2*i + 2));
}
#else
const bool camera_pose_tracked = static_cast<bool>(ts.StatusFlags & ovrStatus_CameraPoseTracked);
if (camera_pose_tracked) {
OSVR_Pose3 camera_pose;
camera_pose.translation.data[0] = ts.CameraPose.Position.x;
camera_pose.translation.data[1] = ts.CameraPose.Position.y;
camera_pose.translation.data[2] = ts.CameraPose.Position.z;
camera_pose.rotation.data[0] = ts.CameraPose.Orientation.w;
camera_pose.rotation.data[1] = ts.CameraPose.Orientation.x;
camera_pose.rotation.data[2] = ts.CameraPose.Orientation.y;
camera_pose.rotation.data[3] = ts.CameraPose.Orientation.z;
osvrDeviceTrackerSendPose(deviceToken_, tracker_, &camera_pose, static_cast<OSVR_ChannelCount>(TrackerChannels::CAMERA));
OSVR_Pose3 leveled_camera_pose;
leveled_camera_pose.translation.data[0] = ts.LeveledCameraPose.Position.x;
leveled_camera_pose.translation.data[1] = ts.LeveledCameraPose.Position.y;
leveled_camera_pose.translation.data[2] = ts.LeveledCameraPose.Position.z;
leveled_camera_pose.rotation.data[0] = ts.LeveledCameraPose.Orientation.w;
leveled_camera_pose.rotation.data[1] = ts.LeveledCameraPose.Orientation.x;
leveled_camera_pose.rotation.data[2] = ts.LeveledCameraPose.Orientation.y;
leveled_camera_pose.rotation.data[3] = ts.LeveledCameraPose.Orientation.z;
osvrDeviceTrackerSendPose(deviceToken_, tracker_, &leveled_camera_pose, static_cast<OSVR_ChannelCount>(TrackerChannels::LEVELED_CAMERA));
}
#endif
#if OSVR_OVR_VERSION_LESS_THAN(1,1,3,0)
// Raw sensor data is no longer available in SDK > 1.3.0
// Now for the analog interfaces
const ovrSensorData sensor_data = ts.RawSensorData;
// Acceleration reading (x, y, z) in m/s^2
const ovrVector3f accelerometer = sensor_data.Accelerometer;
osvrDeviceAnalogSetValue(deviceToken_, analog_, accelerometer.x, static_cast<OSVR_ChannelCount>(AnalogChannels::ACCELEROMETER_X));
osvrDeviceAnalogSetValue(deviceToken_, analog_, accelerometer.y, static_cast<OSVR_ChannelCount>(AnalogChannels::ACCELEROMETER_Y));
osvrDeviceAnalogSetValue(deviceToken_, analog_, accelerometer.z, static_cast<OSVR_ChannelCount>(AnalogChannels::ACCELEROMETER_Z));
// Rotation rate (x, y, z) in rad/s
const ovrVector3f gyro = sensor_data.Gyro;
osvrDeviceAnalogSetValue(deviceToken_, analog_, gyro.x, static_cast<OSVR_ChannelCount>(AnalogChannels::GYROSCOPE_X));
osvrDeviceAnalogSetValue(deviceToken_, analog_, gyro.y, static_cast<OSVR_ChannelCount>(AnalogChannels::GYROSCOPE_Y));
osvrDeviceAnalogSetValue(deviceToken_, analog_, gyro.z, static_cast<OSVR_ChannelCount>(AnalogChannels::GYROSCOPE_Z));
// Magnetic field (x, y, z) in Gauss
const ovrVector3f magnetometer = sensor_data.Magnetometer;
osvrDeviceAnalogSetValue(deviceToken_, analog_, magnetometer.x, static_cast<OSVR_ChannelCount>(AnalogChannels::MAGNETOMETER_X));
osvrDeviceAnalogSetValue(deviceToken_, analog_, magnetometer.y, static_cast<OSVR_ChannelCount>(AnalogChannels::MAGNETOMETER_Y));
osvrDeviceAnalogSetValue(deviceToken_, analog_, magnetometer.z, static_cast<OSVR_ChannelCount>(AnalogChannels::MAGNETOMETER_Z));
// Temperature of sensor in degrees Celsius
const float temperature = sensor_data.Temperature;
osvrDeviceAnalogSetValue(deviceToken_, analog_, temperature, static_cast<OSVR_ChannelCount>(AnalogChannels::TEMPERATURE));
#endif
return OSVR_RETURN_SUCCESS;
}