ESPHome 2026.2.1
Loading...
Searching...
No Matches
pulse_counter_sensor.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7#include <cinttypes>
8
9#if defined(USE_ESP32)
10#include <soc/soc_caps.h>
11#if defined(SOC_PCNT_SUPPORTED) && __has_include(<driver/pulse_cnt.h>)
12#include <driver/pulse_cnt.h>
13#define HAS_PCNT
14#endif // defined(SOC_PCNT_SUPPORTED) && __has_include(<driver/pulse_cnt.h>)
15#endif // USE_ESP32
16
17namespace esphome {
18namespace pulse_counter {
19
25
26using pulse_counter_t = int32_t;
27
38
50
51#ifdef HAS_PCNT
55
56 pcnt_unit_handle_t pcnt_unit{nullptr};
57 pcnt_channel_handle_t pcnt_channel{nullptr};
58};
59#endif // HAS_PCNT
60
61PulseCounterStorageBase *get_storage(bool hw_pcnt = false);
62
64 public:
65 explicit PulseCounterSensor(bool hw_pcnt = false) : storage_(*get_storage(hw_pcnt)) {}
66
67 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
70 void set_filter_us(uint32_t filter) { storage_.filter_us = filter; }
71 void set_total_sensor(sensor::Sensor *total_sensor) { total_sensor_ = total_sensor; }
72
73 void set_total_pulses(uint32_t pulses);
74
76 void setup() override;
77 void update() override;
78 void dump_config() override;
79
80 protected:
83 uint32_t last_time_{0};
84 uint32_t current_total_{0};
86};
87
88} // namespace pulse_counter
89} // namespace esphome
BedjetMode mode
BedJet operating mode.
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:92
This class simplifies creating components that periodically check a state.
Definition component.h:512
void setup() override
Unit of measurement is "pulses/min".
void set_total_sensor(sensor::Sensor *total_sensor)
void set_falling_edge_mode(PulseCounterCountMode mode)
void set_rising_edge_mode(PulseCounterCountMode mode)
Base-class for all sensors.
Definition sensor.h:43
PulseCounterStorageBase * get_storage(bool hw_pcnt)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
bool pulse_counter_setup(InternalGPIOPin *pin) override
static void gpio_intr(BasicPulseCounterStorage *arg)
bool pulse_counter_setup(InternalGPIOPin *pin) override
virtual pulse_counter_t read_raw_value()=0
virtual bool pulse_counter_setup(InternalGPIOPin *pin)=0