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 9574a185..abb5df90 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -8,10 +8,6 @@
-
-
-
-
diff --git a/README.md b/README.md
old mode 100755
new mode 100644
diff --git a/src/OpenBikeSensorFirmware.cpp b/src/OpenBikeSensorFirmware.cpp
index 39b26cdd..2579580d 100644
--- a/src/OpenBikeSensorFirmware.cpp
+++ b/src/OpenBikeSensorFirmware.cpp
@@ -77,7 +77,7 @@ Gps gps;
static const long BLUETOOTH_INTERVAL_MILLIS = 100;
static long lastBluetoothInterval = 0;
-static const long DISPLAY_INTERVAL_MILLIS = 200;
+static const long DISPLAY_INTERVAL_MILLIS = 300;
static long lastDisplayInterval = 0;
float TemperatureValue = -1;
@@ -103,7 +103,7 @@ CircularBuffer dataBuffer;
FileWriter* writer;
const uint8_t displayAddress = 0x3c;
-
+constexpr uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS = 5000;
// Enable dev-mode. Allows to
// - set wifi config
@@ -233,35 +233,31 @@ 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()
{
+ unsigned long now = millis();
+
// 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 = now - timeOfLastPowerKeepAlive;
+ bool ip5306ButtonState = digitalRead(IP5306_BUTTON);
+
+ if(!ip5306ButtonState && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
{
- timeOfLastPowerKeepAlive = millis();
+ timeOfLastPowerKeepAlive = now;
digitalWrite(IP5306_BUTTON, HIGH);
}
- else if(digitalRead(IP5306_BUTTON) && millis() - timeOfLastPowerKeepAlive > 300)
+ else if(ip5306ButtonState && timeSinceLastPowerKeepAlive > 300)
{
- timeOfLastPowerKeepAlive = millis();
+ timeOfLastPowerKeepAlive = now;
digitalWrite(IP5306_BUTTON, LOW);
}
}
- // Soft power-off OBSPro when button is pressed for more than 2 seconds
- if(button.read())
- {
- if(buttonPressedCounter < 255)
- buttonPressedCounter++;
- }
- else
- buttonPressedCounter = 0;
-
- if(shutdownState == 0 && buttonPressedCounter >= 50) {
+ if(shutdownState == 0 && button.handle(now)
+ && button.getCurrentStateMillis() >= BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS) {
shutdownState = 1;
}
switch(shutdownState)
diff --git a/src/configServer.cpp b/src/configServer.cpp
index 272fac24..2716c8ff 100644
--- a/src/configServer.cpp
+++ b/src/configServer.cpp
@@ -509,6 +509,7 @@ String getIp() {
}
void updateDisplay(DisplayDevice * const display, String action = "") {
+ obsDisplay->handleShutdownDisplay();
if (action.isEmpty()) {
display->showTextOnGrid(0, 0, "Ver.:");
display->showTextOnGrid(1, 0, OBSVersion);
@@ -2068,6 +2069,7 @@ void configServerHandle() {
if (obsImprov) {
obsImprov->handle();
}
+ obsDisplay->handleShutdownDisplay();
}
std::vector> extractParameters(HTTPRequest *req) {
diff --git a/src/displays.cpp b/src/displays.cpp
index d3de3444..e6d99324 100644
--- a/src/displays.cpp
+++ b/src/displays.cpp
@@ -54,6 +54,30 @@ void DisplayDevice::displaySimple(uint16_t value) {
this->prepareTextOnGrid(3, 2, "cm", MEDIUM_FONT, -7, -5);
}
+bool startedShutdownDisplay = false;
+
+bool DisplayDevice::handleShutdownDisplay()
+{
+ bool updated = false;
+#ifdef OBSPRO
+ bool buttonPressed = button.getState();
+ if (buttonPressed && button.getCurrentStateMillis() > 3000)
+ {
+ auto pressTimeMs = button.getCurrentStateMillis() - 3000;
+ // black out the display from top to bottom for so that after 7000 ms the whole display is black
+ auto linesToFill = (pressTimeMs * 64) / (BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS - 3000);
+
+ m_display->drawBox(0, 0, 128, linesToFill);
+ startedShutdownDisplay = true;
+ } else if (startedShutdownDisplay) {
+ startedShutdownDisplay = false;
+ clear();
+ updated = true;
+ }
+#endif
+ return updated;
+}
+
void DisplayDevice::showValues(
uint16_t sensor1MinDistance, const char* sensor1Location, uint16_t sensor1RawDistance,
uint16_t sensor2MinDistance, const char* sensor2Location, uint16_t sensor2RawDistance, uint16_t sensor2Distance,
@@ -138,9 +162,8 @@ void DisplayDevice::showValues(
if(BMP280_active == true)
showTemperatureValue(TemperaturValue);
}
-
+ handleShutdownDisplay();
m_display->updateDisplay();
-
}
void DisplayDevice::showGPS(uint8_t sats) {
diff --git a/src/displays.h b/src/displays.h
index 44af3885..85e2fe28 100644
--- a/src/displays.h
+++ b/src/displays.h
@@ -100,6 +100,7 @@ class DisplayDevice {
uint8_t scrollUp();
uint8_t startLine();
void highlight(uint32_t highlightTimeMillis = 500);
+ bool handleShutdownDisplay();
//##############################################################
// Basic display configuration
diff --git a/src/globals.h b/src/globals.h
index a9cb0e5d..6b727fb0 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -73,5 +73,6 @@ extern Gps gps;
extern const uint8_t LEFT_SENSOR_ID;
extern const uint8_t RIGHT_SENSOR_ID;
+extern const uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS;
#endif
diff --git a/src/utils/button.cpp b/src/utils/button.cpp
index 224e1db7..89eea713 100644
--- a/src/utils/button.cpp
+++ b/src/utils/button.cpp
@@ -31,11 +31,11 @@ Button::Button(int pin) : mPin(pin) {
mLastState = mLastRawState = read();
}
-void Button::handle() {
- handle(millis());
+bool Button::handle() {
+ return handle(millis());
}
-void Button::handle(unsigned long millis) {
+bool Button::handle(unsigned long millis) {
const int state = read();
if (state != mLastRawState) {
@@ -52,6 +52,7 @@ void Button::handle(unsigned long millis) {
mReleaseEvents++;
}
}
+ return state;
}
bool Button::gotPressed() {
diff --git a/src/utils/button.h b/src/utils/button.h
index e8201dd3..b206260b 100644
--- a/src/utils/button.h
+++ b/src/utils/button.h
@@ -28,8 +28,8 @@
class Button {
public:
explicit Button(int pin);
- void handle();
- void handle(unsigned long millis);
+ bool handle();
+ bool handle(unsigned long millis);
int read() const;
int getState() const;
bool gotPressed();