ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
status_led.cpp
Go to the documentation of this file.
1#include "status_led.h"
2#include "esphome/core/log.h"
4
5namespace esphome {
6namespace status_led {
7
8static const char *const TAG = "status_led";
9
10static constexpr uint32_t ERROR_PERIOD_MS = 250;
11static constexpr uint32_t ERROR_ON_MS = 150;
12static constexpr uint32_t WARNING_PERIOD_MS = 1500;
13static constexpr uint32_t WARNING_ON_MS = 250;
14
15StatusLED *global_status_led = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
16
17StatusLED::StatusLED(GPIOPin *pin) : pin_(pin) { global_status_led = this; }
19 this->pin_->setup();
20 this->pin_->digital_write(false);
21}
23 ESP_LOGCONFIG(TAG, "Status LED:");
24 LOG_PIN(" Pin: ", this->pin_);
25}
27 const uint32_t app_state = App.get_app_state();
28 // Use millis() rather than App.get_loop_component_start_time() because this loop is also
29 // dispatched from Application::feed_wdt() during long blocking operations, where the cached
30 // per-component timestamp doesn't advance and would freeze the blink pattern.
31 const uint32_t now = millis();
32 if ((app_state & STATUS_LED_ERROR) != 0u) {
33 this->pin_->digital_write(now % ERROR_PERIOD_MS < ERROR_ON_MS);
34 } else if ((app_state & STATUS_LED_WARNING) != 0u) {
35 this->pin_->digital_write(now % WARNING_PERIOD_MS < WARNING_ON_MS);
36 } else {
37 this->pin_->digital_write(false);
38 this->disable_loop();
39 }
40}
42
43} // namespace status_led
44} // namespace esphome
uint8_t get_app_state() const
Return the public app state status bits (STATUS_LED_* only).
void disable_loop()
Disable this component's loop.
virtual void setup()=0
virtual void digital_write(bool value)=0
float get_setup_priority() const override
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:40
const char *const TAG
Definition spi.cpp:7
StatusLED * global_status_led
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr uint8_t STATUS_LED_WARNING
Definition component.h:88
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:26
Application App
Global storage of Application pointer - only one Application can exist.
constexpr uint8_t STATUS_LED_ERROR
Definition component.h:89
static void uint32_t