ESPHome 2025.5.0
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
4namespace esphome {
5namespace pulse_width {
6
7static const char *const TAG = "pulse_width";
8
10 const bool new_level = arg->pin_.digital_read();
11 const uint32_t now = micros();
12 if (new_level) {
13 arg->last_rise_ = now;
14 } else {
15 arg->last_width_ = (now - arg->last_rise_);
16 }
17}
18
20 LOG_SENSOR("", "Pulse Width", this)
21 LOG_UPDATE_INTERVAL(this)
22 LOG_PIN(" Pin: ", this->pin_);
23}
25 float width = this->store_.get_pulse_width_s();
26 ESP_LOGCONFIG(TAG, "'%s' - Got pulse width %.3f s", this->name_.c_str(), width);
27 this->publish_state(width);
28}
29
30} // namespace pulse_width
31} // namespace esphome
constexpr const char * c_str() const
Definition string_ref.h:68
Store data in a class that doesn't use multiple-inheritance (vtables in flash)
Definition pulse_width.h:11
static void gpio_intr(PulseWidthSensorStore *arg)
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:29