mirror of
https://github.com/grillbaer/esp32-geiger-counter.git
synced 2025-12-21 13:23:15 +01:00
added watchdog to break any hangs
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@@ -33,17 +33,27 @@ uint32_t sampleStart = 0;
|
||||
const int16_t ingestInterval = 60;
|
||||
int16_t ingestCountdown;
|
||||
|
||||
const int watchdogTimeoutMicros = 40000000L;
|
||||
hw_timer_t *watchdogTimer = NULL;
|
||||
|
||||
void pulse();
|
||||
uint32_t calcRemainingWait();
|
||||
boolean wifiSwitchOn();
|
||||
uint16_t takeSampleNoSleep();
|
||||
uint16_t takeSampleLowPower();
|
||||
void IRAM_ATTR watchdogExpired();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(921600);
|
||||
Serial.println("Starting!");
|
||||
|
||||
// initialize watchdog timer
|
||||
watchdogTimer = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(watchdogTimer, &watchdogExpired, true);
|
||||
timerAlarmWrite(watchdogTimer, watchdogTimeoutMicros, false);
|
||||
timerAlarmEnable(watchdogTimer);
|
||||
|
||||
// OLED
|
||||
initDisplay();
|
||||
|
||||
@@ -55,7 +65,6 @@ void setup()
|
||||
|
||||
// WiFi switch input
|
||||
pinMode(WIFI_SWITCH_PIN, INPUT_PULLUP);
|
||||
|
||||
if (wifiSwitchOn())
|
||||
{
|
||||
initIngest();
|
||||
@@ -68,12 +77,14 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// blinky
|
||||
|
||||
digitalWrite(LED_BUILTIN, blinky);
|
||||
blinky = !blinky;
|
||||
|
||||
// reset watchdog
|
||||
timerWrite(watchdogTimer, 0);
|
||||
|
||||
const uint16_t pulses =
|
||||
wifiSwitchOn() ? takeSampleNoSleep() : takeSampleLowPower();
|
||||
|
||||
@@ -221,3 +232,8 @@ uint16_t takeSampleLowPower()
|
||||
|
||||
return pulses;
|
||||
}
|
||||
|
||||
void IRAM_ATTR watchdogExpired()
|
||||
{
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user