Skip to content

Commit

Permalink
TimerController: Make TimerController reusable
Browse files Browse the repository at this point in the history
TimerController instance was moved to DisplayApp.
  • Loading branch information
Riksu9000 committed Apr 16, 2023
1 parent 4d93ae6 commit 661ffbe
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 48 deletions.
15 changes: 2 additions & 13 deletions src/components/timer/TimerController.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -33,7 +26,3 @@ void TimerController::StopTimer() {
bool TimerController::IsRunning() {
return (xTimerIsTimerActive(timer) == pdTRUE);
}

void TimerController::OnTimerEnd() {
systemTask->PushMessage(System::Messages::OnTimerDone);
}
12 changes: 1 addition & 11 deletions src/components/timer/TimerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -26,10 +19,7 @@ namespace Pinetime {

bool IsRunning();

void OnTimerEnd();

private:
System::SystemTask* systemTask = nullptr;
TimerHandle_t timer;
};
}
Expand Down
13 changes: 10 additions & 3 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -88,14 +87,14 @@ 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;
Pinetime::Controllers::FS& filesystem;

Pinetime::Controllers::FirmwareValidator validator;
Pinetime::Components::LittleVgl lvgl;
Pinetime::Controllers::TimerController timerController;

TaskHandle_t taskHandle;

Expand Down
1 change: 0 additions & 1 deletion src/displayapp/DisplayAppRecovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand Down
2 changes: 0 additions & 2 deletions src/displayapp/DisplayAppRecovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Pinetime {
class MotionController;
class TouchHandler;
class MotorController;
class TimerController;
class AlarmController;
class BrightnessController;
class FS;
Expand All @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -120,7 +119,6 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
settingsController,
motorController,
motionController,
timerController,
alarmController,
brightnessController,
touchHandler,
Expand All @@ -133,7 +131,6 @@ Pinetime::System::SystemTask systemTask(spi,
batteryController,
bleController,
dateTimeController,
timerController,
alarmController,
watchdog,
notificationManager,
Expand Down
1 change: 0 additions & 1 deletion src/systemtask/Messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Pinetime {
TouchWakeUp,
OnNewTime,
OnNewNotification,
OnTimerDone,
OnNewCall,
BleConnected,
BleFirmwareUpdateStarted,
Expand Down
9 changes: 0 additions & 9 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,7 +59,6 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
batteryController {batteryController},
bleController {bleController},
dateTimeController {dateTimeController},
timerController {timerController},
alarmController {alarmController},
watchdog {watchdog},
notificationManager {notificationManager},
Expand Down Expand Up @@ -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...
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/systemtask/SystemTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 661ffbe

Please sign in to comment.