@@ -103,7 +103,7 @@ CircularBuffer<DataSet*, 10> dataBuffer;
103
103
FileWriter* writer;
104
104
105
105
const uint8_t displayAddress = 0x3c ;
106
-
106
+ const uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS = 10000 ;
107
107
108
108
// Enable dev-mode. Allows to
109
109
// - set wifi config
@@ -233,35 +233,26 @@ static uint8_t shutdownState = 0;
233
233
// Power-management keep alive timer
234
234
// This function is called every 100 ms
235
235
static unsigned long timeOfLastPowerKeepAlive = 0 ;
236
- static uint8_t buttonPressedCounter = 0 ;
237
236
static void powerKeepAliveTimerISR ()
238
237
{
239
238
// Send "keep alive" trigger to power management module
240
239
// This is done by toggling the pin every 300 ms or more
241
240
if (shutdownState == 0 )
242
241
{
243
- if (!digitalRead (IP5306_BUTTON) && millis () - timeOfLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
242
+ unsigned long timeSinceLastPowerKeepAlive = millis () - timeOfLastPowerKeepAlive;
243
+ if (!digitalRead (IP5306_BUTTON) && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
244
244
{
245
245
timeOfLastPowerKeepAlive = millis ();
246
246
digitalWrite (IP5306_BUTTON, HIGH);
247
247
}
248
- else if (digitalRead (IP5306_BUTTON) && millis () - timeOfLastPowerKeepAlive > 300 )
248
+ else if (digitalRead (IP5306_BUTTON) && timeSinceLastPowerKeepAlive > 300 )
249
249
{
250
250
timeOfLastPowerKeepAlive = millis ();
251
251
digitalWrite (IP5306_BUTTON, LOW);
252
252
}
253
253
}
254
254
255
- // Soft power-off OBSPro when button is pressed for more than 10 seconds
256
- if (button.read ())
257
- {
258
- if (buttonPressedCounter < 255 )
259
- buttonPressedCounter++;
260
- }
261
- else
262
- buttonPressedCounter = 0 ;
263
-
264
- if (shutdownState == 0 && buttonPressedCounter >= 100 ) {
255
+ if (shutdownState == 0 && button.read () && button.getCurrentStateMillis () >= BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS) {
265
256
shutdownState = 1 ;
266
257
}
267
258
switch (shutdownState)
0 commit comments