|
@@ -105,6 +105,10 @@ static void display_time() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static uint16_t min(uint16_t a, uint16_t b) {
|
|
|
+ return (a < b) ? a : b;
|
|
|
+}
|
|
|
+
|
|
|
static uint16_t max(uint16_t a, uint16_t b) {
|
|
|
return (a > b) ? a : b;
|
|
|
}
|
|
@@ -112,7 +116,12 @@ static uint16_t max(uint16_t a, uint16_t b) {
|
|
|
static uint64_t determine_sleep_time(struct tm *local_time) {
|
|
|
uint16_t wakeup_time_sec;
|
|
|
if (!should_enable_display(local_time->tm_hour)) {
|
|
|
- wakeup_time_sec = HALF_HOUR_IN_SECONDS;
|
|
|
+ if (local_time->tm_hour == 5) {
|
|
|
+ wakeup_time_sec = min((60 - local_time->tm_min) * 60
|
|
|
+ + (60 - local_time->tm_sec), HALF_HOUR_IN_SECONDS);
|
|
|
+ } else {
|
|
|
+ wakeup_time_sec = HALF_HOUR_IN_SECONDS;
|
|
|
+ }
|
|
|
} else {
|
|
|
wakeup_time_sec = 60 - local_time->tm_sec;
|
|
|
}
|