Consider RTC time UTC instead of local time, applying timezone

replace/11864cadc199ddd246f90fbb462b3f4c46954858
Federico Amedeo Izzo 2021-02-13 22:11:25 +01:00
rodzic ebe87b22e2
commit 31552ff2b2
3 zmienionych plików z 23 dodań i 1 usunięć

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -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