From 1404073053f6f9e16a11eeb4350e59c485d3325a Mon Sep 17 00:00:00 2001 From: Zhaoqi Xu Date: Thu, 15 Oct 2026 09:02:48 +0800 Subject: [PATCH] Fix isLongPressed() during longPressStart callback Enter OCS_PRESS before invoking longPressStart so isLongPressed() returns true inside the callback. Same ordering in OneButtonTiny. Fixes #165 --- src/OneButton.cpp | 2 +- src/OneButtonTiny.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OneButton.cpp b/src/OneButton.cpp index 20ea529..17aa967 100644 --- a/src/OneButton.cpp +++ b/src/OneButton.cpp @@ -269,9 +269,9 @@ void OneButton::_fsm(bool activeLevel) { _startTime = now; // remember starting time } else if (waitTime > _press_ms) { + _newState(OneButton::OCS_PRESS); if (_longPressStartFunc) _longPressStartFunc(); if (_paramLongPressStartFunc) _paramLongPressStartFunc(_longPressStartFuncParam); - _newState(OneButton::OCS_PRESS); } // if break; diff --git a/src/OneButtonTiny.cpp b/src/OneButtonTiny.cpp index 88da31f..50108d9 100644 --- a/src/OneButtonTiny.cpp +++ b/src/OneButtonTiny.cpp @@ -157,8 +157,8 @@ void OneButtonTiny::_fsm(bool activeLevel) { _startTime = now; // remember starting time } else if ((activeLevel) && (waitTime > _press_ms)) { - if (_longPressStartFunc) _longPressStartFunc(); _newState(OneButtonTiny::OCS_PRESS); + if (_longPressStartFunc) _longPressStartFunc(); } // if break;