summaryrefslogtreecommitdiff
path: root/src/displayapp/DisplayApp.cpp
diff options
context:
space:
mode:
authorhassless <85612141+hassless@users.noreply.github.com>2021-06-18 17:17:26 +0200
committerGitHub <noreply@github.com>2021-06-18 17:17:26 +0200
commit84a6c88e98d8b1420edbddd7b67a38737bf5cbb2 (patch)
treeb10cab7ef1a7645fa897aabb179c2e8849a919d7 /src/displayapp/DisplayApp.cpp
parentd0df278b0be2aae0493d901569a094dba221ce99 (diff)
parente90e8c7426f9a44e696b208a5b393a60476a3d43 (diff)
Merge branch 'JF002:develop' into improve-battery-percentage-to-battery-icon-mapping
Diffstat (limited to 'src/displayapp/DisplayApp.cpp')
-rw-r--r--src/displayapp/DisplayApp.cpp77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 7b03d569..ab73969d 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -18,6 +18,7 @@
#include "displayapp/screens/Paddle.h"
#include "displayapp/screens/StopWatch.h"
#include "displayapp/screens/Meter.h"
+#include "displayapp/screens/Metronome.h"
#include "displayapp/screens/Music.h"
#include "displayapp/screens/Navigation.h"
#include "displayapp/screens/Notifications.h"
@@ -32,6 +33,7 @@
#include "drivers/St7789.h"
#include "drivers/Watchdog.h"
#include "systemtask/SystemTask.h"
+#include "systemtask/Messages.h"
#include "displayapp/screens/settings/QuickSettings.h"
#include "displayapp/screens/settings/Settings.h"
@@ -44,6 +46,12 @@
using namespace Pinetime::Applications;
using namespace Pinetime::Applications::Display;
+namespace {
+ static inline bool in_isr(void) {
+ return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
+ }
+}
+
DisplayApp::DisplayApp(Drivers::St7789& lcd,
Components::LittleVgl& lvgl,
Drivers::Cst816S& touchPanel,
@@ -51,7 +59,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Drivers::WatchdogView& watchdog,
- System::SystemTask& systemTask,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::HeartRateController& heartRateController,
Controllers::Settings& settingsController,
@@ -65,19 +72,20 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
bleController {bleController},
dateTimeController {dateTimeController},
watchdog {watchdog},
- systemTask {systemTask},
notificationManager {notificationManager},
heartRateController {heartRateController},
settingsController {settingsController},
motorController {motorController},
motionController {motionController},
timerController {timerController} {
+}
+
+void DisplayApp::Start() {
msgQueue = xQueueCreate(queueSize, itemSize);
+
// Start clock when smartwatch boots
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
-}
-void DisplayApp::Start() {
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
}
@@ -130,7 +138,7 @@ void DisplayApp::Refresh() {
vTaskDelay(100);
}
lcd.DisplayOff();
- systemTask.PushMessage(System::SystemTask::Messages::OnDisplayTaskSleeping);
+ PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping);
state = States::Idle;
break;
case Messages::GoToRunning:
@@ -139,7 +147,7 @@ void DisplayApp::Refresh() {
state = States::Running;
break;
case Messages::UpdateTimeOut:
- systemTask.PushMessage(System::SystemTask::Messages::UpdateTimeOut);
+ PushMessageToSystemTask(System::Messages::UpdateTimeOut);
break;
case Messages::UpdateBleConnection:
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected :
@@ -176,7 +184,7 @@ void DisplayApp::Refresh() {
LoadApp(Apps::QuickSettings, DisplayApp::FullRefreshDirections::RightAnim);
break;
case TouchEvents::DoubleTap:
- systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
+ PushMessageToSystemTask(System::Messages::GoToSleep);
break;
default:
break;
@@ -188,7 +196,7 @@ void DisplayApp::Refresh() {
} break;
case Messages::ButtonPushed:
if (currentApp == Apps::Clock) {
- systemTask.PushMessage(System::SystemTask::Messages::GoToSleep);
+ PushMessageToSystemTask(System::Messages::GoToSleep);
} else {
if (!currentScreen->OnButtonPushed()) {
LoadApp(returnToApp, returnDirection);
@@ -206,6 +214,11 @@ void DisplayApp::Refresh() {
}
}
+ if(nextApp != Apps::None) {
+ LoadApp(nextApp, nextDirection);
+ nextApp = Apps::None;
+ }
+
if (state != States::Idle && touchMode == TouchModes::Polling) {
auto info = touchPanel.GetTouchInfo();
if (info.action == 2) { // 2 = contact
@@ -224,7 +237,8 @@ void DisplayApp::RunningState() {
}
void DisplayApp::StartApp(Apps app, DisplayApp::FullRefreshDirections direction) {
- LoadApp(app, direction);
+ nextApp = app;
+ nextDirection = direction;
}
void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction, TouchEvents touchEvent) {
@@ -267,12 +281,12 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Notifications:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal);
+ this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Normal);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::NotificationsPreview:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview);
+ this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Preview);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::Timer:
@@ -305,7 +319,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
- case Apps::SettingSteps:
+ case Apps::SettingSteps:
currentScreen = std::make_unique<Screens::SettingSteps>(this, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
@@ -318,10 +332,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
- //
-
case Apps::FlashLight:
- currentScreen = std::make_unique<Screens::FlashLight>(this, systemTask, brightnessController);
+ currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController);
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::StopWatch:
@@ -337,18 +349,21 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::Paddle>(this, lvgl);
break;
case Apps::Music:
- currentScreen = std::make_unique<Screens::Music>(this, systemTask.nimble().music());
+ currentScreen = std::make_unique<Screens::Music>(this, systemTask->nimble().music());
break;
case Apps::Navigation:
- currentScreen = std::make_unique<Screens::Navigation>(this, systemTask.nimble().navigation());
+ currentScreen = std::make_unique<Screens::Navigation>(this, systemTask->nimble().navigation());
break;
case Apps::HeartRate:
- currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, systemTask);
+ currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController, *systemTask);
+ break;
+ case Apps::Metronome:
+ currentScreen = std::make_unique<Screens::Metronome>(this, motorController, *systemTask);
break;
case Apps::Motion:
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
break;
- case Apps::Steps:
+ case Apps::Steps:
currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController);
break;
}
@@ -359,12 +374,15 @@ void DisplayApp::IdleState() {
}
void DisplayApp::PushMessage(Messages msg) {
- BaseType_t xHigherPriorityTaskWoken;
- xHigherPriorityTaskWoken = pdFALSE;
- xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
- if (xHigherPriorityTaskWoken) {
- /* Actual macro used here is port specific. */
- // TODO : should I do something here?
+ if(in_isr()) {
+ BaseType_t xHigherPriorityTaskWoken;
+ xHigherPriorityTaskWoken = pdFALSE;
+ xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
+ if (xHigherPriorityTaskWoken) {
+ portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
+ }
+ } else {
+ xQueueSend(msgQueue, &msg, portMAX_DELAY);
}
}
@@ -425,3 +443,12 @@ void DisplayApp::SetFullRefresh(DisplayApp::FullRefreshDirections direction) {
void DisplayApp::SetTouchMode(DisplayApp::TouchModes mode) {
touchMode = mode;
}
+
+void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
+ if(systemTask != nullptr)
+ systemTask->PushMessage(message);
+}
+
+void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
+ this->systemTask = systemTask;
+}