12static const char *
const TAG =
"app";
15 if (comp ==
nullptr) {
16 ESP_LOGW(TAG,
"Tried to register null component!");
22 ESP_LOGW(TAG,
"Component %s already registered! (%p)", c->get_component_source(), c);
26 this->components_.push_back(comp);
29 ESP_LOGI(TAG,
"Running through setup()...");
30 ESP_LOGV(TAG,
"Sorting components by setup priority...");
32 return a->get_actual_setup_priority() > b->get_actual_setup_priority();
35 for (uint32_t i = 0; i < this->
components_.size(); i++) {
46 std::stable_sort(this->
components_.begin(), this->components_.begin() + i + 1,
47 [](
Component *a,
Component *b) { return a->get_loop_priority() > b->get_loop_priority(); });
53 for (uint32_t j = 0; j <= i; j++) {
57 new_app_state |= this->
components_[j]->get_component_state();
66 ESP_LOGI(TAG,
"setup() finished successfully!");
71 uint32_t new_app_state = 0;
76 uint32_t last_op_end_time =
millis();
90 last_op_end_time = guard.
finish();
92 new_app_state |= component->get_component_state();
99 auto elapsed = last_op_end_time - this->
last_loop_;
107 next_schedule = std::max(next_schedule, delay_time / 2);
108 delay_time = std::min(next_schedule, delay_time);
111 this->last_loop_ = last_op_end_time;
115 ESP_LOGI(TAG,
"ESPHome version " ESPHOME_VERSION
" compiled on %s", this->
compilation_time_);
116#ifdef ESPHOME_PROJECT_NAME
117 ESP_LOGI(TAG,
"Project " ESPHOME_PROJECT_NAME
" version " ESPHOME_PROJECT_VERSION);
127 static uint32_t last_feed = 0;
129 uint32_t now = time ? time :
millis();
131 if (now - last_feed > 3) {
142 ESP_LOGI(TAG,
"Forcing a reboot...");
143 for (
auto it = this->
components_.rbegin(); it != this->components_.rend(); ++it) {
144 (*it)->on_shutdown();
149 ESP_LOGI(TAG,
"Rebooting safely...");
155 for (
auto it = this->
components_.rbegin(); it != this->components_.rend(); ++it) {
156 (*it)->on_safe_shutdown();
158 for (
auto it = this->
components_.rbegin(); it != this->components_.rend(); ++it) {
159 (*it)->on_shutdown();
165 if (obj->has_overridden_loop())
void setup()
Set up all the registered components. Call this at the end of your setup() function.
void set_current_component(Component *component)
std::vector< Component * > components_
uint32_t loop_component_start_time_
const char * compilation_time_
std::vector< Component * > looping_components_
void schedule_dump_config()
void run_safe_shutdown_hooks()
void feed_wdt(uint32_t time=0)
void loop()
Make a loop iteration. Call this in your loop() function.
void calculate_looping_components_()
void register_component_(Component *comp)
virtual bool can_proceed()
static bool is_high_frequency()
Check whether the loop is running continuously.
optional< uint32_t > next_schedule_in()
value_type value_or(U const &v) const
StatusLED * global_status_led
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT yield()
void IRAM_ATTR HOT arch_feed_wdt()
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
const uint32_t STATUS_LED_WARNING