From 3d03378b93acc952356c9d51e50e97dbfdbfb5a9 Mon Sep 17 00:00:00 2001 From: amandel Date: Fri, 28 Feb 2025 14:52:39 +0100 Subject: [PATCH 1/4] Soft-off after 10 seconds not earlier --- src/OpenBikeSensorFirmware.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index 39b26cd..6b11f8a 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -252,7 +252,7 @@ static void powerKeepAliveTimerISR() } } - // Soft power-off OBSPro when button is pressed for more than 2 seconds + // Soft power-off OBSPro when button is pressed for more than 10 seconds if(button.read()) { if(buttonPressedCounter < 255) @@ -261,7 +261,7 @@ static void powerKeepAliveTimerISR() else buttonPressedCounter = 0; - if(shutdownState == 0 && buttonPressedCounter >= 50) { + if(shutdownState == 0 && buttonPressedCounter >= 100) { shutdownState = 1; } switch(shutdownState) From f43061249a8e040c80839fbdebe9d745c64f9653 Mon Sep 17 00:00:00 2001 From: amandel Date: Fri, 28 Feb 2025 15:06:19 +0100 Subject: [PATCH 2/4] Use the Button class, introduce constant. --- src/OpenBikeSensorFirmware.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index 6b11f8a..4abc4e0 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -103,7 +103,7 @@ CircularBuffer dataBuffer; FileWriter* writer; const uint8_t displayAddress = 0x3c; - +const uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS = 10000; // Enable dev-mode. Allows to // - set wifi config @@ -233,35 +233,26 @@ static uint8_t shutdownState = 0; // Power-management keep alive timer // This function is called every 100 ms static unsigned long timeOfLastPowerKeepAlive = 0; -static uint8_t buttonPressedCounter = 0; static void powerKeepAliveTimerISR() { // Send "keep alive" trigger to power management module // This is done by toggling the pin every 300 ms or more if(shutdownState == 0) { - if(!digitalRead(IP5306_BUTTON) && millis() - timeOfLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS) + unsigned long timeSinceLastPowerKeepAlive = millis() - timeOfLastPowerKeepAlive; + if(!digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS) { timeOfLastPowerKeepAlive = millis(); digitalWrite(IP5306_BUTTON, HIGH); } - else if(digitalRead(IP5306_BUTTON) && millis() - timeOfLastPowerKeepAlive > 300) + else if(digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > 300) { timeOfLastPowerKeepAlive = millis(); digitalWrite(IP5306_BUTTON, LOW); } } - // Soft power-off OBSPro when button is pressed for more than 10 seconds - if(button.read()) - { - if(buttonPressedCounter < 255) - buttonPressedCounter++; - } - else - buttonPressedCounter = 0; - - if(shutdownState == 0 && buttonPressedCounter >= 100) { + if(shutdownState == 0 && button.read() && button.getCurrentStateMillis() >= BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS) { shutdownState = 1; } switch(shutdownState) From 45fde04a69378bb4e23db9879e6df93e97e14deb Mon Sep 17 00:00:00 2001 From: amandel Date: Fri, 28 Feb 2025 15:21:27 +0100 Subject: [PATCH 3/4] read button only once --- src/OpenBikeSensorFirmware.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp index 4abc4e0..cf715f9 100644 --- a/src/OpenBikeSensorFirmware.cpp +++ b/src/OpenBikeSensorFirmware.cpp @@ -240,12 +240,14 @@ static void powerKeepAliveTimerISR() if(shutdownState == 0) { unsigned long timeSinceLastPowerKeepAlive = millis() - timeOfLastPowerKeepAlive; - if(!digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS) + bool ip5306ButtonState = digitalRead(IP5306_BUTTON); + + if(!ip5306ButtonState && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS) { timeOfLastPowerKeepAlive = millis(); digitalWrite(IP5306_BUTTON, HIGH); } - else if(digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > 300) + else if(ip5306ButtonState && timeSinceLastPowerKeepAlive > 300) { timeOfLastPowerKeepAlive = millis(); digitalWrite(IP5306_BUTTON, LOW); From 76b3be35c8a9a29c8da83a477ca2ccd8c0236928 Mon Sep 17 00:00:00 2001 From: amandel Date: Fri, 28 Feb 2025 18:01:42 +0100 Subject: [PATCH 4/4] work in progress - button / switch off not reliable? - display of process not in all cases --- .github/fake-cc | 0 .idea/codeStyles/Project.xml | 4 ---- README.md | 0 src/OpenBikeSensorFirmware.cpp | 15 +++++++++------ src/configServer.cpp | 2 ++ src/displays.cpp | 27 +++++++++++++++++++++++++-- src/displays.h | 1 + src/globals.h | 1 + src/utils/button.cpp | 7 ++++--- src/utils/button.h | 4 ++-- 10 files changed, 44 insertions(+), 17 deletions(-) mode change 100755 => 100644 .github/fake-cc mode change 100755 => 100644 README.md diff --git a/.github/fake-cc b/.github/fake-cc old mode 100755 new mode 100644 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 9574a18..abb5df9 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -8,10 +8,6 @@