Return button action instead of pushing messages

This commit is contained in:
Riku Isokoski
2021-10-25 16:57:29 +03:00
parent b19a2a760b
commit 351c60a131
6 changed files with 66 additions and 50 deletions

View File

@@ -335,33 +335,25 @@ void SystemTask::Work() {
ReloadIdleTimer();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TouchEvent);
break;
case Messages::OnButtonPushed:
if (!isSleeping && !isGoingToSleep) {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonPushed);
case Messages::HandleButtonEvent: {
// This is for faster wakeup, sacrificing special longpress and doubleclick handling while sleeping
if (IsSleeping()) {
GoToRunning();
break;
}
break;
case Messages::OnButtonLongPressed:
if (!isSleeping) {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongPressed);
}
break;
case Messages::OnButtonLongerPressed:
if (!isSleeping) {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonLongerPressed);
}
break;
case Messages::OnButtonDoubleClicked:
if (!isSleeping) {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ButtonDoubleClicked);
}
break;
case Messages::HandleButtonEvent:
Controllers::ButtonActions action;
if (nrf_gpio_pin_read(Pinetime::PinMap::Button) == 0) {
buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Release);
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Release);
} else {
buttonHandler.HandleEvent(Pinetime::Controllers::ButtonHandler::Events::Press);
action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Press);
}
break;
HandleButtonAction(action);
} break;
case Messages::HandleButtonTimerEvent: {
auto action = buttonHandler.HandleEvent(Controllers::ButtonHandler::Events::Timer);
HandleButtonAction(action);
} break;
case Messages::OnDisplayTaskSleeping:
if (BootloaderVersion::IsValid()) {
// First versions of the bootloader do not expose their version and cannot initialize the SPI NOR FLASH
@@ -398,9 +390,6 @@ void SystemTask::Work() {
case Messages::BatteryPercentageUpdated:
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
break;
case Messages::ReloadIdleTimer:
ReloadIdleTimer();
break;
default:
break;
@@ -449,6 +438,35 @@ void SystemTask::UpdateMotion() {
}
}
void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
if (IsSleeping()) {
return;
}
ReloadIdleTimer();
using Actions = Controllers::ButtonActions;
switch (action) {
case Actions::Click:
if (!isGoingToSleep) {
displayApp.PushMessage(Applications::Display::Messages::ButtonPushed);
}
break;
case Actions::DoubleClick:
displayApp.PushMessage(Applications::Display::Messages::ButtonDoubleClicked);
break;
case Actions::LongPress:
displayApp.PushMessage(Applications::Display::Messages::ButtonLongPressed);
break;
case Actions::LongerPress:
displayApp.PushMessage(Applications::Display::Messages::ButtonLongerPressed);
break;
default:
break;
}
}
void SystemTask::GoToRunning() {
if (isGoingToSleep or (not isSleeping) or isWakingUp)
return;