1
0
Fork 0

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
ScheduleAlarm();
}
systemTask->PushMessage(System::Messages::StopRinging);
}

View file

@ -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<Screens::Timer>(this, timerController);
break;
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;
// Settings

View file

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

View file

@ -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);

View file

@ -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;

View file

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

View file

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

View file

@ -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:

View file

@ -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;