From 053f8db06bc990ff78e93f930e45e523c0d33ee8 Mon Sep 17 00:00:00 2001 From: Joe <1015.5@gmx.de> Date: Fri, 8 Dec 2023 11:54:39 +0100 Subject: [PATCH 1/2] execute cmd directly after longpress-time --- src/Button.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Button.cpp b/src/Button.cpp index 7680a991..b5d5a225 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -305,18 +305,19 @@ void Button_DoButtonActions(void) { break; } - if (gButtons[i].lastReleasedTimestamp > gButtons[i].lastPressedTimestamp) { + if (gButtons[i].lastReleasedTimestamp > gButtons[i].lastPressedTimestamp) { // short action if (gButtons[i].lastReleasedTimestamp - gButtons[i].lastPressedTimestamp < intervalToLongPress) { Cmd_Action(Cmd_Short); } else { - // if not volume buttons than start action after button release - if (Cmd_Long != CMD_VOLUMEUP && Cmd_Long != CMD_VOLUMEDOWN) { + // sleep-mode should only be triggered on release, otherwise it will wake it up directly again + if (Cmd_Long == CMD_SLEEPMODE) { Cmd_Action(Cmd_Long); } } gButtons[i].isPressed = false; - } else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) { + + } else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) { // volume-buttons unsigned long currentTimestamp = millis(); // only start action if intervalToLongPress has been reached @@ -332,6 +333,15 @@ void Button_DoButtonActions(void) { gLongPressTime = remainder; } + + } else if (Cmd_Long != CMD_SLEEPMODE) { // long action, if not sleep-mode + unsigned long currentTimestamp = millis(); + + // start action if intervalToLongPress has been reached + if ((currentTimestamp - gButtons[i].lastPressedTimestamp) > intervalToLongPress) { + gButtons[i].isPressed = false; + Cmd_Action(Cmd_Long); + } } } } From 5e866aac6c0923fb9b52c0f9195d322be3875e78 Mon Sep 17 00:00:00 2001 From: Joe <1015.5@gmx.de> Date: Sun, 10 Dec 2023 21:29:26 +0100 Subject: [PATCH 2/2] only call millis() once --- src/Button.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Button.cpp b/src/Button.cpp index b5d5a225..49469c24 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -268,6 +268,7 @@ void Button_DoButtonActions(void) { gButtons[5].isPressed = false; Cmd_Action(BUTTON_MULTI_45); } else { + unsigned long currentTimestamp = millis(); for (uint8_t i = 0; i <= 5; i++) { if (gButtons[i].isPressed) { uint8_t Cmd_Short = 0; @@ -318,8 +319,6 @@ void Button_DoButtonActions(void) { gButtons[i].isPressed = false; } else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) { // volume-buttons - unsigned long currentTimestamp = millis(); - // only start action if intervalToLongPress has been reached if (currentTimestamp - gButtons[i].lastPressedTimestamp > intervalToLongPress) { @@ -335,8 +334,6 @@ void Button_DoButtonActions(void) { } } else if (Cmd_Long != CMD_SLEEPMODE) { // long action, if not sleep-mode - unsigned long currentTimestamp = millis(); - // start action if intervalToLongPress has been reached if ((currentTimestamp - gButtons[i].lastPressedTimestamp) > intervalToLongPress) { gButtons[i].isPressed = false;