Skip to content

Commit 206b17c

Browse files
committed
[app-settings] Fixed RTC setting.
1 parent c3a0ef5 commit 206b17c

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

applications/settings/modules/module.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,25 +397,30 @@ static void SetupBootSettings() {
397397

398398
static void update_rtc_ui() {
399399
char buf[5];
400-
struct tm time;
401-
402-
rtc_gettimeutc(&time);
403-
404-
sprintf(buf,"%04d",time.tm_year + 1900);
405-
GUI_TextEntrySetText(self.sysdate[0], buf);
406-
sprintf(buf,"%02d",time.tm_mon + 1);
407-
GUI_TextEntrySetText(self.sysdate[1], buf);
408-
sprintf(buf,"%02d",time.tm_mday);
409-
GUI_TextEntrySetText(self.sysdate[2], buf);
410-
sprintf(buf,"%02d",time.tm_hour);
411-
GUI_TextEntrySetText(self.sysdate[3], buf);
412-
sprintf(buf,"%02d",time.tm_min);
413-
GUI_TextEntrySetText(self.sysdate[4], buf);
400+
struct tm *time;
401+
time_t unix_time;
402+
403+
unix_time = rtc_unix_secs();
404+
time = gmtime(&unix_time);
405+
406+
if (time != NULL) {
407+
sprintf(buf, "%04d", time->tm_year + 1900);
408+
GUI_TextEntrySetText(self.sysdate[0], buf);
409+
sprintf(buf, "%02d", time->tm_mon + 1);
410+
GUI_TextEntrySetText(self.sysdate[1], buf);
411+
sprintf(buf, "%02d", time->tm_mday);
412+
GUI_TextEntrySetText(self.sysdate[2], buf);
413+
sprintf(buf, "%02d", time->tm_hour);
414+
GUI_TextEntrySetText(self.sysdate[3], buf);
415+
sprintf(buf, "%02d", time->tm_min);
416+
GUI_TextEntrySetText(self.sysdate[4], buf);
417+
}
414418
}
415419

416420
void SettingsApp_TimeChange(GUI_Widget *widget)
417421
{
418422
struct tm time;
423+
time_t unix_time;
419424

420425
if(strcmp(GUI_ObjectGetName(widget), "get-time") == 0)
421426
{
@@ -429,7 +434,11 @@ void SettingsApp_TimeChange(GUI_Widget *widget)
429434
time.tm_mday = atoi(GUI_TextEntryGetText(self.sysdate[2]));
430435
time.tm_mon = atoi(GUI_TextEntryGetText(self.sysdate[1])) - 1;
431436
time.tm_year = atoi(GUI_TextEntryGetText(self.sysdate[0])) - 1900;
432-
rtc_settimeutc(&time);
437+
438+
unix_time = mktime(&time);
439+
if(unix_time != -1) {
440+
rtc_set_unix_secs(unix_time);
441+
}
433442
}
434443
else if(strcmp(GUI_ObjectGetName(widget), "sync-time") == 0)
435444
{

0 commit comments

Comments
 (0)