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;
|
const int16_t ingestInterval = 60;
|
||||||
int16_t ingestCountdown;
|
int16_t ingestCountdown;
|
||||||
|
|
||||||
|
const int watchdogTimeoutMicros = 40000000L;
|
||||||
|
hw_timer_t *watchdogTimer = NULL;
|
||||||
|
|
||||||
void pulse();
|
void pulse();
|
||||||
uint32_t calcRemainingWait();
|
uint32_t calcRemainingWait();
|
||||||
boolean wifiSwitchOn();
|
boolean wifiSwitchOn();
|
||||||
uint16_t takeSampleNoSleep();
|
uint16_t takeSampleNoSleep();
|
||||||
uint16_t takeSampleLowPower();
|
uint16_t takeSampleLowPower();
|
||||||
|
void IRAM_ATTR watchdogExpired();
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(921600);
|
Serial.begin(921600);
|
||||||
Serial.println("Starting!");
|
Serial.println("Starting!");
|
||||||
|
|
||||||
|
// initialize watchdog timer
|
||||||
|
watchdogTimer = timerBegin(0, 80, true);
|
||||||
|
timerAttachInterrupt(watchdogTimer, &watchdogExpired, true);
|
||||||
|
timerAlarmWrite(watchdogTimer, watchdogTimeoutMicros, false);
|
||||||
|
timerAlarmEnable(watchdogTimer);
|
||||||
|
|
||||||
// OLED
|
// OLED
|
||||||
initDisplay();
|
initDisplay();
|
||||||
|
|
||||||
@@ -55,7 +65,6 @@ void setup()
|
|||||||
|
|
||||||
// WiFi switch input
|
// WiFi switch input
|
||||||
pinMode(WIFI_SWITCH_PIN, INPUT_PULLUP);
|
pinMode(WIFI_SWITCH_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
if (wifiSwitchOn())
|
if (wifiSwitchOn())
|
||||||
{
|
{
|
||||||
initIngest();
|
initIngest();
|
||||||
@@ -68,12 +77,14 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
// blinky
|
// blinky
|
||||||
|
|
||||||
digitalWrite(LED_BUILTIN, blinky);
|
digitalWrite(LED_BUILTIN, blinky);
|
||||||
blinky = !blinky;
|
blinky = !blinky;
|
||||||
|
|
||||||
|
// reset watchdog
|
||||||
|
timerWrite(watchdogTimer, 0);
|
||||||
|
|
||||||
const uint16_t pulses =
|
const uint16_t pulses =
|
||||||
wifiSwitchOn() ? takeSampleNoSleep() : takeSampleLowPower();
|
wifiSwitchOn() ? takeSampleNoSleep() : takeSampleLowPower();
|
||||||
|
|
||||||
@@ -221,3 +232,8 @@ uint16_t takeSampleLowPower()
|
|||||||
|
|
||||||
return pulses;
|
return pulses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR watchdogExpired()
|
||||||
|
{
|
||||||
|
esp_restart();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user