Skip to content

Commit 474ad24

Browse files
committed
add(vector): implement LogI2c vector/color/orientation
1 parent f8b5d97 commit 474ad24

File tree

2 files changed

+97
-6
lines changed

2 files changed

+97
-6
lines changed

src/components/i2c/drivers/drvQmc5883p.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ bool drvQmc5883p::getEventRaw(sensors_event_t *rawEvent) {
9191
// Get Gauss field data
9292
if (!_qmc->getGaussField(&gx, &gy, &gz)) {
9393
WS_DEBUG_PRINTLN("Failed to read Gauss field data");
94+
WS_DEBUG_PRINTLN("Raw x: " + String(x) + " y: " + String(y) +
95+
" z: " + String(z));
9496
return false;
9597
}
9698

@@ -101,6 +103,8 @@ bool drvQmc5883p::getEventRaw(sensors_event_t *rawEvent) {
101103
}
102104

103105
// Calculate magnitude in Gauss
106+
WS_DEBUG_PRINTLN("RAW EVENT: Gauss Field (G) X: " + String(gx) +
107+
" Y: " + String(gy) + " Z: " + String(gz));
104108
float magnitude_G = sqrtf(gx * gx + gy * gy + gz * gz);
105109
rawEvent->data[0] = magnitude_G;
106110
return true;
@@ -133,6 +137,8 @@ bool drvQmc5883p::getEventMagneticField(sensors_event_t *magneticEvent) {
133137
// Get Gauss field data
134138
if (!_qmc->getGaussField(&gx, &gy, &gz)) {
135139
WS_DEBUG_PRINTLN("Failed to read Gauss field data");
140+
WS_DEBUG_PRINTLN("Raw x: " + String(x) + " y: " + String(y) +
141+
" z: " + String(z));
136142
return false;
137143
}
138144

@@ -146,7 +152,10 @@ bool drvQmc5883p::getEventMagneticField(sensors_event_t *magneticEvent) {
146152
magneticEvent->magnetic.x = gx * 100.0f;
147153
magneticEvent->magnetic.y = gy * 100.0f;
148154
magneticEvent->magnetic.z = gz * 100.0f;
149-
155+
WS_DEBUG_PRINTLN(
156+
"Magnetic Field (uT) X: " + String(magneticEvent->magnetic.x) +
157+
" Y: " + String(magneticEvent->magnetic.y) +
158+
" Z: " + String(magneticEvent->magnetic.z));
150159
return true;
151160
}
152161

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,93 @@ bool ws_sdcard::LogEventI2c(
14001400
// Log each event
14011401
for (pb_size_t i = 0; i < msg_device_event->i2c_device_events_count; i++) {
14021402
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+
}
14081490
}
14091491
return true;
14101492
}

0 commit comments

Comments
 (0)