Merge PR #268 - add daylight savings time toggle

Adds a toggle in the preferences face that allows the user
to enable or disable the daylight savings time.

Should help produce the correct results with the sunrise/sunset presets.

A proper solution would be to integrate the tzinfo database
but it's too big for the watch at the time of this writing.
Can't be done unless it can be shrunk down into a subset
the user would be interested. Even then it's a stopgap
since the database is likely to keep growing over time.

Reviewed-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
GitHub-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/268
This commit is contained in:
Matheus Afonso Martins Moreira
2024-09-08 11:09:10 -03:00
3 changed files with 125 additions and 4 deletions

View File

@@ -27,8 +27,8 @@
#include "watch.h"
#include "watch_utility.h"
#define SET_TIME_FACE_NUM_SETTINGS (7)
const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO"};
#define SET_TIME_FACE_NUM_SETTINGS (8)
const char set_time_face_titles[SET_TIME_FACE_NUM_SETTINGS][3] = {"HR", "M1", "SE", "YR", "MO", "DA", "ZO", "DS"};
static bool _quick_ticks_running;
@@ -59,6 +59,16 @@ static void _handle_alarm_button(movement_settings_t *settings, watch_date_time
settings->bit.time_zone++;
if (settings->bit.time_zone > 40) settings->bit.time_zone = 0;
break;
case 7: // daylight savings time
if (settings->bit.dst_active) { // deactivate DST
date_time.unit.hour = (date_time.unit.hour + 24 - 1) % 24;
settings->bit.time_zone = movement_dst_inverse_jump_table[settings->bit.time_zone];
} else { // activate DST
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
settings->bit.time_zone = movement_dst_jump_table[settings->bit.time_zone];
}
settings->bit.dst_active = !settings->bit.dst_active;
break;
}
if (date_time.unit.day > days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR))
date_time.unit.day = 1;
@@ -145,7 +155,7 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
watch_clear_indicator(WATCH_INDICATOR_24H);
watch_clear_indicator(WATCH_INDICATOR_PM);
sprintf(buf, "%s %2d%02d%02d", set_time_face_titles[current_page], date_time.unit.year + 20, date_time.unit.month, date_time.unit.day);
} else {
} else if (current_page < 7) { // zone
if (event.subsecond % 2) {
watch_clear_colon();
sprintf(buf, "%s ", set_time_face_titles[current_page]);
@@ -153,6 +163,10 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
watch_set_colon();
sprintf(buf, "%s %3d%02d ", set_time_face_titles[current_page], (int8_t) (movement_timezone_offsets[settings->bit.time_zone] / 60), (int8_t) (movement_timezone_offsets[settings->bit.time_zone] % 60) * (movement_timezone_offsets[settings->bit.time_zone] < 0 ? -1 : 1));
}
} else { // daylight savings
watch_clear_colon();
if (settings->bit.dst_active) sprintf(buf, "%s dsT y", set_time_face_titles[current_page]);
else sprintf(buf, "%s dsT n", set_time_face_titles[current_page]);
}
// blink up the parameter we're setting
@@ -170,6 +184,9 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
case 5:
buf[8] = buf[9] = ' ';
break;
case 7:
buf[9] = ' ';
break;
}
}