From c99b69be5e14c38d6a9544fef5635780adae260b Mon Sep 17 00:00:00 2001 From: Anthony Doud Date: Tue, 6 Feb 2024 18:06:39 -0600 Subject: [PATCH] Added inactivity reboot timer --- include/settings.h | 2 +- src/Main.cpp | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/settings.h b/include/settings.h index 89564c4a..0ee37e29 100644 --- a/include/settings.h +++ b/include/settings.h @@ -38,7 +38,7 @@ #define configFILENAME "/config.txt" // name of local file to save Physical Working Capacity in LittleFS -#define userPWCFILENAME "/userPWC->txt" +#define userPWCFILENAME "/userPWC.txt" // name of the local file to save the torque table. #define TORQUE_TABLE_FILENAME "/TorqueTable.txt" diff --git a/src/Main.cpp b/src/Main.cpp index b9523c97..089a46a6 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -35,9 +35,9 @@ Boards boards; Board currentBoard; ///////////// Initialize the Config ///////////// -SS2K *ss2k = new SS2K; -userParameters *userConfig = new userParameters; -RuntimeParameters *rtConfig = new RuntimeParameters; +SS2K *ss2k = new SS2K; +userParameters *userConfig = new userParameters; +RuntimeParameters *rtConfig = new RuntimeParameters; physicalWorkingCapacity *userPWC = new physicalWorkingCapacity; ///////////// Log Appender ///////////// @@ -190,6 +190,7 @@ void SS2K::maintenanceLoop(void *pvParameters) { static int loopCounter = 0; static unsigned long intervalTimer = millis(); static unsigned long intervalTimer2 = millis(); + static unsigned long rebootTimer = millis(); static bool isScanning = false; while (true) { @@ -200,8 +201,8 @@ void SS2K::maintenanceLoop(void *pvParameters) { ss2k->txSerial(); } - if(ss2k->rebootFlag){ - vTaskDelay(100/portTICK_RATE_MS); + if (ss2k->rebootFlag) { + vTaskDelay(100 / portTICK_RATE_MS); ESP.restart(); } @@ -232,6 +233,19 @@ void SS2K::maintenanceLoop(void *pvParameters) { } intervalTimer2 = millis(); } + + // reboot every half hour if not in use. + if ((millis() - rebootTimer) > 1800000) { + if (NimBLEDevice::getServer()) { + if (!(NimBLEDevice::getServer()->getConnectedCount())) { + SS2K_LOGW(MAIN_LOG_TAG, "Rebooting due to inactivity"); + ss2k->rebootFlag = true; + }else{ + rebootTimer = millis(); + } + } + } + if (loopCounter > 10) { ss2k->checkDriverTemperature();