ESPHome  2022.11.3
status_led.cpp
Go to the documentation of this file.
1 #include "status_led.h"
2 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace status_led {
7 
8 static const char *const TAG = "status_led";
9 
10 StatusLED *global_status_led = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
11 
12 StatusLED::StatusLED(GPIOPin *pin) : pin_(pin) { global_status_led = this; }
14  ESP_LOGCONFIG(TAG, "Setting up Status LED...");
15  this->pin_->setup();
16  this->pin_->digital_write(false);
17 }
19  ESP_LOGCONFIG(TAG, "Status LED:");
20  LOG_PIN(" Pin: ", this->pin_);
21 }
23  if ((App.get_app_state() & STATUS_LED_ERROR) != 0u) {
24  this->pin_->digital_write(millis() % 250u < 150u);
25  } else if ((App.get_app_state() & STATUS_LED_WARNING) != 0u) {
26  this->pin_->digital_write(millis() % 1500u < 250u);
27  } else {
28  this->pin_->digital_write(false);
29  }
30 }
32 float StatusLED::get_loop_priority() const { return 50.0f; }
33 
34 } // namespace status_led
35 } // namespace esphome
virtual void digital_write(bool value)=0
float get_loop_priority() const override
Definition: status_led.cpp:32
virtual void setup()=0
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:26
Application App
Global storage of Application pointer - only one Application can exist.
float get_setup_priority() const override
Definition: status_led.cpp:31
const uint32_t STATUS_LED_WARNING
Definition: component.cpp:38
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition: component.cpp:17
StatusLED * global_status_led
Definition: status_led.cpp:10
const uint32_t STATUS_LED_ERROR
Definition: component.cpp:39
uint32_t get_app_state() const
Definition: application.h:166
Definition: a4988.cpp:4