9#if !defined(USE_RP2040) && !defined(USE_HOST)
13static const char *
const TAG =
"factory_reset";
14static const uint32_t POWER_CYCLES_KEY = 0xFA5C0DE;
16static bool was_power_cycled() {
18 return esp_reset_reason() == ESP_RST_POWERON;
21 auto reset_reason = EspClass::getResetReason();
22 return strcasecmp(reset_reason.c_str(),
"power On") == 0 || strcasecmp(reset_reason.c_str(),
"external system") == 0;
25 auto reason = lt_get_reboot_reason();
26 return reason == REBOOT_REASON_POWER || reason == REBOOT_REASON_HARDWARE;
33 ESP_LOGCONFIG(TAG,
"Factory Reset by Reset:");
35 " Max interval between resets: %u seconds\n"
36 " Current count: %u\n"
37 " Factory reset after %u resets",
49 if (was_power_cycled()) {
55 ESP_LOGW(TAG,
"Reset count reached, factory resetting");
62 ESP_LOGD(TAG,
"Power on reset detected, incremented count to %u", count);
64 ESP_LOGD(TAG,
"No reset in the last %u seconds, resetting count", this->
max_interval_);
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual bool sync()=0
Commit pending writes to flash.
virtual bool reset()=0
Forget all unsaved changes and re-initialize the permanent preferences storage.
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
CallbackManager< void(uint8_t, uint8_t)> increment_callback_
ESPPreferenceObject flash_
void save_(uint8_t count)
void dump_config() override
ESPPreferences * global_preferences
void IRAM_ATTR HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.