ESPHome 2025.5.0
Loading...
Searching...
No Matches
pulse_width.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome {
8namespace pulse_width {
9
12 public:
14 pin->setup();
15 this->pin_ = pin->to_isr();
16 this->last_rise_ = micros();
18 }
19 static void gpio_intr(PulseWidthSensorStore *arg);
20 uint32_t get_pulse_width_us() const { return this->last_width_; }
21 float get_pulse_width_s() const { return this->last_width_ / 1e6f; }
22 uint32_t get_last_rise() const { return last_rise_; }
23
24 protected:
26 volatile uint32_t last_width_{0};
27 volatile uint32_t last_rise_{0};
28};
29
31 public:
32 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
33 void setup() override { this->store_.setup(this->pin_); }
34 void dump_config() override;
35 float get_setup_priority() const override { return setup_priority::DATA; }
36 void update() override;
37
38 protected:
41};
42
43} // namespace pulse_width
44} // namespace esphome
virtual void setup()=0
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:73
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
Definition gpio.h:88
virtual ISRInternalGPIOPin to_isr() const =0
This class simplifies creating components that periodically check a state.
Definition component.h:301
void set_pin(InternalGPIOPin *pin)
Definition pulse_width.h:32
float get_setup_priority() const override
Definition pulse_width.h:35
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)
Base-class for all sensors.
Definition sensor.h:57
@ INTERRUPT_ANY_EDGE
Definition gpio.h:43
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
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