9#if !defined(USE_RP2040) && !defined(USE_HOST)
12namespace factory_reset {
14static const char *
const TAG =
"factory_reset";
15static const uint32_t POWER_CYCLES_KEY = 0xFA5C0DE;
17static bool was_power_cycled() {
19 return esp_reset_reason() == ESP_RST_POWERON;
22 auto reset_reason = EspClass::getResetReason();
23 return strcasecmp(reset_reason.c_str(),
"power On") == 0 || strcasecmp(reset_reason.c_str(),
"external system") == 0;
26 auto reason = lt_get_reboot_reason();
27 return reason == REBOOT_REASON_POWER || reason == REBOOT_REASON_HARDWARE;
34 ESP_LOGCONFIG(TAG,
"Factory Reset by Reset:");
36 " Max interval between resets %" PRIu32
" seconds\n"
37 " Current count: %u\n"
38 " Factory reset after %u resets",
50 if (was_power_cycled()) {
56 ESP_LOGW(TAG,
"Reset count reached, factory resetting");
63 ESP_LOGD(TAG,
"Power on reset detected, incremented count to %u", count);
65 ESP_LOGD(TAG,
"No reset in the last %" PRIu32
" seconds, resetting count", this->
max_interval_ / 1000);
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
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
void IRAM_ATTR HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.