summaryrefslogtreecommitdiff
path: root/src/components/alarm
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-04-17 11:13:41 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-04-17 13:16:10 (GMT)
commitaca605d4fb4040cc80c1acf101023aa86e7694ba (patch)
tree5f83db7a5bfbf05d732121bb95ca383243cc8eaf /src/components/alarm
parentc372ba1908bb861d7f05d057c7fc25202c34bbe3 (diff)
Differentiate time adjustment (< 3h for example time zone change when crossing a border or because of daylight saving) and time setting (for example when the firmware is booted for the first time and the companion app sends the time)
Diffstat (limited to 'src/components/alarm')
-rw-r--r--src/components/alarm/AlarmController.cpp19
-rw-r--r--src/components/alarm/AlarmController.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index c86ff73..5432e75 100644
--- a/src/components/alarm/AlarmController.cpp
+++ b/src/components/alarm/AlarmController.cpp
@@ -44,6 +44,25 @@ void AlarmController::SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin) {
minutes = alarmMin;
}
+void AlarmController::OnAdjustTime() {
+
+ if (state != AlarmState::Set) {
+ return;
+ }
+
+ xTimerStop(alarmAppTimer, 0);
+ auto now = dateTimeController.CurrentDateTime();
+
+ if (now > alarmTime) {
+ xTimerChangePeriod(alarmAppTimer, 1, 0);
+ } else {
+ auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
+ xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0);
+ }
+
+ xTimerStart(alarmAppTimer, 0);
+}
+
void AlarmController::ScheduleAlarm() {
// Determine the next time the alarm needs to go off and set the timer
xTimerStop(alarmAppTimer, 0);
diff --git a/src/components/alarm/AlarmController.h b/src/components/alarm/AlarmController.h
index 099de8b..6ad220f 100644
--- a/src/components/alarm/AlarmController.h
+++ b/src/components/alarm/AlarmController.h
@@ -33,6 +33,7 @@ namespace Pinetime {
void SetAlarmTime(uint8_t alarmHr, uint8_t alarmMin);
void ScheduleAlarm();
+ void OnAdjustTime();
void DisableAlarm();
void SetOffAlarmNow();
uint32_t SecondsToAlarm();