From 7d997ed5430fdaf8187e076f5462c5f58414e8eb Mon Sep 17 00:00:00 2001 From: Victus Date: Mon, 11 May 2026 00:39:26 +0200 Subject: [PATCH] Naprawa isPressed() - dodanie wykrywania zbocza opadajacego, co rozwiazuje problem wielokrotnego wyzwalania akcji przy przytrzymaniu --- include/Settings.h | 4 ++++ src/Settings.cpp | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/Settings.h b/include/Settings.h index 0653c68..37362bd 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -47,6 +47,10 @@ private: void constrainValue(int &value, int minVal, int maxVal); void printField(const char *label, int value); + bool lastState1_ = true; + bool lastState2_ = true; + bool lastState3_ = true; + }; #endif diff --git a/src/Settings.cpp b/src/Settings.cpp index 82fc781..74af30e 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -13,15 +13,28 @@ void Settings::begin() { pinMode(BTN_DOWN, INPUT_PULLUP); } -// Zwraca true, jeśli przycisk jest wciśnięty +// Zwraca true, jeśli przycisk został WŁAŚNIE wciśnięty (zbocze opadające) bool Settings::isPressed(uint8_t btnIndex) { - //ESP_LOGI(TAG_SETTINGS, "BTN check"); + bool currentState, isNewlyPressed = false; switch (btnIndex) { - case 1: return digitalRead(BTN_UP) == LOW; - case 2: return digitalRead(BTN_OK) == LOW; - case 3: return digitalRead(BTN_DOWN) == LOW; + case 1: + currentState = digitalRead(BTN_UP); + isNewlyPressed = (currentState == LOW && lastState1_ == HIGH); + lastState1_ = currentState; + break; + case 2: + currentState = digitalRead(BTN_OK); + isNewlyPressed = (currentState == LOW && lastState2_ == HIGH); + lastState2_ = currentState; + break; + case 3: + currentState = digitalRead(BTN_DOWN); + isNewlyPressed = (currentState == LOW && lastState3_ == HIGH); + lastState3_ = currentState; + break; default: return false; } + return isNewlyPressed; } // Kombinacja 1 i 3 jednocześnie