Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long press behaviour #279

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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