ESPHome 2026.6.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
6static const char *const 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", this->name_.c_str(), width);
26 this->publish_state(width);
27}
28
29} // namespace esphome::pulse_width
constexpr const char * c_str() const
Definition string_ref.h:73
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:68
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
static void uint32_t