8static const char *
const TAG =
"duty_cycle";
19 LOG_SENSOR(
"",
"Duty Cycle Sensor",
this);
20 LOG_PIN(
" Pin: ", this->
pin_);
21 LOG_UPDATE_INTERVAL(
this);
24 const uint32_t now =
micros();
35 on_time += now - last_interrupt;
37 const float total_time = float(now - this->
last_update_);
39 const float value = (on_time * 100.0f) / total_time;
40 ESP_LOGD(TAG,
"'%s' Got duty cycle=%.1f%%", this->
get_name().c_str(), value);
53 const uint32_t now =
micros();
const StringRef & get_name() const
virtual bool digital_read()=0
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
virtual ISRInternalGPIOPin to_isr() const =0
float get_setup_priority() const override
DutyCycleSensorStore store_
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT micros()
Store data in a class that doesn't use multiple-inheritance (vtables in flash)
static void gpio_intr(DutyCycleSensorStore *arg)
volatile uint32_t last_interrupt
volatile uint32_t on_time