static void rtc_set_time_unix(time_t t) { RTCDateTime timespec; struct tm tim; localtime_r(&t, &tim); rtcConvertStructTmToDateTime(&tim, 0, ×pec); rtcSetTime(&RTCD1, ×pec); }
/** * @brief Converts time from seconds/milliseconds to timespec. * * @param[in] tv_sec seconds value * @param[in] tv_msec milliseconds value * @param[out] timespec pointer to a @p RTCDateTime structure * * @notapi */ static void rtc_decode(uint32_t tv_sec, uint32_t tv_msec, RTCDateTime *timespec) { struct tm tim; struct tm *t; /* If the conversion is successful the function returns a pointer to the object the result was written into.*/ #if defined(__GNUC__) || defined(__CC_ARM) t = localtime_r((time_t *)&(tv_sec), &tim); osalDbgAssert(t != NULL, "conversion failed"); #else struct tm *t = localtime(&tv_sec); memcpy(&tim, t, sizeof(struct tm)); #endif rtcConvertStructTmToDateTime(&tim, tv_msec, timespec); }
static void rtc_set_time(struct tm *tim) { RTCDateTime timespec; rtcConvertStructTmToDateTime(tim, 0, ×pec); rtcSetTime(&RTCD1, ×pec); }
static THD_FUNCTION(ThreadGFXEvent, arg) { (void)arg; chRegSetThreadName("GFXEvent"); GEvent* pe; static RTCDateTime timespec; struct tm timeinfo; struct tm tim; struct tm *canary; static time_t unix_time; while (true) { pe = geventEventWait(&gl, TIME_INFINITE); switch (pe->type) { case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->gwin == ghBtnSettings) { createSettingsFrame(); gwinShow(ghFrame1); updateGraph = false; updateSettingTime = true; } else if (((GEventGWinButton*)pe)->gwin == ghBtnSave) { timeinfo.tm_hour = atoi(gwinListGetSelectedText(ghListHour)); timeinfo.tm_min = atoi(gwinListGetSelectedText(ghListMin)); timeinfo.tm_sec = 0; timeinfo.tm_mday = atoi(gwinListGetSelectedText(ghListDay)); timeinfo.tm_mon = gwinListGetSelected(ghListMonth); timeinfo.tm_year = atoi(gwinListGetSelectedText(ghListYear))-1900; unix_time = mktime(&timeinfo); canary = localtime_r(&unix_time, &tim); osalDbgCheck(&tim == canary); rtcConvertStructTmToDateTime(&tim, 0, ×pec); rtcSetTime(RTC_DRIVER, ×pec); } else if (((GEventGWinButton*)pe)->gwin == ghBtnTime) { updateGraph = false; gwinShow(ghListFreq); } break; case GEVENT_GWIN_CHECKBOX: if (((GEventGWinCheckbox*)pe)->gwin == ghCheckBoxHR) { if (((GEventGWinCheckbox*)pe)->isChecked) use12HR = true; else use12HR = false; } break; case GEVENT_GWIN_CLOSE: updateGraph = true; updateSettingTime = false; switch (activeGraph) { case 0: drawGraphLines(ghContainerGraphC); break; case 1: drawGraphLines(ghContainerGraphV); break; case 2: drawGraphLines(ghContainerGraphW); break; case 3: drawGraphLines(ghContainerGraphCV_1); drawGraphLines(ghContainerGraphCV_2); break; default: break; } break; case GEVENT_GWIN_RADIO: activeGraph = atoi(gwinGetText(((GEventGWinRadio *)pe)->gwin)); setActiveGraph(activeGraph); break; case GEVENT_GWIN_LIST: if (((GEventGWinList*)pe)->gwin == ghListFreq) { char str[5]; uint8_t val = atoi(gwinListGetSelectedText(ghListFreq)); GRAPH_Refresh = ((1.0/val)*1000); snprintf(str, 5, "%d%s", val, "Hz"); gwinSetText(ghBtnTime, str, true); chThdSleepMilliseconds(10); gwinHide(ghListFreq); updateGraph = true; switch (activeGraph) { case 0: drawGraphLines(ghContainerGraphC); break; case 1: drawGraphLines(ghContainerGraphV); break; case 2:palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOA, 5); drawGraphLines(ghContainerGraphW); break; case 3: drawGraphLines(ghContainerGraphCV_1); drawGraphLines(ghContainerGraphCV_2); break; default: break; } } break; default: break; } chThdSleepMilliseconds(500); } }