From dcc6a4b5e7fd7074dd7daf17fa8936eafa4828a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 28 Jul 2022 09:37:16 +0200 Subject: [PATCH 1/4] Tryfix LED T-Echo --- src/ButtonThread.h | 7 +++++++ src/shutdown.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index 49243a93d..1549c748b 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -144,8 +144,15 @@ class ButtonThread : public concurrency::OSThread screen->startShutdownScreen(); DEBUG_MSG("Shutdown from long press"); playBeep(); +#ifdef PIN_LED1 ledOff(PIN_LED1); +#endif +#ifdef PIN_LED2 ledOff(PIN_LED2); +#endif +#ifdef PIN_LED3 + ledOff(PIN_LED3); +#endif shutdown_on_long_stop = true; } #endif diff --git a/src/shutdown.h b/src/shutdown.h index 57cd1b691..718ed0e0b 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -21,8 +21,15 @@ void powerCommandsCheck() if (shutdownAtMsec) { screen->startShutdownScreen(); playBeep(); +#ifdef PIN_LED1 ledOff(PIN_LED1); +#endif +#ifdef PIN_LED2 ledOff(PIN_LED2); +#endif +#ifdef PIN_LED3 + ledOff(PIN_LED3); +#endif } #endif From 295dca84154d64bbf0f1340004d482433990b933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 4 Aug 2022 09:08:02 +0200 Subject: [PATCH 2/4] Work around bug in littlefs rename() for now. After upstream change to version 2.5 this can be reverted. --- src/FSCommon.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/FSCommon.h | 1 + src/mesh/NodeDB.cpp | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index b0ba44f28..56dece8cd 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -1,6 +1,46 @@ #include "configuration.h" #include "FSCommon.h" + +bool copyFile(const char* from, const char* to) +{ +#ifdef FSCom + unsigned char cbuffer[16]; + + File f1 = FSCom.open(from, FILE_O_READ); + if (!f1){ + DEBUG_MSG("Failed to open file"); + return false; + } + + File f2 = FSCom.open(to, FILE_O_WRITE); + if (!f2) { + DEBUG_MSG("Failed to open file"); + return false; + } + + while (f1.available() > 0) { + byte i = f1.read(cbuffer, 16); + f2.write(cbuffer, i); + } + + f2.close(); + f1.close(); + return true; +#endif +} + +bool renameFile(const char* pathFrom, const char* pathTo) +{ +#ifdef FSCom + if (copyFile(pathFrom, pathTo) & FSCom.remove(pathFrom) ) { + return true; + } else{ + return false; + } +#endif +} + void listDir(const char * dirname, uint8_t levels) { #ifdef FSCom diff --git a/src/FSCommon.h b/src/FSCommon.h index 3493a8464..89b2ed10d 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -31,5 +31,6 @@ using namespace Adafruit_LittleFS_Namespace; #endif void fsInit(); +bool renameFile(const char* pathFrom, const char* pathTo); void listDir(const char * dirname, uint8_t levels); void rmDir(const char * dirname); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cb4c625db..48a525fcd 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -414,7 +414,7 @@ bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_ // brief window of risk here ;-) if (FSCom.exists(filename) && !FSCom.remove(filename)) DEBUG_MSG("Warning: Can't remove old pref file\n"); - if (!FSCom.rename(filenameTmp.c_str(), filename)) + if (!renameFile(filenameTmp.c_str(), filename)) DEBUG_MSG("Error: can't rename new pref file\n"); } else { DEBUG_MSG("Can't write prefs\n"); From 18d5712ecd5d98f13c0edf343268413492b2b3a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 4 Aug 2022 09:10:50 +0200 Subject: [PATCH 3/4] This code was committed by mistake --- src/ButtonThread.h | 7 ------- src/shutdown.h | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index fe014246c..50ac14316 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -144,15 +144,8 @@ class ButtonThread : public concurrency::OSThread screen->startShutdownScreen(); DEBUG_MSG("Shutdown from long press"); playBeep(); -#ifdef PIN_LED1 ledOff(PIN_LED1); -#endif -#ifdef PIN_LED2 ledOff(PIN_LED2); -#endif -#ifdef PIN_LED3 - ledOff(PIN_LED3); -#endif shutdown_on_long_stop = true; } #endif diff --git a/src/shutdown.h b/src/shutdown.h index 4c82b16c4..a0b10f4ff 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -21,15 +21,8 @@ void powerCommandsCheck() if (shutdownAtMsec) { screen->startShutdownScreen(); playBeep(); -#ifdef PIN_LED1 ledOff(PIN_LED1); -#endif -#ifdef PIN_LED2 ledOff(PIN_LED2); -#endif -#ifdef PIN_LED3 - ledOff(PIN_LED3); -#endif } #endif From 71a9f4645101709fb110a5a896dc7747024b6108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 4 Aug 2022 09:12:56 +0200 Subject: [PATCH 4/4] change to logical and operator --- src/FSCommon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 56dece8cd..76dc97757 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -33,7 +33,7 @@ bool copyFile(const char* from, const char* to) bool renameFile(const char* pathFrom, const char* pathTo) { #ifdef FSCom - if (copyFile(pathFrom, pathTo) & FSCom.remove(pathFrom) ) { + if (copyFile(pathFrom, pathTo) && FSCom.remove(pathFrom) ) { return true; } else{ return false;