From 16dfabc6bacd853a71799e182b32429ebf625087 Mon Sep 17 00:00:00 2001 From: Fisch Date: Tue, 16 Jul 2024 23:47:58 +0200 Subject: [PATCH] fix logging file first row zero values --- controller_teensy/include/logging.h | 2 +- controller_teensy/src/main.cpp | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/controller_teensy/include/logging.h b/controller_teensy/include/logging.h index e3af7b1..843dc60 100644 --- a/controller_teensy/include/logging.h +++ b/controller_teensy/include/logging.h @@ -81,7 +81,7 @@ bool initLogging() { void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm& escRear) { - static unsigned long last_datalogging_write=0; + static unsigned long last_datalogging_write=loopmillis; //initialize with current time to have first log written after one interval static boolean logging_headerWritten=false; unsigned long logginginterval=LOGGINGINTERVAL; diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index 07aac79..7012459 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -269,14 +269,6 @@ void loop() { - loggingLoop(loopmillis,escFront,escRear); - if (!armed && !statswritten) { //write stats only once when disarmed - statswritten=true; - writeTrip(loopmillis,escFront,escRear); - } - if (statswritten && armed) { - statswritten=false; - } leds(); led_update(loopmillis,escFront,escRear); //ws2812 led ring @@ -325,6 +317,17 @@ void loop() { serialCommandLoop(loopmillis,escFront,escRear); + + + //Logging + loggingLoop(loopmillis,escFront,escRear); + if (!armed && !statswritten) { //write stats only once when disarmed + statswritten=true; + writeTrip(loopmillis,escFront,escRear); + } + if (statswritten && armed) { + statswritten=false; + } looptime_duration_min=min(looptime_duration_min,millis()-loopmillis);