aboutsummaryrefslogtreecommitdiffstats
path: root/src/sensor_bulk.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2023-12-17 17:59:25 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-01-19 11:55:15 -0500
commit266e96621c0133e1192bbaec5addb6bcf443a203 (patch)
tree1f4396874db47db20aa75feb09757204c13b2c98 /src/sensor_bulk.c
parentdc6182f3b339b990c8a68940f02a210e332be269 (diff)
downloadkutter-266e96621c0133e1192bbaec5addb6bcf443a203.tar.gz
kutter-266e96621c0133e1192bbaec5addb6bcf443a203.tar.xz
kutter-266e96621c0133e1192bbaec5addb6bcf443a203.zip
sensor_bulk: New C file with helper code for sending bulk sensor measurements
Refactor the low-level "bulk sensor" management code in the mcu. This updates the sensor_adxl345.c, sensor_mpu9250.c, sensor_lis2dw.c, and sensor_angle.c code to use the same "bulk sensor" messages. All of these sensors will now send "sensor_bulk_data" and "sensor_bulk_status" messages. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/sensor_bulk.c')
-rw-r--r--src/sensor_bulk.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/sensor_bulk.c b/src/sensor_bulk.c
new file mode 100644
index 00000000..9b5c782c
--- /dev/null
+++ b/src/sensor_bulk.c
@@ -0,0 +1,38 @@
+// Helper code for collecting and sending bulk sensor measurements
+//
+// Copyright (C) 2020-2023 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "command.h" // sendf
+#include "sensor_bulk.h" // sensor_bulk_report
+
+// Reset counters
+void
+sensor_bulk_reset(struct sensor_bulk *sb)
+{
+ sb->sequence = 0;
+ sb->possible_overflows = 0;
+ sb->data_count = 0;
+}
+
+// Report local measurement buffer
+void
+sensor_bulk_report(struct sensor_bulk *sb, uint8_t oid)
+{
+ sendf("sensor_bulk_data oid=%c sequence=%hu data=%*s"
+ , oid, sb->sequence, sb->data_count, sb->data);
+ sb->data_count = 0;
+ sb->sequence++;
+}
+
+// Report buffer and fifo status
+void
+sensor_bulk_status(struct sensor_bulk *sb, uint8_t oid
+ , uint32_t time1, uint32_t query_ticks, uint32_t fifo)
+{
+ sendf("sensor_bulk_status oid=%c clock=%u query_ticks=%u next_sequence=%hu"
+ " buffered=%u possible_overflows=%hu"
+ , oid, time1, query_ticks, sb->sequence
+ , sb->data_count + fifo, sb->possible_overflows);
+}