From 25034cccdfbdd75a7370afa80c24d758c52868ad Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Wed, 29 Sep 2021 19:25:25 +0300 Subject: [PATCH] Fixes based on code review --- src/components/alarm/AlarmController.cpp | 12 +++++------- src/components/alarm/AlarmController.h | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index bc9fcce89e..aaf4226307 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -47,10 +47,9 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) { minutes = alarmMin; } -std::chrono::time_point AlarmController::TimePoint() { +std::chrono::time_point AlarmController::CalculateAlarmTimePoint() { 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(now); tm* tmAlarmTime = std::localtime(&ttAlarmTime); // If the time being set has already passed today,the alarm should be set for tomorrow @@ -82,8 +81,7 @@ void AlarmController::ScheduleAlarm() { // Determine the next time the alarm needs to go off and set the app_timer app_timer_stop(alarmAppTimer); - alarmTime = TimePoint(); - auto mSecToAlarm = std::chrono::duration_cast(alarmTime - dateTimeController.CurrentDateTime()).count(); + auto mSecToAlarm = std::chrono::duration_cast(CalculateAlarmTimePoint() - dateTimeController.CurrentDateTime()).count(); app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this); state = AlarmState::Set; @@ -91,9 +89,9 @@ void AlarmController::ScheduleAlarm() { uint32_t AlarmController::SecondsToAlarm() { if (state == AlarmState::Set) { - return std::chrono::duration_cast(alarmTime - dateTimeController.CurrentDateTime()).count(); + return std::chrono::duration_cast(CalculateAlarmTimePoint() - dateTimeController.CurrentDateTime()).count(); } else { - return std::chrono::duration_cast(TimePoint() - dateTimeController.CurrentDateTime()).count(); + return std::chrono::duration_cast(CalculateAlarmTimePoint() - dateTimeController.CurrentDateTime()).count(); } } diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h index bc70f2257c..4676ec401c 100644 --- a/src/components/alarm/AlarmController.h +++ b/src/components/alarm/AlarmController.h @@ -33,7 +33,6 @@ namespace Pinetime { void Init(System::SystemTask* systemTask); void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin); - std::chrono::time_point TimePoint(); void ScheduleAlarm(); void DisableAlarm(); void SetOffAlarmNow(); @@ -58,11 +57,12 @@ namespace Pinetime { } private: + std::chrono::time_point CalculateAlarmTimePoint(); + Controllers::DateTime& dateTimeController; System::SystemTask* systemTask = nullptr; uint8_t hours = 7; uint8_t minutes = 0; - std::chrono::time_point alarmTime; AlarmState state = AlarmState::Not_Set; RecurType recurrence = RecurType::None; };