diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-06-06 15:47:43 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-06 15:47:43 (GMT) |
| commit | 35dcf8c8607483c104711c9398d47d57147f4389 (patch) | |
| tree | b2c17823827af9233dff152d918fb829cc939ad8 /src/components/alarm/AlarmController.cpp | |
| parent | f95147cf0ed759a6ae30ac8d7cfdf7eba23a3ee9 (diff) | |
Switch to freertos timers (#1095)
* Use FreeRTOS timer for AlarmController
* Use FreeRTOS timer for MotorController
* Remove app_timer component from compilation as we now solely use
FreeROTS timer
* Simplify variable and text names for AlarmController and MotorController timers
* Call ScheduleAlarm directly from StopAlerting, for recurring timers
Co-authored-by: Riku Isokoski <riksu9000@gmail.com>
Co-authored-by: NeroBurner <pyro4hell@gmail.com>
Diffstat (limited to 'src/components/alarm/AlarmController.cpp')
| -rw-r--r-- | src/components/alarm/AlarmController.cpp | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index d412273..9f4e910 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -17,7 +17,6 @@ */ #include "components/alarm/AlarmController.h" #include "systemtask/SystemTask.h" -#include "app_timer.h" #include "task.h" #include <chrono> @@ -27,20 +26,16 @@ using namespace std::chrono_literals; AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { } -APP_TIMER_DEF(alarmAppTimer); - namespace { - void SetOffAlarm(void* p_context) { - auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(p_context); - if (controller != nullptr) { - controller->SetOffAlarmNow(); - } + void SetOffAlarm(TimerHandle_t xTimer) { + auto controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer)); + controller->SetOffAlarmNow(); } } void AlarmController::Init(System::SystemTask* systemTask) { - app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm); this->systemTask = systemTask; + alarmTimer = xTimerCreate("Alarm", 1, pdFALSE, this, SetOffAlarm); } void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { @@ -49,8 +44,8 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { } void AlarmController::ScheduleAlarm() { - // Determine the next time the alarm needs to go off and set the app_timer - app_timer_stop(alarmAppTimer); + // Determine the next time the alarm needs to go off and set the timer + xTimerStop(alarmTimer, 0); auto now = dateTimeController.CurrentDateTime(); alarmTime = now; @@ -80,8 +75,9 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); - auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count(); - app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this); + auto secondsToAlarm = std::chrono::duration_cast<std::chrono::seconds>(alarmTime - now).count(); + xTimerChangePeriod(alarmTimer, secondsToAlarm * configTICK_RATE_HZ, 0); + xTimerStart(alarmTimer, 0); state = AlarmState::Set; } @@ -91,7 +87,7 @@ uint32_t AlarmController::SecondsToAlarm() { } void AlarmController::DisableAlarm() { - app_timer_stop(alarmAppTimer); + xTimerStop(alarmTimer, 0); state = AlarmState::Not_Set; } @@ -101,14 +97,12 @@ void AlarmController::SetOffAlarmNow() { } void AlarmController::StopAlerting() { - systemTask->PushMessage(System::Messages::StopRinging); - // Alarm state is off unless this is a recurring alarm if (recurrence == RecurType::None) { state = AlarmState::Not_Set; } else { - state = AlarmState::Set; // set next instance ScheduleAlarm(); } + systemTask->PushMessage(System::Messages::StopRinging); } |
