ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
pulse_width.cpp
Go to the documentation of this file.
1#include "pulse_width.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "pulse_width");
7
9 const bool new_level = arg->pin_.digital_read();
10 const uint32_t now = micros();
11 if (new_level) {
12 arg->last_rise_ = now;
13 } else {
14 arg->last_width_ = (now - arg->last_rise_);
15 }
16}
17
19 LOG_SENSOR("", "Pulse Width", this);
20 LOG_UPDATE_INTERVAL(this);
21 LOG_PIN(" Pin: ", this->pin_);
22}
24 float width = this->store_.get_pulse_width_s();
25 ESP_LOGCONFIG(TAG, "'%s' - Got pulse width %.3f s", LOG_STR_ARG(this->get_log_name()), width);
26 this->publish_state(width);
27}
28
29} // namespace esphome::pulse_width
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
Store data in a class that doesn't use multiple-inheritance (vtables in flash)
Definition pulse_width.h:10
static void gpio_intr(PulseWidthSensorStore *arg)
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
ESPHOME_LOG_TAG(TAG, "pulse_width")
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
static void uint32_t