const char *rtc_show_val_cb(guiObject_t *obj, const void *data) { (void)obj; u32 time = RTC_GetValue(); switch ((long)data) { case 0: // second sprintf(rp->tmpstr, "%02d", RTC_GetTimeValue(time) % 60); break; case 1: // minute sprintf(rp->tmpstr, "%02d", (RTC_GetTimeValue(time) / 60) % 60); break; case 2: // hour sprintf(rp->tmpstr, "%02d", (RTC_GetTimeValue(time) / 3600) % 24); break; case 3: // day RTC_GetDateStringLong(rp->tmpstr,time); rp->tmpstr[rp->tmpstr[1] == '.' ? 1 : 2] = 0; break; case 4: // month RTC_GetDateStringLong(rp->tmpstr,RTC_GetValue()); int idx = (rp->tmpstr[1] == '.' ? 1 : 2); rp->tmpstr[idx+3] = 0; return rp->tmpstr + idx + 1; case 5: // year RTC_GetDateStringLong(rp->tmpstr,RTC_GetValue()); return rp->tmpstr + (rp->tmpstr[1] == '.' ? 1 : 2) + 4; } return rp->tmpstr; }
const char *show_date_cb(guiObject_t *obj, const void *data) { (void)obj; (void)data; RTC_GetDateStringLong(tempstring, RTC_GetValue()); return tempstring; }
void PAGE_RTCInit(int page) { (void)page; PAGE_SetModal(1); PAGE_RemoveAllObjects(); PAGE_ShowHeader_ExitOnly(PAGE_GetName(PAGEID_RTC), okcancel_cb); u32 time = RTC_GetValue(); u32 timevalue = RTC_GetTimeValue(time); Rtc.value[HOUR] = (u16)(timevalue / 3600); Rtc.value[MINUTE] = (u16)(timevalue % 3600) / 60; Rtc.value[SECOND] = (u16)(timevalue % 60); RTC_GetDateStringLong(tempstring,time); int idx = (tempstring[1] == '.' ? 1 : 2); tempstring[idx] = 0; tempstring[idx+3] = 0; Rtc.value[DAY] = atoi(tempstring); Rtc.value[MONTH] = atoi(tempstring + idx + 1); Rtc.value[YEAR] = atoi(tempstring + idx + 4); min[SECOND] = 0; max[SECOND] = 59; min[MINUTE] = 0; max[MINUTE] = 59; min[HOUR] = 0; max[HOUR] = 23; min[DAY] = 1; max[DAY] = daysInMonth[Rtc.value[MONTH] - 1] + (((Rtc.value[YEAR] % 4) == 0) && (Rtc.value[MONTH] == 2) ? 1 : 0); min[MONTH] = 1; max[MONTH] = 12; min[YEAR] = RTC_STARTYEAR; max[YEAR] = RTC_STARTYEAR + 67; _show_page(); }
const char *rtc_show_val_cb(guiObject_t *obj, const void *data) { (void)obj; u32 time = RTC_GetValue(); switch ((long)data) { case SECOND: sprintf(tempstring, "%2d", RTC_GetTimeValue(time) % 60); break; case MINUTE: sprintf(tempstring, "%2d", (RTC_GetTimeValue(time) / 60) % 60); break; case HOUR: { u32 value = RTC_GetTimeValue(time) / 3600; if (Transmitter.rtcflags & CLOCK12HR) { u8 hour = value % 12; if (hour == 0) hour = 12; sprintf(tempstring, "%2d %s", hour, value > 12? "PM" : "AM"); } else { sprintf(tempstring, "%2d", value % 24); } break; } case DAY: RTC_GetDateStringLong(tempstring, time); tempstring[tempstring[1] == '.' ? 1 : 2] = 0; break; case MONTH: RTC_GetDateStringLong(tempstring, time); int idx = (tempstring[1] == '.' ? 1 : 2); tempstring[idx+3] = 0; if (tempstring[idx + 1] == '0') idx++; return tempstring + idx + 1; case YEAR: RTC_GetDateStringLong(tempstring, time); return tempstring + (tempstring[1] == '.' ? 1 : 2) + 4; } return tempstring; }
void PAGE_RTCInit(int page) { (void)page; PAGE_SetModal(1); PAGE_RemoveAllObjects(); PAGE_ShowHeader_ExitOnly(PAGE_GetName(PAGEID_RTC), okcancel_cb); u32 time = RTC_GetValue(); u32 timevalue = RTC_GetTimeValue(time); Rtc.value[2] = (u16)(timevalue / 3600); Rtc.value[1] = (u16)(timevalue % 3600) / 60; Rtc.value[0] = (u16)(timevalue % 60); RTC_GetDateStringLong(rp->tmpstr,time); int idx = (rp->tmpstr[1] == '.' ? 1 : 2); rp->tmpstr[idx] = 0; rp->tmpstr[idx+3] = 0; Rtc.value[3] = atoi(rp->tmpstr); Rtc.value[4] = atoi(rp->tmpstr + idx + 1); Rtc.value[5] = atoi(rp->tmpstr + idx + 4); _show_page(); }