From 8dd552111c8a1f6964151ed12ba95623a6591174 Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 10 Jul 2023 16:25:19 +0200 Subject: [PATCH] add sd unavailable error --- controller_teensy/include/definitions.h | 1 + controller_teensy/include/display.h | 5 ++++- controller_teensy/include/logging.h | 3 +++ controller_teensy/src/main.cpp | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/controller_teensy/include/definitions.h b/controller_teensy/include/definitions.h index f94a576..a961335 100644 --- a/controller_teensy/include/definitions.h +++ b/controller_teensy/include/definitions.h @@ -64,6 +64,7 @@ unsigned long brake_ok_time=0; bool error_throttle_outofrange=false; bool error_brake_outofrange=false; bool error_ads_max_read_interval=false; +bool error_sdfile_unavailable=false; #define REVERSE_ENABLE_TIME 1000 //ms. how long standstill to be able to drive backward #define REVERSE_SPEED 0.25 //reverse driving speed //0 to 1 diff --git a/controller_teensy/include/display.h b/controller_teensy/include/display.h index b401c92..59bd7ec 100644 --- a/controller_teensy/include/display.h +++ b/controller_teensy/include/display.h @@ -51,7 +51,7 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){ display.print(F(" / ")); display.println(escRear.getFeedback_batVoltage()); */ - if ( (error_brake_outofrange || error_throttle_outofrange || error_ads_max_read_interval ) && ((loopmillis/2000)%2==0)) { + if ( (error_brake_outofrange || error_throttle_outofrange || error_ads_max_read_interval || error_sdfile_unavailable) && ((loopmillis/2000)%2==0)) { //Error Messages display.setFont(); @@ -70,6 +70,8 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){ } if (error_ads_max_read_interval) { errorstring+="ads_max_read_interval\n"; + }if (error_sdfile_unavailable) { + errorstring+="error_sdfile_unavailable\n"; } display.print(errorstring); @@ -87,6 +89,7 @@ void display_update(ESCSerialComm& escFront, ESCSerialComm& escRear){ }else{ display_standingDisarmedDisplay(escFront,escRear); } + } diff --git a/controller_teensy/include/logging.h b/controller_teensy/include/logging.h index 2e67b66..d4a0726 100644 --- a/controller_teensy/include/logging.h +++ b/controller_teensy/include/logging.h @@ -59,6 +59,7 @@ void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm File dataFile = SD.open(datalogging_filename, FILE_WRITE); + if (dataFile) { // if the file is available, write to it if (!logging_headerWritten) { dataFile.print("time,cmd_FrontL,cmd_FrontR,cmd_RearL,cmd_RearR,"); @@ -106,6 +107,8 @@ void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm dataFile.println(""); dataFile.close(); + }else{ //dataFile not available + error_sdfile_unavailable=true; } } } diff --git a/controller_teensy/src/main.cpp b/controller_teensy/src/main.cpp index 448149a..1e9a9ef 100644 --- a/controller_teensy/src/main.cpp +++ b/controller_teensy/src/main.cpp @@ -529,6 +529,12 @@ void failChecks() { //Serial.print("Error ADS Max read interval="); Serial.println(loopmillis-last_adsread); } + boolean logged_error_sdfile_unavailable=false; + if (error_sdfile_unavailable && !logged_error_sdfile_unavailable) { + logged_error_sdfile_unavailable=true; + writeLogComment(loopmillis, "Error SDFile Unavailable"); + } + if (!controllers_connected || error_brake_outofrange || error_throttle_outofrange || error_ads_max_read_interval) { //any errors? armed=false; //disarm throttle_pos=0;