SystemTask: Move MotorController to DisplayApp

Vibrations should be associated with something happening on the UI.
Therefore SystemTask should not be controlling the motor.
This commit is contained in:
Riku Isokoski 2023-02-25 10:25:38 +02:00
parent 255b07094b
commit 5ab255b26b
9 changed files with 25 additions and 27 deletions

View file

@ -104,5 +104,4 @@ void AlarmController::StopAlerting() {
// set next instance // set next instance
ScheduleAlarm(); ScheduleAlarm();
} }
systemTask->PushMessage(System::Messages::StopRinging);
} }

View file

@ -127,6 +127,7 @@ void DisplayApp::Process(void* instance) {
void DisplayApp::InitHw() { void DisplayApp::InitHw() {
brightnessController.Init(); brightnessController.Init();
ApplyBrightness(); ApplyBrightness();
motorController.Init();
} }
void DisplayApp::Refresh() { void DisplayApp::Refresh() {
@ -206,6 +207,7 @@ void DisplayApp::Refresh() {
} else { } else {
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
} }
motorController.RunForDuration(35);
break; break;
case Messages::AlarmTriggered: case Messages::AlarmTriggered:
if (currentApp == Apps::Alarm) { if (currentApp == Apps::Alarm) {
@ -217,6 +219,7 @@ void DisplayApp::Refresh() {
break; break;
case Messages::ShowPairingKey: case Messages::ShowPairingKey:
LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up); LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up);
motorController.RunForDuration(35);
break; break;
case Messages::TouchEvent: { case Messages::TouchEvent: {
if (state != States::Running) { if (state != States::Running) {
@ -307,8 +310,12 @@ void DisplayApp::Refresh() {
// Added to remove warning // Added to remove warning
// What should happen here? // What should happen here?
break; break;
case Messages::Clock: case Messages::Chime:
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
motorController.RunForDuration(35);
break;
case Messages::OnChargingEvent:
motorController.RunForDuration(15);
break; break;
} }
} }
@ -342,6 +349,7 @@ void DisplayApp::LoadNewScreen(Apps app, DisplayApp::FullRefreshDirections direc
void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) { void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections direction) {
lvgl.CancelTap(); lvgl.CancelTap();
ApplyBrightness(); ApplyBrightness();
motorController.StopRinging();
currentScreen.reset(nullptr); currentScreen.reset(nullptr);
SetFullRefresh(direction); SetFullRefresh(direction);
@ -399,7 +407,8 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
currentScreen = std::make_unique<Screens::Timer>(this, timerController); currentScreen = std::make_unique<Screens::Timer>(this, timerController);
break; break;
case Apps::Alarm: case Apps::Alarm:
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController.GetClockType(), *systemTask); currentScreen =
std::make_unique<Screens::Alarm>(this, alarmController, settingsController.GetClockType(), *systemTask, motorController);
break; break;
// Settings // Settings

View file

@ -22,8 +22,9 @@ namespace Pinetime {
RestoreBrightness, RestoreBrightness,
ShowPairingKey, ShowPairingKey,
AlarmTriggered, AlarmTriggered,
Clock, Chime,
BleRadioEnableToggle BleRadioEnableToggle,
OnChargingEvent,
}; };
} }
} }

View file

@ -43,8 +43,9 @@ static void StopAlarmTaskCallback(lv_task_t* task) {
Alarm::Alarm(DisplayApp* app, Alarm::Alarm(DisplayApp* app,
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType, Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask) System::SystemTask& systemTask,
: Screen(app), alarmController {alarmController}, systemTask {systemTask} { Controllers::MotorController& motorController)
: Screen(app), alarmController {alarmController}, systemTask {systemTask}, motorController {motorController} {
hourCounter.Create(); hourCounter.Create();
lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); 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(enableSwitch, true);
lv_obj_set_hidden(btnStop, false); lv_obj_set_hidden(btnStop, false);
taskStopAlarm = lv_task_create(StopAlarmTaskCallback, pdMS_TO_TICKS(60 * 1000), LV_TASK_PRIO_MID, this); taskStopAlarm = lv_task_create(StopAlarmTaskCallback, pdMS_TO_TICKS(60 * 1000), LV_TASK_PRIO_MID, this);
motorController.StartRinging();
systemTask.PushMessage(System::Messages::DisableSleeping); systemTask.PushMessage(System::Messages::DisableSleeping);
} }
void Alarm::StopAlerting() { void Alarm::StopAlerting() {
alarmController.StopAlerting(); alarmController.StopAlerting();
motorController.StopRinging();
SetSwitchState(LV_ANIM_OFF); SetSwitchState(LV_ANIM_OFF);
if (taskStopAlarm != nullptr) { if (taskStopAlarm != nullptr) {
lv_task_del(taskStopAlarm); lv_task_del(taskStopAlarm);

View file

@ -31,7 +31,8 @@ namespace Pinetime {
Alarm(DisplayApp* app, Alarm(DisplayApp* app,
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Controllers::Settings::ClockType clockType, Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask); System::SystemTask& systemTask,
Controllers::MotorController& motorController);
~Alarm() override; ~Alarm() override;
void SetAlerting(); void SetAlerting();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event); void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
@ -43,6 +44,7 @@ namespace Pinetime {
private: private:
Controllers::AlarmController& alarmController; Controllers::AlarmController& alarmController;
System::SystemTask& systemTask; System::SystemTask& systemTask;
Controllers::MotorController& motorController;
lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch; lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch;
lv_obj_t* lblampm = nullptr; lv_obj_t* lblampm = nullptr;

View file

@ -146,7 +146,6 @@ Pinetime::System::SystemTask systemTask(spi,
alarmController, alarmController,
watchdog, watchdog,
notificationManager, notificationManager,
motorController,
heartRateSensor, heartRateSensor,
motionController, motionController,
motionSensor, motionSensor,

View file

@ -27,7 +27,6 @@ namespace Pinetime {
OnChargingEvent, OnChargingEvent,
OnPairing, OnPairing,
SetOffAlarm, SetOffAlarm,
StopRinging,
MeasureBatteryTimerExpired, MeasureBatteryTimerExpired,
BatteryPercentageUpdated, BatteryPercentageUpdated,
LowBattery, LowBattery,

View file

@ -61,7 +61,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog, Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Drivers::Hrs3300& heartRateSensor, Pinetime::Drivers::Hrs3300& heartRateSensor,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Drivers::Bma421& motionSensor, Pinetime::Drivers::Bma421& motionSensor,
@ -85,7 +84,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
alarmController {alarmController}, alarmController {alarmController},
watchdog {watchdog}, watchdog {watchdog},
notificationManager {notificationManager}, notificationManager {notificationManager},
motorController {motorController},
heartRateSensor {heartRateSensor}, heartRateSensor {heartRateSensor},
motionSensor {motionSensor}, motionSensor {motionSensor},
settingsController {settingsController}, settingsController {settingsController},
@ -149,7 +147,6 @@ void SystemTask::Work() {
touchPanel.Init(); touchPanel.Init();
dateTimeController.Register(this); dateTimeController.Register(this);
batteryController.Register(this); batteryController.Register(this);
motorController.Init();
motionSensor.SoftReset(); motionSensor.SoftReset();
timerController.Init(this); timerController.Init(this);
alarmController.Init(this); alarmController.Init(this);
@ -295,19 +292,14 @@ void SystemTask::Work() {
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
motorController.RunForDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone); displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break; break;
case Messages::SetOffAlarm: case Messages::SetOffAlarm:
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
motorController.StartRinging();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered); displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
break; break;
case Messages::StopRinging:
motorController.StopRinging();
break;
case Messages::BleConnected: case Messages::BleConnected:
ReloadIdleTimer(); ReloadIdleTimer();
isBleDiscoveryTimerRunning = true; isBleDiscoveryTimerRunning = true;
@ -394,9 +386,8 @@ void SystemTask::Work() {
alarmController.State() != AlarmController::AlarmState::Alerting) { alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime);
} }
motorController.RunForDuration(35);
} }
break; break;
case Messages::OnNewHalfHour: case Messages::OnNewHalfHour:
@ -406,14 +397,13 @@ void SystemTask::Work() {
alarmController.State() != AlarmController::AlarmState::Alerting) { alarmController.State() != AlarmController::AlarmState::Alerting) {
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Chime);
} }
motorController.RunForDuration(35);
} }
break; break;
case Messages::OnChargingEvent: case Messages::OnChargingEvent:
batteryController.ReadPowerState(); batteryController.ReadPowerState();
motorController.RunForDuration(15); displayApp.PushMessage(Applications::Display::Messages::OnChargingEvent);
ReloadIdleTimer(); ReloadIdleTimer();
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
@ -439,7 +429,6 @@ void SystemTask::Work() {
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();
} }
motorController.RunForDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowPairingKey); displayApp.PushMessage(Pinetime::Applications::Display::Messages::ShowPairingKey);
break; break;
case Messages::BleRadioEnableToggle: case Messages::BleRadioEnableToggle:

View file

@ -15,7 +15,6 @@
#include "systemtask/SystemMonitor.h" #include "systemtask/SystemMonitor.h"
#include "components/ble/NimbleController.h" #include "components/ble/NimbleController.h"
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h" #include "components/timer/TimerController.h"
#include "components/alarm/AlarmController.h" #include "components/alarm/AlarmController.h"
#include "components/fs/FS.h" #include "components/fs/FS.h"
@ -70,7 +69,6 @@ namespace Pinetime {
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog, Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Drivers::Hrs3300& heartRateSensor, Pinetime::Drivers::Hrs3300& heartRateSensor,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Drivers::Bma421& motionSensor, Pinetime::Drivers::Bma421& motionSensor,
@ -116,7 +114,6 @@ namespace Pinetime {
QueueHandle_t systemTasksMsgQueue; QueueHandle_t systemTasksMsgQueue;
Pinetime::Drivers::Watchdog& watchdog; Pinetime::Drivers::Watchdog& watchdog;
Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Drivers::Hrs3300& heartRateSensor; Pinetime::Drivers::Hrs3300& heartRateSensor;
Pinetime::Drivers::Bma421& motionSensor; Pinetime::Drivers::Bma421& motionSensor;
Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::Settings& settingsController;