Skip to content

Commit 95d7a24

Browse files
committed
[fix]: I2C not setting which_value type per event
1 parent a653fae commit 95d7a24

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/components/i2c/model.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,7 @@ GetValueFromSensorsEventOrientation(wippersnapper_sensor_SensorType sensor_type,
221221
*/
222222
bool GetValueFromSensorsEventBoolean(
223223
wippersnapper_sensor_SensorType sensor_type, sensors_event_t *event) {
224-
bool value = false;
225-
WS_DEBUG_PRINTLN("[i2c] Getting boolean event value...");
226-
WS_DEBUG_PRINT("[i2c] Event data[0]: ");
227-
WS_DEBUG_PRINTLN(event->data[0]);
228-
value = event->data[0] > 0.0f;
229-
WS_DEBUG_PRINT("[i2c] Boolean value (x>0): ");
230-
WS_DEBUG_PRINTLN(value);
231-
return value;
224+
return event->data[0] > 0.0f;
232225
}
233226

234227
/*!
@@ -477,6 +470,9 @@ bool I2cModel::AddI2cDeviceSensorEvent(
477470
_msg_i2c_device_event
478471
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
479472
.value.vector_value.z = value_vect.z;
473+
_msg_i2c_device_event
474+
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
475+
.which_value = wippersnapper_sensor_SensorEvent_vector_value_tag;
480476
} else if (sensor_type ==
481477
wippersnapper_sensor_SensorType_SENSOR_TYPE_ORIENTATION ||
482478
sensor_type ==
@@ -492,18 +488,27 @@ bool I2cModel::AddI2cDeviceSensorEvent(
492488
_msg_i2c_device_event
493489
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
494490
.value.orientation_value.pitch = value_vect.pitch;
491+
_msg_i2c_device_event
492+
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
493+
.which_value = wippersnapper_sensor_SensorEvent_orientation_value_tag;
495494
// TODO: Add color RGB(A) vector support
496495
} else if (sensor_type ==
497496
wippersnapper_sensor_SensorType_SENSOR_TYPE_BOOLEAN) {
498497
bool value = GetValueFromSensorsEventBoolean(sensor_type, &event);
499498
_msg_i2c_device_event
500499
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
501500
.value.bool_value = value;
501+
_msg_i2c_device_event
502+
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
503+
.which_value = wippersnapper_sensor_SensorEvent_bool_value_tag;
502504
} else {
503505
float value = GetValueFromSensorsEvent(sensor_type, &event);
504506
_msg_i2c_device_event
505507
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
506508
.value.float_value = value;
509+
_msg_i2c_device_event
510+
.i2c_device_events[_msg_i2c_device_event.i2c_device_events_count]
511+
.which_value = wippersnapper_sensor_SensorEvent_float_value_tag;
507512
}
508513

509514
_msg_i2c_device_event.i2c_device_events_count++;

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,23 +1382,24 @@ bool ws_sdcard::LogEventDs18x(wippersnapper_ds18x20_Ds18x20Event *event_msg) {
13821382
*/
13831383
bool ws_sdcard::LogEventI2c(
13841384
wippersnapper_i2c_I2cDeviceEvent *msg_device_event) {
1385-
JsonDocument doc;
1385+
JsonDocument baseDoc;
13861386
// Pull the DeviceDescriptor out
13871387
wippersnapper_i2c_I2cDeviceDescriptor descriptor =
13881388
msg_device_event->i2c_device_description;
13891389
char hex_addr[5];
13901390
snprintf(hex_addr, sizeof(hex_addr), "0x%02X", descriptor.i2c_device_address);
1391-
doc["i2c_address"] = hex_addr;
1391+
baseDoc["i2c_address"] = hex_addr;
13921392

13931393
// Using I2C MUX?
13941394
if (descriptor.i2c_mux_address != 0x00) {
13951395
snprintf(hex_addr, sizeof(hex_addr), "0x%02X", descriptor.i2c_mux_address);
1396-
doc["i2c_mux_addr"] = hex_addr;
1397-
doc["i2c_mux_ch"] = descriptor.i2c_mux_channel;
1396+
baseDoc["i2c_mux_addr"] = hex_addr;
1397+
baseDoc["i2c_mux_ch"] = descriptor.i2c_mux_channel;
13981398
}
13991399

14001400
// Log each event
14011401
for (pb_size_t i = 0; i < msg_device_event->i2c_device_events_count; i++) {
1402+
JsonDocument doc = baseDoc; // no stale vectors/values
14021403
doc["timestamp"] = GetTimestamp();
14031404
// if mag/vector/colour etc log all value elements
14041405
if (msg_device_event->i2c_device_events[i].type ==

0 commit comments

Comments
 (0)