TimerController: Make TimerController reusable

TimerController instance was moved to DisplayApp.
This commit is contained in:
Riku Isokoski 2023-02-27 15:40:43 +02:00
parent 4d93ae6d27
commit 661ffbeb1e
10 changed files with 14 additions and 48 deletions

View File

@ -1,16 +1,9 @@
#include "components/timer/TimerController.h" #include "components/timer/TimerController.h"
#include "systemtask/SystemTask.h"
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
void TimerCallback(TimerHandle_t xTimer) { TimerController::TimerController(void* const timerData, TimerCallbackFunction_t timerCallbackFunction) {
auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer)); timer = xTimerCreate("Timer", 1, pdFALSE, timerData, timerCallbackFunction);
controller->OnTimerEnd();
}
void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
timer = xTimerCreate("Timer", 1, pdFALSE, this, TimerCallback);
} }
void TimerController::StartTimer(std::chrono::milliseconds duration) { void TimerController::StartTimer(std::chrono::milliseconds duration) {
@ -33,7 +26,3 @@ void TimerController::StopTimer() {
bool TimerController::IsRunning() { bool TimerController::IsRunning() {
return (xTimerIsTimerActive(timer) == pdTRUE); return (xTimerIsTimerActive(timer) == pdTRUE);
} }
void TimerController::OnTimerEnd() {
systemTask->PushMessage(System::Messages::OnTimerDone);
}

View File

@ -6,17 +6,10 @@
#include <chrono> #include <chrono>
namespace Pinetime { namespace Pinetime {
namespace System {
class SystemTask;
}
namespace Controllers { namespace Controllers {
class TimerController { class TimerController {
public: public:
TimerController() = default; TimerController(void* timerData, TimerCallbackFunction_t timerCallbackFunction);
void Init(System::SystemTask* systemTask);
void StartTimer(std::chrono::milliseconds duration); void StartTimer(std::chrono::milliseconds duration);
@ -26,10 +19,7 @@ namespace Pinetime {
bool IsRunning(); bool IsRunning();
void OnTimerEnd();
private: private:
System::SystemTask* systemTask = nullptr;
TimerHandle_t timer; TimerHandle_t timer;
}; };
} }

View File

@ -57,6 +57,11 @@ namespace {
inline bool in_isr() { inline bool in_isr() {
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0; return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
} }
void TimerCallback(TimerHandle_t xTimer) {
auto* dispApp = static_cast<DisplayApp*>(pvTimerGetTimerID(xTimer));
dispApp->PushMessage(Display::Messages::TimerDone);
}
} }
DisplayApp::DisplayApp(Drivers::St7789& lcd, DisplayApp::DisplayApp(Drivers::St7789& lcd,
@ -70,7 +75,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler, Pinetime::Controllers::TouchHandler& touchHandler,
@ -86,12 +90,12 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
settingsController {settingsController}, settingsController {settingsController},
motorController {motorController}, motorController {motorController},
motionController {motionController}, motionController {motionController},
timerController {timerController},
alarmController {alarmController}, alarmController {alarmController},
brightnessController {brightnessController}, brightnessController {brightnessController},
touchHandler {touchHandler}, touchHandler {touchHandler},
filesystem {filesystem}, filesystem {filesystem},
lvgl {lcd, filesystem} { lvgl {lcd, filesystem},
timerController(this, TimerCallback) {
} }
void DisplayApp::Start(System::BootErrors error) { void DisplayApp::Start(System::BootErrors error) {
@ -238,6 +242,9 @@ void DisplayApp::Refresh() {
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down); LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
break; break;
case Messages::TimerDone: case Messages::TimerDone:
if (state != States::Running) {
PushMessageToSystemTask(System::Messages::GoToRunning);
}
if (currentApp == Apps::Timer) { if (currentApp == Apps::Timer) {
lv_disp_trig_activity(nullptr); lv_disp_trig_activity(nullptr);
auto* timer = static_cast<Screens::Timer*>(currentScreen.get()); auto* timer = static_cast<Screens::Timer*>(currentScreen.get());

View File

@ -61,7 +61,6 @@ namespace Pinetime {
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler, Pinetime::Controllers::TouchHandler& touchHandler,
@ -88,7 +87,6 @@ namespace Pinetime {
Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::Settings& settingsController;
Pinetime::Controllers::MotorController& motorController; Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::MotionController& motionController; Pinetime::Controllers::MotionController& motionController;
Pinetime::Controllers::TimerController& timerController;
Pinetime::Controllers::AlarmController& alarmController; Pinetime::Controllers::AlarmController& alarmController;
Pinetime::Controllers::BrightnessController& brightnessController; Pinetime::Controllers::BrightnessController& brightnessController;
Pinetime::Controllers::TouchHandler& touchHandler; Pinetime::Controllers::TouchHandler& touchHandler;
@ -96,6 +94,7 @@ namespace Pinetime {
Pinetime::Controllers::FirmwareValidator validator; Pinetime::Controllers::FirmwareValidator validator;
Pinetime::Components::LittleVgl lvgl; Pinetime::Components::LittleVgl lvgl;
Pinetime::Controllers::TimerController timerController;
TaskHandle_t taskHandle; TaskHandle_t taskHandle;

View File

@ -21,7 +21,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Controllers::Settings& /*settingsController*/, Controllers::Settings& /*settingsController*/,
Pinetime::Controllers::MotorController& /*motorController*/, Pinetime::Controllers::MotorController& /*motorController*/,
Pinetime::Controllers::MotionController& /*motionController*/, Pinetime::Controllers::MotionController& /*motionController*/,
Pinetime::Controllers::TimerController& /*timerController*/,
Pinetime::Controllers::AlarmController& /*alarmController*/, Pinetime::Controllers::AlarmController& /*alarmController*/,
Pinetime::Controllers::BrightnessController& /*brightnessController*/, Pinetime::Controllers::BrightnessController& /*brightnessController*/,
Pinetime::Controllers::TouchHandler& /*touchHandler*/, Pinetime::Controllers::TouchHandler& /*touchHandler*/,

View File

@ -31,7 +31,6 @@ namespace Pinetime {
class MotionController; class MotionController;
class TouchHandler; class TouchHandler;
class MotorController; class MotorController;
class TimerController;
class AlarmController; class AlarmController;
class BrightnessController; class BrightnessController;
class FS; class FS;
@ -55,7 +54,6 @@ namespace Pinetime {
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController, Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::BrightnessController& brightnessController, Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler, Pinetime::Controllers::TouchHandler& touchHandler,

View File

@ -103,7 +103,6 @@ Pinetime::Controllers::DateTime dateTimeController {settingsController};
Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::Watchdog watchdog;
Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::MotionController motionController;
Pinetime::Controllers::TimerController timerController;
Pinetime::Controllers::AlarmController alarmController {dateTimeController}; Pinetime::Controllers::AlarmController alarmController {dateTimeController};
Pinetime::Controllers::TouchHandler touchHandler; Pinetime::Controllers::TouchHandler touchHandler;
Pinetime::Controllers::ButtonHandler buttonHandler; Pinetime::Controllers::ButtonHandler buttonHandler;
@ -120,7 +119,6 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
settingsController, settingsController,
motorController, motorController,
motionController, motionController,
timerController,
alarmController, alarmController,
brightnessController, brightnessController,
touchHandler, touchHandler,
@ -133,7 +131,6 @@ Pinetime::System::SystemTask systemTask(spi,
batteryController, batteryController,
bleController, bleController,
dateTimeController, dateTimeController,
timerController,
alarmController, alarmController,
watchdog, watchdog,
notificationManager, notificationManager,

View File

@ -9,7 +9,6 @@ namespace Pinetime {
TouchWakeUp, TouchWakeUp,
OnNewTime, OnNewTime,
OnNewNotification, OnNewNotification,
OnTimerDone,
OnNewCall, OnNewCall,
BleConnected, BleConnected,
BleFirmwareUpdateStarted, BleFirmwareUpdateStarted,

View File

@ -39,7 +39,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Controllers::Battery& batteryController, Controllers::Battery& batteryController,
Controllers::Ble& bleController, Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Controllers::TimerController& timerController,
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog, Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::NotificationManager& notificationManager,
@ -60,7 +59,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
batteryController {batteryController}, batteryController {batteryController},
bleController {bleController}, bleController {bleController},
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
timerController {timerController},
alarmController {alarmController}, alarmController {alarmController},
watchdog {watchdog}, watchdog {watchdog},
notificationManager {notificationManager}, notificationManager {notificationManager},
@ -127,7 +125,6 @@ void SystemTask::Work() {
dateTimeController.Register(this); dateTimeController.Register(this);
batteryController.Register(this); batteryController.Register(this);
motionSensor.SoftReset(); motionSensor.SoftReset();
timerController.Init(this);
alarmController.Init(this); alarmController.Init(this);
// Reset the TWI device because the motion sensor chip most probably crashed it... // Reset the TWI device because the motion sensor chip most probably crashed it...
@ -256,12 +253,6 @@ void SystemTask::Work() {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification); displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
} }
break; break;
case Messages::OnTimerDone:
if (state == SystemTaskState::Sleeping) {
GoToRunning();
}
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break;
case Messages::SetOffAlarm: case Messages::SetOffAlarm:
if (state == SystemTaskState::Sleeping) { if (state == SystemTaskState::Sleeping) {
GoToRunning(); GoToRunning();

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/timer/TimerController.h"
#include "components/alarm/AlarmController.h" #include "components/alarm/AlarmController.h"
#include "components/fs/FS.h" #include "components/fs/FS.h"
#include "touchhandler/TouchHandler.h" #include "touchhandler/TouchHandler.h"
@ -61,7 +60,6 @@ namespace Pinetime {
Controllers::Battery& batteryController, Controllers::Battery& batteryController,
Controllers::Ble& bleController, Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController, Controllers::DateTime& dateTimeController,
Controllers::TimerController& timerController,
Controllers::AlarmController& alarmController, Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog, Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::NotificationManager& notificationManager,
@ -107,7 +105,6 @@ namespace Pinetime {
Pinetime::Controllers::Ble& bleController; Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController;
Pinetime::Controllers::AlarmController& alarmController; Pinetime::Controllers::AlarmController& alarmController;
QueueHandle_t systemTasksMsgQueue; QueueHandle_t systemTasksMsgQueue;
Pinetime::Drivers::Watchdog& watchdog; Pinetime::Drivers::Watchdog& watchdog;