diff options
Diffstat (limited to 'test_fw/src/main.cpp')
| -rw-r--r-- | test_fw/src/main.cpp | 62 |
1 files changed, 48 insertions, 14 deletions
diff --git a/test_fw/src/main.cpp b/test_fw/src/main.cpp index 8a6b3c4..6ffa9de 100644 --- a/test_fw/src/main.cpp +++ b/test_fw/src/main.cpp @@ -38,7 +38,8 @@ static VEML lux(Wire1); static Adafruit_LSM6DSL lsm; #define SCAN_I2C 0 -#define ENABLE_SD 0 +#define ENABLE_SD 1 +#define DEBUG_SD 0 #define SDCARD_SPI SD_SPI #include <SD.h> @@ -107,9 +108,12 @@ static QueueHandle_t bme_buffer_handle; #endif void setup() { -#if !USE_RTT - Serial.begin(115200); +#if USE_RTT + rtt.trimDownBufferFull(); + rtt.trimUpBufferFull(); #endif + + LOGGER.begin(115200); LOGGER.println("boot"); bringup::init_buses(); @@ -135,7 +139,6 @@ void setup() { #endif bringup::boot_animation(); - delay(100); } @@ -246,10 +249,19 @@ void loop() { sd_connected = false; } - if (millis() - sd_last_connect > sd_period && card_detected) + if (millis() - sd_last_connect > sd_period && card_detected && !sd_connected) { sd_last_connect = millis(); +#if 0 + Sd2Card card; + auto result = card.init(3, SD_CS); + + if (!result) + { + LOGGER.printf("failed to connect to sd card, code: %d, data: %d", card.errorCode(), card.errorData()); + } +#else if (!sd.begin(SD_CS)) { LOGGER.println("failed connection to sd card"); @@ -258,6 +270,7 @@ void loop() { { sd_connected = true; } +#endif } #endif @@ -331,22 +344,39 @@ void loop() { }; - for (const auto &[name, value] : readings) +#if !DEBUG_SD + if (LOGGER) { - // This awkwardness is to support the fact that the RTT implementation - // doesn't support formatting floats and instead silently fails -- manually - // format first, then printf the string. - char buf[32]; - auto n = snprintf(buf, sizeof(buf), "%s:%f,", name, value); + for (const auto &[name, value] : readings) + { + // This awkwardness is to support the fact that the RTT implementation + // doesn't support formatting floats and instead silently fails -- manually + // format first, then printf the string. + char buf[32]; + snprintf(buf, sizeof(buf), "%s:%f,", name, value); - LOGGER.printf("%s", buf); - } + LOGGER.printf("%s", buf); + } - LOGGER.println(); + LOGGER.println(); + } +#endif #if ENABLE_SD if (sd_connected) { auto data = sd.open("data.csv", O_CREAT | O_WRITE | O_APPEND); + if (data.size() == 0) + { + data.write("uptime_ms,"); + + for (const auto &[name, _] : readings) + { + data.write(name); + data.write(","); + } + + data.write("\n"); + } data.write(String(millis()).c_str()); @@ -358,6 +388,10 @@ void loop() { data.write("\n"); data.close(); + +#if DEBUG_SD + LOGGER.println("wrote entry to sd"); +#endif } #endif } |
