From 31552ff2b20d6ffff97a5c54e9f8f842d0c01e11 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sat, 13 Feb 2021 22:11:25 +0100 Subject: [PATCH] Consider RTC time UTC instead of local time, applying timezone --- openrtx/src/state.c | 11 +++++++++++ openrtx/src/threads.c | 1 + openrtx/src/ui/ui.c | 12 +++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 41da64b0..243737c3 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -37,6 +37,7 @@ void state_init() state.radioStateUpdated = true; #ifdef HAS_RTC state.time = rtc_getTime(); + state_applyTimezone(); #endif state.v_bat = platform_getVbat(); state.charge = battery_getCharge(state.v_bat); @@ -74,3 +75,13 @@ void state_init() state.settings.brightness = 255; state.settings.contrast = 84; } + +state_applyTimezone() +{ + if(state.time.hour + state.settings.utc_timezone >= 24) + state.time.hour = state.time.hour - 24 + state.settings.utc_timezone; + else if(state.time.hour + state.settings.utc_timezone < 0) + state.time.hour = state.time.hour + 24 + state.settings.utc_timezone; + else + state.time.hour += state.settings.utc_timezone; +} diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index 6a89debd..1f929453 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -253,6 +253,7 @@ static void dev_task(void *arg) #ifdef HAS_RTC state.time = rtc_getTime(); + state_applyTimezone(); #endif state.v_bat = platform_getVbat(); state.charge = battery_getCharge(state.v_bat); diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 82751540..a9652103 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -987,6 +987,15 @@ void ui_updateFSM(event_t event, bool *sync_rtx) if(ui_state.input_position < TIMEDATE_DIGITS) break; // Return to Time&Date menu, saving values + // NOTE: The user inserted a local time, we save an UTC time to the RTC + if(ui_state.new_timedate.hour - state.settings.utc_timezone >= 24) + ui_state.new_timedate.hour = ui_state.new_timedate.hour - 24 - + state.settings.utc_timezone; + else if(ui_state.new_timedate.hour - state.settings.utc_timezone < 0) + ui_state.new_timedate.hour = ui_state.new_timedate.hour + 24 - + state.settings.utc_timezone; + else + ui_state.new_timedate.hour += state.settings.utc_timezone; rtc_setTime(ui_state.new_timedate); state.ui_screen = SETTINGS_TIMEDATE; } @@ -999,7 +1008,8 @@ void ui_updateFSM(event_t event, bool *sync_rtx) break; ui_state.input_position += 1; ui_state.input_number = input_getPressedNumber(msg); - _ui_timedate_add_digit(&ui_state.new_timedate, ui_state.input_position, ui_state.input_number); + _ui_timedate_add_digit(&ui_state.new_timedate, ui_state.input_position, + ui_state.input_number); } break; #endif