From 7cd5bad1c273862b8407ada80fea4502d4d372af Mon Sep 17 00:00:00 2001 From: brisk Date: Sat, 13 Jul 2024 18:29:04 +0930 Subject: [PATCH] pulse_counter_ulp: only read valid bits of ulp_edge_count --- .../components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp | 3 ++- .../components/pulse_counter_ulp/pulse_counter_ulp_sensor.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp index 618671edba..9dbd67437c 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -64,6 +64,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { * * Note that the ULP reads only the lower 16 bits of these variables. */ + ulp_edge_count = 0; ulp_debounce_counter = 3; ulp_debounce_max_count = 3; ulp_next_edge = 0; @@ -91,7 +92,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { pulse_counter_t UlpPulseCounterStorage::read_raw_value() { // TODO count edges separately - uint32_t count = ulp_edge_count; + auto count = static_cast(ulp_edge_count); ulp_edge_count = 0; return count; } diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h index 9f75540b7e..e8d59d9474 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h @@ -15,7 +15,7 @@ namespace pulse_counter_ulp { enum class CountMode { disable = 0, increment = 1, decrement = -1 }; -using pulse_counter_t = int32_t; +using pulse_counter_t = int16_t; using timestamp_t = int64_t; struct UlpPulseCounterStorage {