From 706ac17678055c12cfe369251c364f102152c3d5 Mon Sep 17 00:00:00 2001 From: nomakewan Date: Thu, 13 Nov 2025 12:30:05 -0800 Subject: [PATCH] Add isLongPressed function Adds isLongPressed function to return true if a push button has been long pressed and is still being actively held down. --- README.md | 6 +++++- keywords.txt | 1 + src/avdweb_Switch.cpp | 4 +++- src/avdweb_Switch.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d82beb3..85351c3 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,11 @@ It returns `true` if a push button was released (switched towards the off positi ### `longPress()` -It returns `true` if a push button is pressed longer than `300ms` (by default). Note that a `longPress()` always will be preceded by `pushed()` from the first push. +It returns `true` if a push button was pressed longer than `300ms` (by default). Note that a `longPress()` always will be preceded by `pushed()` from the first push. + +### `isLongPressed()` + +It returns `true` if the conditions for `longPress()` were true and the push button is still being held down. ### `doubleClick()` diff --git a/keywords.txt b/keywords.txt index 9b65f44..c19ba9f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -19,6 +19,7 @@ on KEYWORD2 pushed KEYWORD2 released KEYWORD2 longPress KEYWORD2 +isLongPressed KEYWORD2 doubleClick KEYWORD2 singleClick KEYWORD2 setPushedCallback KEYWORD2 diff --git a/src/avdweb_Switch.cpp b/src/avdweb_Switch.cpp index 91781e2..6019248 100644 --- a/src/avdweb_Switch.cpp +++ b/src/avdweb_Switch.cpp @@ -94,7 +94,7 @@ ******************************************************************************** ......................................DOUBLE CLICK.............................. - __________ ______ + __________ ______ debounced ________| |_______| |_____________________________ poll ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ @@ -264,6 +264,8 @@ bool Switch::released() { return _switched && (debounced ^ polarity); } bool Switch::longPress() { return _longPress; } +bool Switch::isLongPressed() { return longPressDisable; } + bool Switch::doubleClick() { return _doubleClick; } bool Switch::singleClick() { return _singleClick; } diff --git a/src/avdweb_Switch.h b/src/avdweb_Switch.h index 02e944c..d5b3743 100644 --- a/src/avdweb_Switch.h +++ b/src/avdweb_Switch.h @@ -55,6 +55,7 @@ class Switch { bool pushed(); // will be refreshed by poll() bool released(); // will be refreshed by poll() bool longPress(); // will be refreshed by poll() + bool isLongPressed(); // will be refreshed by poll() bool doubleClick(); // will be refreshed by poll() bool singleClick(); // will be refreshed by poll()