summaryrefslogtreecommitdiff
path: root/src/components/alarm/AlarmController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/alarm/AlarmController.cpp')
-rw-r--r--src/components/alarm/AlarmController.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index 5432e75..596bcaf 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>
@@ -36,7 +35,7 @@ namespace {
void AlarmController::Init(System::SystemTask* systemTask) {
this->systemTask = systemTask;
- alarmAppTimer = xTimerCreate("alarmAppTm", 1, pdFALSE, this, SetOffAlarm);
+ alarmTimer = xTimerCreate("Alarm", 1, pdFALSE, this, SetOffAlarm);
}
void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
@@ -65,11 +64,11 @@ void AlarmController::OnAdjustTime() {
void AlarmController::ScheduleAlarm() {
// Determine the next time the alarm needs to go off and set the timer
- xTimerStop(alarmAppTimer, 0);
+ xTimerStop(alarmTimer, 0);
auto now = dateTimeController.CurrentDateTime();
alarmTime = now;
- time_t ttAlarmTime = std::chrono::system_clock::to_time_t(alarmTime);
+ time_t ttAlarmTime = std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(alarmTime));
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
// If the time being set has already passed today,the alarm should be set for tomorrow
@@ -95,9 +94,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();
- xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
- xTimerStart(alarmAppTimer, 0);
+ 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;
}
@@ -107,7 +106,7 @@ uint32_t AlarmController::SecondsToAlarm() {
}
void AlarmController::DisableAlarm() {
- xTimerStop(alarmAppTimer, 0);
+ xTimerStop(alarmTimer, 0);
state = AlarmState::Not_Set;
}
@@ -117,20 +116,12 @@ void AlarmController::SetOffAlarmNow() {
}
void AlarmController::StopAlerting() {
- systemTask->PushMessage(System::Messages::StopRinging);
-}
-
-void AlarmController::OnStopRinging() {
- if (state != AlarmState::Alerting) {
- return;
- }
-
// 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);
}