TimerController: Make TimerController reusable
TimerController instance was moved to DisplayApp.
This commit is contained in:
parent
4d93ae6d27
commit
661ffbeb1e
|
@ -1,16 +1,9 @@
|
|||
#include "components/timer/TimerController.h"
|
||||
#include "systemtask/SystemTask.h"
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
void TimerCallback(TimerHandle_t xTimer) {
|
||||
auto* controller = static_cast<TimerController*>(pvTimerGetTimerID(xTimer));
|
||||
controller->OnTimerEnd();
|
||||
}
|
||||
|
||||
void TimerController::Init(Pinetime::System::SystemTask* systemTask) {
|
||||
this->systemTask = systemTask;
|
||||
timer = xTimerCreate("Timer", 1, pdFALSE, this, TimerCallback);
|
||||
TimerController::TimerController(void* const timerData, TimerCallbackFunction_t timerCallbackFunction) {
|
||||
timer = xTimerCreate("Timer", 1, pdFALSE, timerData, timerCallbackFunction);
|
||||
}
|
||||
|
||||
void TimerController::StartTimer(std::chrono::milliseconds duration) {
|
||||
|
@ -33,7 +26,3 @@ void TimerController::StopTimer() {
|
|||
bool TimerController::IsRunning() {
|
||||
return (xTimerIsTimerActive(timer) == pdTRUE);
|
||||
}
|
||||
|
||||
void TimerController::OnTimerEnd() {
|
||||
systemTask->PushMessage(System::Messages::OnTimerDone);
|
||||
}
|
||||
|
|
|
@ -6,17 +6,10 @@
|
|||
#include <chrono>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace System {
|
||||
class SystemTask;
|
||||
}
|
||||
|
||||
namespace Controllers {
|
||||
|
||||
class TimerController {
|
||||
public:
|
||||
TimerController() = default;
|
||||
|
||||
void Init(System::SystemTask* systemTask);
|
||||
TimerController(void* timerData, TimerCallbackFunction_t timerCallbackFunction);
|
||||
|
||||
void StartTimer(std::chrono::milliseconds duration);
|
||||
|
||||
|
@ -26,10 +19,7 @@ namespace Pinetime {
|
|||
|
||||
bool IsRunning();
|
||||
|
||||
void OnTimerEnd();
|
||||
|
||||
private:
|
||||
System::SystemTask* systemTask = nullptr;
|
||||
TimerHandle_t timer;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ namespace {
|
|||
inline bool in_isr() {
|
||||
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,
|
||||
|
@ -70,7 +75,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
|||
Controllers::Settings& settingsController,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Controllers::TimerController& timerController,
|
||||
Pinetime::Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||
Pinetime::Controllers::TouchHandler& touchHandler,
|
||||
|
@ -86,12 +90,12 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
|||
settingsController {settingsController},
|
||||
motorController {motorController},
|
||||
motionController {motionController},
|
||||
timerController {timerController},
|
||||
alarmController {alarmController},
|
||||
brightnessController {brightnessController},
|
||||
touchHandler {touchHandler},
|
||||
filesystem {filesystem},
|
||||
lvgl {lcd, filesystem} {
|
||||
lvgl {lcd, filesystem},
|
||||
timerController(this, TimerCallback) {
|
||||
}
|
||||
|
||||
void DisplayApp::Start(System::BootErrors error) {
|
||||
|
@ -238,6 +242,9 @@ void DisplayApp::Refresh() {
|
|||
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
|
||||
break;
|
||||
case Messages::TimerDone:
|
||||
if (state != States::Running) {
|
||||
PushMessageToSystemTask(System::Messages::GoToRunning);
|
||||
}
|
||||
if (currentApp == Apps::Timer) {
|
||||
lv_disp_trig_activity(nullptr);
|
||||
auto* timer = static_cast<Screens::Timer*>(currentScreen.get());
|
||||
|
|
|
@ -61,7 +61,6 @@ namespace Pinetime {
|
|||
Controllers::Settings& settingsController,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Controllers::TimerController& timerController,
|
||||
Pinetime::Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||
Pinetime::Controllers::TouchHandler& touchHandler,
|
||||
|
@ -88,7 +87,6 @@ namespace Pinetime {
|
|||
Pinetime::Controllers::Settings& settingsController;
|
||||
Pinetime::Controllers::MotorController& motorController;
|
||||
Pinetime::Controllers::MotionController& motionController;
|
||||
Pinetime::Controllers::TimerController& timerController;
|
||||
Pinetime::Controllers::AlarmController& alarmController;
|
||||
Pinetime::Controllers::BrightnessController& brightnessController;
|
||||
Pinetime::Controllers::TouchHandler& touchHandler;
|
||||
|
@ -96,6 +94,7 @@ namespace Pinetime {
|
|||
|
||||
Pinetime::Controllers::FirmwareValidator validator;
|
||||
Pinetime::Components::LittleVgl lvgl;
|
||||
Pinetime::Controllers::TimerController timerController;
|
||||
|
||||
TaskHandle_t taskHandle;
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
|||
Controllers::Settings& /*settingsController*/,
|
||||
Pinetime::Controllers::MotorController& /*motorController*/,
|
||||
Pinetime::Controllers::MotionController& /*motionController*/,
|
||||
Pinetime::Controllers::TimerController& /*timerController*/,
|
||||
Pinetime::Controllers::AlarmController& /*alarmController*/,
|
||||
Pinetime::Controllers::BrightnessController& /*brightnessController*/,
|
||||
Pinetime::Controllers::TouchHandler& /*touchHandler*/,
|
||||
|
|
|
@ -31,7 +31,6 @@ namespace Pinetime {
|
|||
class MotionController;
|
||||
class TouchHandler;
|
||||
class MotorController;
|
||||
class TimerController;
|
||||
class AlarmController;
|
||||
class BrightnessController;
|
||||
class FS;
|
||||
|
@ -55,7 +54,6 @@ namespace Pinetime {
|
|||
Controllers::Settings& settingsController,
|
||||
Pinetime::Controllers::MotorController& motorController,
|
||||
Pinetime::Controllers::MotionController& motionController,
|
||||
Pinetime::Controllers::TimerController& timerController,
|
||||
Pinetime::Controllers::AlarmController& alarmController,
|
||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||
Pinetime::Controllers::TouchHandler& touchHandler,
|
||||
|
|
|
@ -103,7 +103,6 @@ Pinetime::Controllers::DateTime dateTimeController {settingsController};
|
|||
Pinetime::Drivers::Watchdog watchdog;
|
||||
Pinetime::Controllers::NotificationManager notificationManager;
|
||||
Pinetime::Controllers::MotionController motionController;
|
||||
Pinetime::Controllers::TimerController timerController;
|
||||
Pinetime::Controllers::AlarmController alarmController {dateTimeController};
|
||||
Pinetime::Controllers::TouchHandler touchHandler;
|
||||
Pinetime::Controllers::ButtonHandler buttonHandler;
|
||||
|
@ -120,7 +119,6 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
|
|||
settingsController,
|
||||
motorController,
|
||||
motionController,
|
||||
timerController,
|
||||
alarmController,
|
||||
brightnessController,
|
||||
touchHandler,
|
||||
|
@ -133,7 +131,6 @@ Pinetime::System::SystemTask systemTask(spi,
|
|||
batteryController,
|
||||
bleController,
|
||||
dateTimeController,
|
||||
timerController,
|
||||
alarmController,
|
||||
watchdog,
|
||||
notificationManager,
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Pinetime {
|
|||
TouchWakeUp,
|
||||
OnNewTime,
|
||||
OnNewNotification,
|
||||
OnTimerDone,
|
||||
OnNewCall,
|
||||
BleConnected,
|
||||
BleFirmwareUpdateStarted,
|
||||
|
|
|
@ -39,7 +39,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
|||
Controllers::Battery& batteryController,
|
||||
Controllers::Ble& bleController,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Controllers::TimerController& timerController,
|
||||
Controllers::AlarmController& alarmController,
|
||||
Drivers::Watchdog& watchdog,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
|
@ -60,7 +59,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
|||
batteryController {batteryController},
|
||||
bleController {bleController},
|
||||
dateTimeController {dateTimeController},
|
||||
timerController {timerController},
|
||||
alarmController {alarmController},
|
||||
watchdog {watchdog},
|
||||
notificationManager {notificationManager},
|
||||
|
@ -127,7 +125,6 @@ void SystemTask::Work() {
|
|||
dateTimeController.Register(this);
|
||||
batteryController.Register(this);
|
||||
motionSensor.SoftReset();
|
||||
timerController.Init(this);
|
||||
alarmController.Init(this);
|
||||
|
||||
// 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);
|
||||
}
|
||||
break;
|
||||
case Messages::OnTimerDone:
|
||||
if (state == SystemTaskState::Sleeping) {
|
||||
GoToRunning();
|
||||
}
|
||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
||||
break;
|
||||
case Messages::SetOffAlarm:
|
||||
if (state == SystemTaskState::Sleeping) {
|
||||
GoToRunning();
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "systemtask/SystemMonitor.h"
|
||||
#include "components/ble/NimbleController.h"
|
||||
#include "components/ble/NotificationManager.h"
|
||||
#include "components/timer/TimerController.h"
|
||||
#include "components/alarm/AlarmController.h"
|
||||
#include "components/fs/FS.h"
|
||||
#include "touchhandler/TouchHandler.h"
|
||||
|
@ -61,7 +60,6 @@ namespace Pinetime {
|
|||
Controllers::Battery& batteryController,
|
||||
Controllers::Ble& bleController,
|
||||
Controllers::DateTime& dateTimeController,
|
||||
Controllers::TimerController& timerController,
|
||||
Controllers::AlarmController& alarmController,
|
||||
Drivers::Watchdog& watchdog,
|
||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||
|
@ -107,7 +105,6 @@ namespace Pinetime {
|
|||
|
||||
Pinetime::Controllers::Ble& bleController;
|
||||
Pinetime::Controllers::DateTime& dateTimeController;
|
||||
Pinetime::Controllers::TimerController& timerController;
|
||||
Pinetime::Controllers::AlarmController& alarmController;
|
||||
QueueHandle_t systemTasksMsgQueue;
|
||||
Pinetime::Drivers::Watchdog& watchdog;
|
||||
|
|
Loading…
Reference in New Issue
Block a user