From 5ab255b26b4f23ca4b6fab2a660f8cf55fcda48b Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sat, 25 Feb 2023 10:25:38 +0200 Subject: [PATCH] SystemTask: Move MotorController to DisplayApp Vibrations should be associated with something happening on the UI. Therefore SystemTask should not be controlling the motor. --- src/components/alarm/AlarmController.cpp | 1 - src/displayapp/DisplayApp.cpp | 13 +++++++++++-- src/displayapp/Messages.h | 5 +++-- src/displayapp/screens/Alarm.cpp | 7 +++++-- src/displayapp/screens/Alarm.h | 4 +++- src/main.cpp | 1 - src/systemtask/Messages.h | 1 - src/systemtask/SystemTask.cpp | 17 +++-------------- src/systemtask/SystemTask.h | 3 --- 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 88f65d9a..c4eb8ed0 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -104,5 +104,4 @@ void AlarmController::StopAlerting() { // set next instance ScheduleAlarm(); } - systemTask->PushMessage(System::Messages::StopRinging); } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 41e73f33..055a6a80 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -127,6 +127,7 @@ void DisplayApp::Process(void* instance) { void DisplayApp::InitHw() { brightnessController.Init(); ApplyBrightness(); + motorController.Init(); } void DisplayApp::Refresh() { @@ -206,6 +207,7 @@ void DisplayApp::Refresh() { } else { LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); } + motorController.RunForDuration(35); break; case Messages::AlarmTriggered: if (currentApp == Apps::Alarm) { @@ -217,6 +219,7 @@ void DisplayApp::Refresh() { break; case Messages::ShowPairingKey: LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up); + motorController.RunForDuration(35); break; case Messages::TouchEvent: { if (state != States::Running) { @@ -307,8 +310,12 @@ void DisplayApp::Refresh() { // Added to remove warning // What should happen here? break; - case Messages::Clock: + case Messages::Chime: LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); + motorController.RunForDuration(35); + break; + case Messages::OnChargingEvent: + motorController.RunForDuration(15); break; } } @@ -342,6 +349,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) { lvgl.CancelTap(); ApplyBrightness(); + motorController.StopRinging(); currentScreen.reset(nullptr); SetFullRefresh(direction); @@ -399,7 +407,8 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio currentScreen = std::make_unique(this, timerController); break; case Apps::Alarm: - currentScreen = std::make_unique(this, alarmController, settingsController.GetClockType(), *systemTask); + currentScreen = + std::make_unique(this, alarmController, settingsController.GetClockType(), *systemTask, motorController); break; // Settings diff --git a/src/displayapp/Messages.h b/src/displayapp/Messages.h index afa7709a..b670b1aa 100644 --- a/src/displayapp/Messages.h +++ b/src/displayapp/Messages.h @@ -22,8 +22,9 @@ namespace Pinetime { RestoreBrightness, ShowPairingKey, AlarmTriggered, - Clock, - BleRadioEnableToggle + Chime, + BleRadioEnableToggle, + OnChargingEvent, }; } } diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp index d6371ce6..371e0185 100644 --- a/src/displayapp/screens/Alarm.cpp +++ b/src/displayapp/screens/Alarm.cpp @@ -43,8 +43,9 @@ static void StopAlarmTaskCallback(lv_task_t* task) { Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Controllers::Settings::ClockType clockType, - System::SystemTask& systemTask) - : Screen(app), alarmController {alarmController}, systemTask {systemTask} { + System::SystemTask& systemTask, + Controllers::MotorController& motorController) + : Screen(app), alarmController {alarmController}, systemTask {systemTask}, motorController {motorController} { hourCounter.Create(); lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); @@ -200,11 +201,13 @@ void Alarm::SetAlerting() { lv_obj_set_hidden(enableSwitch, true); lv_obj_set_hidden(btnStop, false); taskStopAlarm = lv_task_create(StopAlarmTaskCallback, pdMS_TO_TICKS(60 * 1000), LV_TASK_PRIO_MID, this); + motorController.StartRinging(); systemTask.PushMessage(System::Messages::DisableSleeping); } void Alarm::StopAlerting() { alarmController.StopAlerting(); + motorController.StopRinging(); SetSwitchState(LV_ANIM_OFF); if (taskStopAlarm != nullptr) { lv_task_del(taskStopAlarm); diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h index fba9d5d9..d7935549 100644 --- a/src/displayapp/screens/Alarm.h +++ b/src/displayapp/screens/Alarm.h @@ -31,7 +31,8 @@ namespace Pinetime { Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Controllers::Settings::ClockType clockType, - System::SystemTask& systemTask); + System::SystemTask& systemTask, + Controllers::MotorController& motorController); ~Alarm() override; void SetAlerting(); void OnButtonEvent(lv_obj_t* obj, lv_event_t event); @@ -43,6 +44,7 @@ namespace Pinetime { private: Controllers::AlarmController& alarmController; System::SystemTask& systemTask; + Controllers::MotorController& motorController; lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch; lv_obj_t* lblampm = nullptr; diff --git a/src/main.cpp b/src/main.cpp index 0053c5e8..6cb52a81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,7 +146,6 @@ Pinetime::System::SystemTask systemTask(spi, alarmController, watchdog, notificationManager, - motorController, heartRateSensor, motionController, motionSensor, diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index b7fee8a5..9679bbb5 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -27,7 +27,6 @@ namespace Pinetime { OnChargingEvent, OnPairing, SetOffAlarm, - StopRinging, MeasureBatteryTimerExpired, BatteryPercentageUpdated, LowBattery, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 2f29dc7a..49c30a9f 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -61,7 +61,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, Controllers::AlarmController& alarmController, Drivers::Watchdog& watchdog, Pinetime::Controllers::NotificationManager& notificationManager, - Pinetime::Controllers::MotorController& motorController, Pinetime::Drivers::Hrs3300& heartRateSensor, Pinetime::Controllers::MotionController& motionController, Pinetime::Drivers::Bma421& motionSensor, @@ -85,7 +84,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, alarmController {alarmController}, watchdog {watchdog}, notificationManager {notificationManager}, - motorController {motorController}, heartRateSensor {heartRateSensor}, motionSensor {motionSensor}, settingsController {settingsController}, @@ -149,7 +147,6 @@ void SystemTask::Work() { touchPanel.Init(); dateTimeController.Register(this); batteryController.Register(this); - motorController.Init(); motionSensor.SoftReset(); timerController.Init(this); alarmController.Init(this); @@ -295,19 +292,14 @@ void SystemTask::Work() { if (state == SystemTaskState::Sleeping) { GoToRunning(); } - motorController.RunForDuration(35); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone); break; case Messages::SetOffAlarm: if (state == SystemTaskState::Sleeping) { GoToRunning(); } - motorController.StartRinging(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered); break; - case Messages::StopRinging: - motorController.StopRinging(); - break; case Messages::BleConnected: ReloadIdleTimer(); isBleDiscoveryTimerRunning = true; @@ -394,9 +386,8 @@ void SystemTask::Work() { alarmController.State() != AlarmController::AlarmState::Alerting) { if (state == SystemTaskState::Sleeping) { GoToRunning(); - displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime); } - motorController.RunForDuration(35); } break; case Messages::OnNewHalfHour: @@ -406,14 +397,13 @@ void SystemTask::Work() { alarmController.State() != AlarmController::AlarmState::Alerting) { if (state == SystemTaskState::Sleeping) { GoToRunning(); - displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime); } - motorController.RunForDuration(35); } break; case Messages::OnChargingEvent: batteryController.ReadPowerState(); - motorController.RunForDuration(15); + displayApp.PushMessage(Applications::Display::Messages::OnChargingEvent); ReloadIdleTimer(); if (state == SystemTaskState::Sleeping) { GoToRunning(); @@ -439,7 +429,6 @@ void SystemTask::Work() { if (state == SystemTaskState::Sleeping) { GoToRunning(); } - motorController.RunForDuration(35); displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowPairingKey); break; case Messages::BleRadioEnableToggle: diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 9c43b9b2..dd3f39b9 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -15,7 +15,6 @@ #include "systemtask/SystemMonitor.h" #include "components/ble/NimbleController.h" #include "components/ble/NotificationManager.h" -#include "components/motor/MotorController.h" #include "components/timer/TimerController.h" #include "components/alarm/AlarmController.h" #include "components/fs/FS.h" @@ -70,7 +69,6 @@ namespace Pinetime { Controllers::AlarmController& alarmController, Drivers::Watchdog& watchdog, Pinetime::Controllers::NotificationManager& notificationManager, - Pinetime::Controllers::MotorController& motorController, Pinetime::Drivers::Hrs3300& heartRateSensor, Pinetime::Controllers::MotionController& motionController, Pinetime::Drivers::Bma421& motionSensor, @@ -116,7 +114,6 @@ namespace Pinetime { QueueHandle_t systemTasksMsgQueue; Pinetime::Drivers::Watchdog& watchdog; Pinetime::Controllers::NotificationManager& notificationManager; - Pinetime::Controllers::MotorController& motorController; Pinetime::Drivers::Hrs3300& heartRateSensor; Pinetime::Drivers::Bma421& motionSensor; Pinetime::Controllers::Settings& settingsController;