aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/DisplayApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/DisplayApp.cpp')
-rw-r--r--src/displayapp/DisplayApp.cpp133
1 files changed, 70 insertions, 63 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 108e380d..725caaf4 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -43,8 +43,7 @@
#include "displayapp/screens/settings/SettingWakeUp.h"
#include "displayapp/screens/settings/SettingDisplay.h"
#include "displayapp/screens/settings/SettingSteps.h"
-#include "displayapp/screens/settings/SettingSetDate.h"
-#include "displayapp/screens/settings/SettingSetTime.h"
+#include "displayapp/screens/settings/SettingSetDateTime.h"
#include "displayapp/screens/settings/SettingChimes.h"
#include "displayapp/screens/settings/SettingShakeThreshold.h"
#include "displayapp/screens/settings/SettingBluetooth.h"
@@ -102,9 +101,9 @@ void DisplayApp::Start(System::BootErrors error) {
bootError = error;
if (error == System::BootErrors::TouchController) {
- LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None);
+ LoadNewScreen(Apps::Error, DisplayApp::FullRefreshDirections::None);
} else {
- LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
+ LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
}
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
@@ -132,7 +131,25 @@ void DisplayApp::InitHw() {
void DisplayApp::Refresh() {
auto LoadPreviousScreen = [this]() {
- LoadApp(returnToApp, returnDirection);
+ FullRefreshDirections returnDirection;
+ switch (appStackDirections.Pop()) {
+ case FullRefreshDirections::Up:
+ returnDirection = FullRefreshDirections::Down;
+ break;
+ case FullRefreshDirections::Down:
+ returnDirection = FullRefreshDirections::Up;
+ break;
+ case FullRefreshDirections::LeftAnim:
+ returnDirection = FullRefreshDirections::RightAnim;
+ break;
+ case FullRefreshDirections::RightAnim:
+ returnDirection = FullRefreshDirections::LeftAnim;
+ break;
+ default:
+ returnDirection = FullRefreshDirections::None;
+ break;
+ }
+ LoadScreen(returnAppStack.Pop(), returnDirection);
};
TickType_t queueTimeout;
@@ -152,7 +169,7 @@ void DisplayApp::Refresh() {
}
Messages msg;
- if (xQueueReceive(msgQueue, &msg, queueTimeout)) {
+ if (xQueueReceive(msgQueue, &msg, queueTimeout) == pdTRUE) {
switch (msg) {
case Messages::DimScreen:
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
@@ -180,14 +197,14 @@ void DisplayApp::Refresh() {
// Screens::Clock::BleConnectionStates::NotConnected);
break;
case Messages::NewNotification:
- LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break;
case Messages::TimerDone:
if (currentApp == Apps::Timer) {
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
timer->Reset();
} else {
- LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
}
break;
case Messages::AlarmTriggered:
@@ -195,11 +212,11 @@ void DisplayApp::Refresh() {
auto* alarm = static_cast<Screens::Alarm*>(currentScreen.get());
alarm->SetAlerting();
} else {
- LoadApp(Apps::Alarm, DisplayApp::FullRefreshDirections::None);
+ LoadNewScreen(Apps::Alarm, DisplayApp::FullRefreshDirections::None);
}
break;
case Messages::ShowPairingKey:
- LoadApp(Apps::PassKey, DisplayApp::FullRefreshDirections::Up);
+ LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up);
break;
case Messages::TouchEvent: {
if (state != States::Running) {
@@ -209,17 +226,30 @@ void DisplayApp::Refresh() {
if (gesture == TouchEvents::None) {
break;
}
+ auto LoadDirToReturnSwipe = [](DisplayApp::FullRefreshDirections refreshDirection) {
+ switch (refreshDirection) {
+ default:
+ case DisplayApp::FullRefreshDirections::Up:
+ return TouchEvents::SwipeDown;
+ case DisplayApp::FullRefreshDirections::Down:
+ return TouchEvents::SwipeUp;
+ case DisplayApp::FullRefreshDirections::LeftAnim:
+ return TouchEvents::SwipeRight;
+ case DisplayApp::FullRefreshDirections::RightAnim:
+ return TouchEvents::SwipeLeft;
+ }
+ };
if (!currentScreen->OnTouchEvent(gesture)) {
if (currentApp == Apps::Clock) {
switch (gesture) {
case TouchEvents::SwipeUp:
- LoadApp(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
+ LoadNewScreen(Apps::Launcher, DisplayApp::FullRefreshDirections::Up);
break;
case TouchEvents::SwipeDown:
- LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
break;
case TouchEvents::SwipeRight:
- LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
+ LoadNewScreen(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
break;
case TouchEvents::DoubleTap:
PushMessageToSystemTask(System::Messages::GoToSleep);
@@ -227,7 +257,7 @@ void DisplayApp::Refresh() {
default:
break;
}
- } else if (returnTouchEvent == gesture) {
+ } else if (gesture == LoadDirToReturnSwipe(appStackDirections.Top())) {
LoadPreviousScreen();
}
} else {
@@ -246,26 +276,28 @@ void DisplayApp::Refresh() {
case Messages::ButtonLongPressed:
if (currentApp != Apps::Clock) {
if (currentApp == Apps::Notifications) {
- LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::Up);
+ LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::Up);
} else if (currentApp == Apps::QuickSettings) {
- LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::LeftAnim);
+ LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::LeftAnim);
} else {
- LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::Down);
}
+ appStackDirections.Reset();
+ returnAppStack.Reset();
}
break;
case Messages::ButtonLongerPressed:
// Create reboot app and open it instead
- LoadApp(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up);
+ LoadNewScreen(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up);
break;
case Messages::ButtonDoubleClicked:
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
- LoadApp(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
}
break;
case Messages::BleFirmwareUpdateStarted:
- LoadApp(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down);
+ LoadNewScreen(Apps::FirmwareUpdate, DisplayApp::FullRefreshDirections::Down);
break;
case Messages::BleRadioEnableToggle:
PushMessageToSystemTask(System::Messages::BleRadioEnableToggle);
@@ -275,7 +307,7 @@ void DisplayApp::Refresh() {
// What should happen here?
break;
case Messages::Clock:
- LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
+ LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
break;
}
}
@@ -285,7 +317,7 @@ void DisplayApp::Refresh() {
}
if (nextApp != Apps::None) {
- LoadApp(nextApp, nextDirection);
+ LoadNewScreen(nextApp, nextDirection);
nextApp = Apps::None;
}
}
@@ -295,27 +327,28 @@ void DisplayApp::StartApp(Apps app, DisplayApp::FullRefreshDirections direction)
nextDirection = direction;
}
-void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction, TouchEvents touchEvent) {
- returnToApp = app;
- returnDirection = direction;
- returnTouchEvent = touchEvent;
+void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
+ // Don't add the same screen to the stack back to back.
+ // This is mainly to fix an issue with receiving two notifications at the same time
+ // and shouldn't happen otherwise.
+ if (app != currentApp) {
+ returnAppStack.Push(currentApp);
+ appStackDirections.Push(direction);
+ }
+ LoadScreen(app, direction);
}
-void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
+void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
touchHandler.CancelTap();
ApplyBrightness();
currentScreen.reset(nullptr);
SetFullRefresh(direction);
- // default return to launcher
- ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::SwipeDown);
-
switch (app) {
case Apps::Launcher:
currentScreen =
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController);
- ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::None:
case Apps::Clock:
@@ -332,21 +365,17 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Error:
currentScreen = std::make_unique<Screens::Error>(this, bootError);
- ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::FirmwareValidation:
currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::FirmwareUpdate:
currentScreen = std::make_unique<Screens::FirmwareUpdate>(this, bleController);
- ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::PassKey:
currentScreen = std::make_unique<Screens::PassKey>(this, bleController.GetPairingKey());
- ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::Notifications:
@@ -356,7 +385,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
motorController,
*systemTask,
Screens::Notifications::Modes::Normal);
- ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::NotificationsPreview:
currentScreen = std::make_unique<Screens::Notifications>(this,
@@ -365,7 +393,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
motorController,
*systemTask,
Screens::Notifications::Modes::Preview);
- ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::Timer:
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
@@ -383,55 +410,39 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
motorController,
settingsController,
bleController);
- ReturnApp(Apps::Clock, FullRefreshDirections::LeftAnim, TouchEvents::SwipeLeft);
break;
case Apps::Settings:
currentScreen = std::make_unique<Screens::Settings>(this, settingsController);
- ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingWatchFace:
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController, filesystem);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingTimeFormat:
currentScreen = std::make_unique<Screens::SettingTimeFormat>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingSteps:
currentScreen = std::make_unique<Screens::SettingSteps>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
- case Apps::SettingSetDate:
- currentScreen = std::make_unique<Screens::SettingSetDate>(this, dateTimeController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
- break;
- case Apps::SettingSetTime:
- currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
+ case Apps::SettingSetDateTime:
+ currentScreen = std::make_unique<Screens::SettingSetDateTime>(this, dateTimeController, settingsController);
break;
case Apps::SettingChimes:
currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingShakeThreshold:
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController, motionController, *systemTask);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingBluetooth:
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SysInfo:
currentScreen = std::make_unique<Screens::SystemInfo>(this,
@@ -442,11 +453,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
watchdog,
motionController,
touchPanel);
- ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::FlashLight:
currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController);
- ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::StopWatch:
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask);
@@ -471,7 +480,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
break;
case Apps::Metronome:
currentScreen = std::make_unique<Screens::Metronome>(this, motorController, *systemTask);
- ReturnApp(Apps::Launcher, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::Motion:
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
@@ -485,10 +493,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
void DisplayApp::PushMessage(Messages msg) {
if (in_isr()) {
- BaseType_t xHigherPriorityTaskWoken;
- xHigherPriorityTaskWoken = pdFALSE;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
- if (xHigherPriorityTaskWoken) {
+ if (xHigherPriorityTaskWoken == pdTRUE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
@@ -530,10 +537,10 @@ void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
+
void DisplayApp::ApplyBrightness() {
auto brightness = settingsController.GetBrightness();
- if(brightness != Controllers::BrightnessController::Levels::Low &&
- brightness != Controllers::BrightnessController::Levels::Medium &&
+ if (brightness != Controllers::BrightnessController::Levels::Low && brightness != Controllers::BrightnessController::Levels::Medium &&
brightness != Controllers::BrightnessController::Levels::High) {
brightness = Controllers::BrightnessController::Levels::High;
}