8 static const char *
const TAG =
"duty_cycle";
11 ESP_LOGCONFIG(TAG,
"Setting up Duty Cycle Sensor '%s'...", this->
get_name().c_str());
20 LOG_SENSOR(
"",
"Duty Cycle Sensor",
this);
21 LOG_PIN(
" Pin: ", this->
pin_);
22 LOG_UPDATE_INTERVAL(
this);
25 const uint32_t now =
micros();
36 on_time += now - last_interrupt;
38 const float total_time = float(now - this->
last_update_);
40 const float value = (on_time * 100.0f) / total_time;
41 ESP_LOGD(TAG,
"'%s' Got duty cycle=%.1f%%", this->
get_name().c_str(), value);
54 const uint32_t now =
micros();
DutyCycleSensorStore store_
const float DATA
For components that import data from directly connected sensors like DHT.
Store data in a class that doesn't use multiple-inheritance (vtables in flash)
uint32_t IRAM_ATTR HOT micros()
volatile uint32_t on_time
void dump_config() override
float get_setup_priority() const override
static void gpio_intr(DutyCycleSensorStore *arg)
void publish_state(float state)
Publish a new state to the front-end.
virtual bool digital_read()=0
virtual ISRInternalGPIOPin to_isr() const =0
volatile uint32_t last_interrupt
Implementation of SPI Controller mode.
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
const StringRef & get_name() const