@@ -1400,11 +1400,93 @@ bool ws_sdcard::LogEventI2c(
1400
1400
// Log each event
1401
1401
for (pb_size_t i = 0 ; i < msg_device_event->i2c_device_events_count ; i++) {
1402
1402
doc[" timestamp" ] = GetTimestamp ();
1403
- doc[" value" ] = msg_device_event->i2c_device_events [i].value .float_value ;
1404
- doc[" si_unit" ] =
1405
- SensorTypeToSIUnit (msg_device_event->i2c_device_events [i].type );
1406
- if (!LogJSONDoc (doc))
1407
- return false ;
1403
+ // if mag/vector/colour etc log all value elements
1404
+ if (msg_device_event->i2c_device_events [i].type ==
1405
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_MAGNETIC_FIELD ||
1406
+ msg_device_event->i2c_device_events [i].type ==
1407
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_ACCELEROMETER ||
1408
+ msg_device_event->i2c_device_events [i].type ==
1409
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_GYROSCOPE ||
1410
+ msg_device_event->i2c_device_events [i].type ==
1411
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_GRAVITY ||
1412
+ msg_device_event->i2c_device_events [i].type ==
1413
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_LINEAR_ACCELERATION) {
1414
+ doc[" value_x" ] =
1415
+ msg_device_event->i2c_device_events [i].value .vector_value .x ;
1416
+ doc[" value_y" ] =
1417
+ msg_device_event->i2c_device_events [i].value .vector_value .y ;
1418
+ doc[" value_z" ] =
1419
+ msg_device_event->i2c_device_events [i].value .vector_value .z ;
1420
+ doc[" value" ] =
1421
+ String (" (" ) +
1422
+ String (msg_device_event->i2c_device_events [i].value .vector_value .x ) +
1423
+ String (" , " ) +
1424
+ String (msg_device_event->i2c_device_events [i].value .vector_value .y ) +
1425
+ String (" , " ) +
1426
+ String (msg_device_event->i2c_device_events [i].value .vector_value .z ) +
1427
+ String (" )" );
1428
+ doc[" si_unit" ] =
1429
+ SensorTypeToSIUnit (msg_device_event->i2c_device_events [i].type );
1430
+ if (!LogJSONDoc (doc))
1431
+ return false ;
1432
+ continue ;
1433
+ } else if (msg_device_event->i2c_device_events [i].type ==
1434
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_COLOR) {
1435
+ doc[" value_r" ] =
1436
+ msg_device_event->i2c_device_events [i].value .color_value .r ;
1437
+ doc[" value_g" ] =
1438
+ msg_device_event->i2c_device_events [i].value .color_value .g ;
1439
+ doc[" value_b" ] =
1440
+ msg_device_event->i2c_device_events [i].value .color_value .b ;
1441
+ doc[" value_a" ] =
1442
+ msg_device_event->i2c_device_events [i].value .color_value .a ;
1443
+ doc[" value" ] =
1444
+ String (" (" ) +
1445
+ String (msg_device_event->i2c_device_events [i].value .color_value .r ) +
1446
+ String (" , " ) +
1447
+ String (msg_device_event->i2c_device_events [i].value .color_value .g ) +
1448
+ String (" , " ) +
1449
+ String (msg_device_event->i2c_device_events [i].value .color_value .b ) +
1450
+ String (" , " ) +
1451
+ String (msg_device_event->i2c_device_events [i].value .color_value .a ) +
1452
+ String (" )" );
1453
+ doc[" si_unit" ] = " RGBA" ;
1454
+ if (!LogJSONDoc (doc))
1455
+ return false ;
1456
+ continue ;
1457
+ } else if (
1458
+ msg_device_event->i2c_device_events [i].type ==
1459
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_ORIENTATION ||
1460
+ msg_device_event->i2c_device_events [i].type ==
1461
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_ROTATION_VECTOR) {
1462
+ // heading/roll/pitch
1463
+ doc[" value_heading" ] = msg_device_event->i2c_device_events [i]
1464
+ .value .orientation_value .heading ;
1465
+ doc[" value_roll" ] =
1466
+ msg_device_event->i2c_device_events [i].value .orientation_value .roll ;
1467
+ doc[" value_pitch" ] =
1468
+ msg_device_event->i2c_device_events [i].value .orientation_value .pitch ;
1469
+ doc[" value" ] = String (" (" ) +
1470
+ String (msg_device_event->i2c_device_events [i]
1471
+ .value .orientation_value .heading ) +
1472
+ String (" , " ) +
1473
+ String (msg_device_event->i2c_device_events [i]
1474
+ .value .orientation_value .roll ) +
1475
+ String (" , " ) +
1476
+ String (msg_device_event->i2c_device_events [i]
1477
+ .value .orientation_value .pitch ) +
1478
+ String (" )" );
1479
+ doc[" si_unit" ] = " HPR" ;
1480
+ if (!LogJSONDoc (doc))
1481
+ return false ;
1482
+ continue ;
1483
+ } else { // normal scalar float value
1484
+ doc[" value" ] = msg_device_event->i2c_device_events [i].value .float_value ;
1485
+ doc[" si_unit" ] =
1486
+ SensorTypeToSIUnit (msg_device_event->i2c_device_events [i].type );
1487
+ if (!LogJSONDoc (doc))
1488
+ return false ;
1489
+ }
1408
1490
}
1409
1491
return true ;
1410
1492
}
0 commit comments