From 2ba8f3a51adec91154838ce9dfa664821ce1e3d9 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Thu, 28 Sep 2023 14:07:29 +0100 Subject: [PATCH] Samples for data logging DataLoggingNextGenTest is suitable for testing MICROBIT_LOG_MODE 2 --- source/samples/DataLoggingNextGenTest.cpp | 60 +++++++++++++++++++++++ source/samples/DataLoggingTest.cpp | 36 ++++++++++++++ source/samples/Tests.h | 2 + 3 files changed, 98 insertions(+) create mode 100644 source/samples/DataLoggingNextGenTest.cpp create mode 100644 source/samples/DataLoggingTest.cpp diff --git a/source/samples/DataLoggingNextGenTest.cpp b/source/samples/DataLoggingNextGenTest.cpp new file mode 100644 index 00000000..af9e7b2e --- /dev/null +++ b/source/samples/DataLoggingNextGenTest.cpp @@ -0,0 +1,60 @@ +#include "MicroBit.h" +#include "Tests.h" + +// Requires MICROBIT_LOG_MODE value 2 +// Sample data for nextgen data logging for testing the MicroBitLog mode. +// Actual next gen data uses a custom HEX build in +// https://github.com/microbit-foundation/adl-recognition/ +const char* sample = \ +"movement_level,acceleration_mean,model_prediction,model_label1,model_label2,model_label3,model_label4,model_label5,model_label6,model_label7,metadata_key,metadata_value\n" +",,,,,,,,,,version,1\n" +",,,,,,,,,,row_interval_ms,1000\n" +",,,,,,,,,,display_mode,full\n" +",,,,,,,,,,model_version,6\n" +",,,,,,,,,,dev_mode,1\n" +",,,,,,,,,,start,7851\n" +"0,1030\n" +"1,1109\n" +"1,1087\n" +"0,1075\n" +"2,1510,2,27,816,11,144,0,0,0\n" +"2,1536\n" +"2,1479\n" +"2,1789\n" +"1,1261\n" +"2,1593,1,746,0,187,66,0,0,0\n" +"0,1017\n" +"2,1411\n" +"2,1788\n" +"2,1507\n" +"1,1286,1,828,19,148,7,0,0,0\n" +"1,1271\n" +"1,1147\n" +"0,1036\n" +"0,1036\n" +"0,1036,2,0,996,0,0,0,0,0\n" +"0,1036\n" +"0,1036\n" +"0,1036\n" +"0,1037\n" +"0,1036,2,0,996,0,0,0,0,0\n" +",,,,,,,,,,end,37451\n"; + + +void data_logging_timeseries_next_gen() +{ + while (1) + { + if (uBit.buttonA.wasPressed()) + { + uBit.display.scroll("L"); + uBit.log.logString(sample); + } + if (uBit.buttonB.wasPressed()) + { + uBit.display.scroll("C"); + uBit.log.clear(false); + } + uBit.sleep(1); + } +} \ No newline at end of file diff --git a/source/samples/DataLoggingTest.cpp b/source/samples/DataLoggingTest.cpp new file mode 100644 index 00000000..9aca350e --- /dev/null +++ b/source/samples/DataLoggingTest.cpp @@ -0,0 +1,36 @@ +#include "MicroBit.h" +#include "Tests.h" + +void data_logging_timeseries() +{ + uBit.log.setTimeStamp(TimeStampFormat::Seconds); + bool logging = false; + while (1) + { + if (uBit.buttonA.wasPressed()) + { + uBit.display.scroll("L"); + logging = true; + } + if (uBit.buttonB.wasPressed()) + { + uBit.display.scroll("C"); + logging = false; + uBit.log.clear(false); + } + if (uBit.log.isFull()) + { + uBit.display.scroll("F"); + logging = false; + } + if (logging) + { + uBit.log.beginRow(); + uBit.log.logData("x", uBit.accelerometer.getX()); + uBit.log.logData("y", uBit.accelerometer.getY()); + uBit.log.logData("z", uBit.accelerometer.getZ()); + uBit.log.endRow(); + uBit.sleep(250); + } + } +} \ No newline at end of file diff --git a/source/samples/Tests.h b/source/samples/Tests.h index 1657a897..ca163e7e 100644 --- a/source/samples/Tests.h +++ b/source/samples/Tests.h @@ -104,5 +104,7 @@ void stream_test_mic_activate(); void stream_test_getValue_interval(); void stream_test_record(); void stream_test_all(); +void data_logging_timeseries(); +void data_logging_timeseries_next_gen(); #endif