ESPHome  2024.10.2
safe_mode.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 #include "esphome/core/helpers.h"
7 
8 namespace esphome {
9 namespace safe_mode {
10 
12 class SafeModeComponent : public Component {
13  public:
14  bool should_enter_safe_mode(uint8_t num_attempts, uint32_t enable_time, uint32_t boot_is_good_after);
15 
17  void set_safe_mode_pending(const bool &pending);
18  bool get_safe_mode_pending();
19 
20  void dump_config() override;
21  float get_setup_priority() const override;
22  void loop() override;
23 
24  void clean_rtc();
25 
26  void on_safe_shutdown() override;
27 
28  void add_on_safe_mode_callback(std::function<void()> &&callback) {
29  this->safe_mode_callback_.add(std::move(callback));
30  }
31 
32  protected:
33  void write_rtc_(uint32_t val);
34  uint32_t read_rtc_();
35 
36  bool boot_successful_{false};
38  uint32_t safe_mode_enable_time_{60000};
39  uint32_t safe_mode_rtc_value_{0};
40  uint32_t safe_mode_start_time_{0};
44 
45  static const uint32_t ENTER_SAFE_MODE_MAGIC =
46  0x5afe5afe;
47 };
48 
49 } // namespace safe_mode
50 } // namespace esphome
static const uint32_t ENTER_SAFE_MODE_MAGIC
a magic number to indicate that safe mode should be entered on next boot
Definition: safe_mode.h:45
void set_safe_mode_pending(const bool &pending)
Set to true if the next startup will enter safe mode.
Definition: safe_mode.cpp:47
uint32_t safe_mode_boot_is_good_after_
The amount of time after which the boot is considered successful.
Definition: safe_mode.h:37
CallbackManager< void()> safe_mode_callback_
Definition: safe_mode.h:43
mopeka_std_values val[4]
uint32_t safe_mode_start_time_
stores when safe mode was enabled
Definition: safe_mode.h:40
void add_on_safe_mode_callback(std::function< void()> &&callback)
Definition: safe_mode.h:28
bool should_enter_safe_mode(uint8_t num_attempts, uint32_t enable_time, uint32_t boot_is_good_after)
Definition: safe_mode.cpp:65
float get_setup_priority() const override
Definition: safe_mode.cpp:36
bool boot_successful_
set to true after boot is considered successful
Definition: safe_mode.h:36
uint32_t safe_mode_enable_time_
The time safe mode should remain active for.
Definition: safe_mode.h:38
SafeModeComponent provides a safe way to recover from repeated boot failures.
Definition: safe_mode.h:12
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7