@@ -146,6 +146,27 @@ GetValueFromSensorsEventVector(wippersnapper_sensor_SensorType sensor_type,
146
146
value.y = event->magnetic .y ;
147
147
value.z = event->magnetic .z ;
148
148
break ;
149
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_ACCELEROMETER:
150
+ value.x = event->acceleration .x ;
151
+ value.y = event->acceleration .y ;
152
+ value.z = event->acceleration .z ;
153
+ break ;
154
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_GYROSCOPE:
155
+ value.x = event->gyro .x ;
156
+ value.y = event->gyro .y ;
157
+ value.z = event->gyro .z ;
158
+ break ;
159
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_GRAVITY:
160
+ value.x = event->acceleration .x ;
161
+ value.y = event->acceleration .y ;
162
+ value.z = event->acceleration .z ;
163
+ break ;
164
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_LINEAR_ACCELERATION:
165
+ value.x = event->acceleration .x ;
166
+ value.y = event->acceleration .y ;
167
+ value.z = event->acceleration .z ;
168
+ break ;
169
+
149
170
default :
150
171
value.x = 0.0 ;
151
172
value.y = 0.0 ;
@@ -155,6 +176,38 @@ GetValueFromSensorsEventVector(wippersnapper_sensor_SensorType sensor_type,
155
176
return value;
156
177
}
157
178
179
+ /* !
180
+ @brief Returns the orientation vector event value mapped to a sensor event.
181
+ @param sensor_type
182
+ The SensorType.
183
+ @param event
184
+ The sensors_event_t event.
185
+ @returns The value of the SensorType as an orientation vector.
186
+ */
187
+ wippersnapper_sensor_SensorEvent_SensorEventOrientation
188
+ GetValueFromSensorsEventOrientation (wippersnapper_sensor_SensorType sensor_type,
189
+ sensors_event_t *event) {
190
+ wippersnapper_sensor_SensorEvent_SensorEventOrientation value = {0.0 , 0.0 , 0.0 };
191
+ switch (sensor_type) {
192
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_ORIENTATION:
193
+ value.roll = event->orientation .roll ;
194
+ value.pitch = event->orientation .pitch ;
195
+ value.heading = event->orientation .heading ;
196
+ break ;
197
+ case wippersnapper_sensor_SensorType_SENSOR_TYPE_ROTATION_VECTOR:
198
+ value.roll = event->orientation .roll ;
199
+ value.pitch = event->orientation .pitch ;
200
+ value.heading = event->orientation .heading ;
201
+ break ;
202
+ default :
203
+ value.roll = 0.0 ;
204
+ value.pitch = 0.0 ;
205
+ value.heading = 0.0 ;
206
+ break ;
207
+ }
208
+ return value;
209
+ }
210
+
158
211
/* !
159
212
@brief Decodes a I2cDeviceRemove message from an input stream.
160
213
@param stream
@@ -383,7 +436,11 @@ bool I2cModel::AddI2cDeviceSensorEvent(
383
436
.i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
384
437
.type = sensor_type;
385
438
if (sensor_type ==
386
- wippersnapper_sensor_SensorType_SENSOR_TYPE_MAGNETIC_FIELD) {
439
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_MAGNETIC_FIELD || sensor_type ==
440
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_ACCELEROMETER || sensor_type ==
441
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_GYROSCOPE || sensor_type ==
442
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_GRAVITY || sensor_type ==
443
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_LINEAR_ACCELERATION) {
387
444
wippersnapper_sensor_SensorEvent_SensorEvent3DVector value_vect = GetValueFromSensorsEventVector (sensor_type, &event);
388
445
_msg_i2c_device_event
389
446
.i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
@@ -394,6 +451,19 @@ bool I2cModel::AddI2cDeviceSensorEvent(
394
451
_msg_i2c_device_event
395
452
.i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
396
453
.value .vector_value .z = value_vect.z ;
454
+ } else if (sensor_type == wippersnapper_sensor_SensorType_SENSOR_TYPE_ORIENTATION || sensor_type ==
455
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_ROTATION_VECTOR) {
456
+ wippersnapper_sensor_SensorEvent_SensorEventOrientation value_vect = GetValueFromSensorsEventOrientation (sensor_type, &event);
457
+ _msg_i2c_device_event
458
+ .i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
459
+ .value .orientation_value .heading = value_vect.heading ;
460
+ _msg_i2c_device_event
461
+ .i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
462
+ .value .orientation_value .roll = value_vect.roll ;
463
+ _msg_i2c_device_event
464
+ .i2c_device_events [_msg_i2c_device_event.i2c_device_events_count ]
465
+ .value .orientation_value .pitch = value_vect.pitch ;
466
+ // TODO: Add color RGB(A) vector support
397
467
} else {
398
468
float value = GetValueFromSensorsEvent (sensor_type, &event);
399
469
_msg_i2c_device_event
0 commit comments