ESPHome 2026.5.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::pulse_counter {
18
24
25using pulse_counter_t = int32_t;
26
37
49
50#ifdef HAS_PCNT
54
55 pcnt_unit_handle_t pcnt_unit{nullptr};
56 pcnt_channel_handle_t pcnt_channel{nullptr};
57};
58#endif // HAS_PCNT
59
60PulseCounterStorageBase *get_storage(bool hw_pcnt = false);
61
63 public:
64 explicit PulseCounterSensor(bool hw_pcnt = false) : storage_(*get_storage(hw_pcnt)) {}
65
66 void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
69 void set_filter_us(uint32_t filter) { storage_.filter_us = filter; }
70 void set_total_sensor(sensor::Sensor *total_sensor) { total_sensor_ = total_sensor; }
71
72 void set_total_pulses(uint32_t pulses);
73
75 void setup() override;
76 void update() override;
77 void dump_config() override;
78
79 protected:
85};
86
87} // namespace esphome::pulse_counter
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:602
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:47
PulseCounterStorageBase * get_storage(bool hw_pcnt)
static void uint32_t
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