-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrdGuard.cpp
More file actions
38 lines (30 loc) · 1.01 KB
/
Copy pathdrdGuard.cpp
File metadata and controls
38 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "drdGuard.h"
#include <Arduino.h>
// Must be defined before the library include - selects SPIFFS (not EEPROM)
// as the double-reset flag storage. Keep this file the only place the
// library is included so the storage choice can never diverge between
// translation units.
#define ESP_DRD_USE_SPIFFS true
#include <ESP_DoubleResetDetector.h>
// Number of seconds after reset during which a subsequent reset will be
// considered a double reset.
#define DRD_TIMEOUT 10
// RTC Memory Address for the DoubleResetDetector to use
#define DRD_ADDRESS 0
static DoubleResetDetector *drd = nullptr;
bool drdSetupDetect()
{
if (!drd) drd = new DoubleResetDetector(DRD_TIMEOUT, DRD_ADDRESS);
return drd->detectDoubleReset();
}
void drdLoop()
{
if (drd) drd->loop();
}
[[noreturn]] void rebootCleanly(unsigned long delayMs)
{
if (drd) drd->stop(); // avoid the reboot registering as a double reset
if (delayMs) delay(delayMs);
ESP.restart();
for (;;) {} // unreachable - ESP.restart() does not return
}