Skip to content

Commit

Permalink
Long press behaviour, execute cmd directly after longpress-time (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe91 authored Dec 12, 2023
1 parent 3af356b commit 2234bca
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,20 +306,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) {
unsigned long currentTimestamp = millis();

} else if (Cmd_Long == CMD_VOLUMEUP || Cmd_Long == CMD_VOLUMEDOWN) { // volume-buttons
// only start action if intervalToLongPress has been reached
if (currentTimestamp - gButtons[i].lastPressedTimestamp > intervalToLongPress) {

Expand All @@ -332,6 +332,13 @@ void Button_DoButtonActions(void) {

gLongPressTime = remainder;
}

} else if (Cmd_Long != CMD_SLEEPMODE) { // long action, if not sleep-mode
// start action if intervalToLongPress has been reached
if ((currentTimestamp - gButtons[i].lastPressedTimestamp) > intervalToLongPress) {
gButtons[i].isPressed = false;
Cmd_Action(Cmd_Long);
}
}
}
}
Expand Down

0 comments on commit 2234bca

Please sign in to comment.