17
17
*/
18
18
#include " components/alarm/AlarmController.h"
19
19
#include " systemtask/SystemTask.h"
20
- #include " app_timer.h"
21
20
#include " task.h"
22
21
#include < chrono>
23
22
@@ -27,20 +26,16 @@ using namespace std::chrono_literals;
27
26
AlarmController::AlarmController (Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
28
27
}
29
28
30
- APP_TIMER_DEF (alarmAppTimer);
31
-
32
29
namespace {
33
- void SetOffAlarm (void * p_context) {
34
- auto * controller = static_cast <Pinetime::Controllers::AlarmController*>(p_context);
35
- if (controller != nullptr ) {
36
- controller->SetOffAlarmNow ();
37
- }
30
+ void SetOffAlarm (TimerHandle_t xTimer) {
31
+ auto controller = static_cast <Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID (xTimer));
32
+ controller->SetOffAlarmNow ();
38
33
}
39
34
}
40
35
41
36
void AlarmController::Init (System::SystemTask* systemTask) {
42
- app_timer_create (&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm);
43
37
this ->systemTask = systemTask;
38
+ alarmTimer = xTimerCreate (" Alarm" , 1 , pdFALSE, this , SetOffAlarm);
44
39
}
45
40
46
41
void AlarmController::SetAlarmTime (uint8_t alarmHr, uint8_t alarmMin) {
@@ -49,8 +44,8 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
49
44
}
50
45
51
46
void AlarmController::ScheduleAlarm () {
52
- // Determine the next time the alarm needs to go off and set the app_timer
53
- app_timer_stop (alarmAppTimer );
47
+ // Determine the next time the alarm needs to go off and set the timer
48
+ xTimerStop (alarmTimer, 0 );
54
49
55
50
auto now = dateTimeController.CurrentDateTime ();
56
51
alarmTime = now;
@@ -80,8 +75,9 @@ void AlarmController::ScheduleAlarm() {
80
75
81
76
// now can convert back to a time_point
82
77
alarmTime = std::chrono::system_clock::from_time_t (std::mktime (tmAlarmTime));
83
- auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count ();
84
- app_timer_start (alarmAppTimer, APP_TIMER_TICKS (mSecToAlarm ), this );
78
+ auto secondsToAlarm = std::chrono::duration_cast<std::chrono::seconds>(alarmTime - now).count ();
79
+ xTimerChangePeriod (alarmTimer, secondsToAlarm * configTICK_RATE_HZ, 0 );
80
+ xTimerStart (alarmTimer, 0 );
85
81
86
82
state = AlarmState::Set;
87
83
}
@@ -91,7 +87,7 @@ uint32_t AlarmController::SecondsToAlarm() {
91
87
}
92
88
93
89
void AlarmController::DisableAlarm () {
94
- app_timer_stop (alarmAppTimer );
90
+ xTimerStop (alarmTimer, 0 );
95
91
state = AlarmState::Not_Set;
96
92
}
97
93
@@ -101,14 +97,12 @@ void AlarmController::SetOffAlarmNow() {
101
97
}
102
98
103
99
void AlarmController::StopAlerting () {
104
- systemTask->PushMessage (System::Messages::StopRinging);
105
-
106
100
// Alarm state is off unless this is a recurring alarm
107
101
if (recurrence == RecurType::None) {
108
102
state = AlarmState::Not_Set;
109
103
} else {
110
- state = AlarmState::Set;
111
104
// set next instance
112
105
ScheduleAlarm ();
113
106
}
107
+ systemTask->PushMessage (System::Messages::StopRinging);
114
108
}
0 commit comments