Skip to content

Commit

Permalink
Added inactivity reboot timer
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar committed Feb 7, 2024
1 parent 825d954 commit c99b69b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 19 additions & 5 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 /////////////
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c99b69b

Please sign in to comment.