From 968efb86bfe1f55ee05ceb5fd83826014e06c509 Mon Sep 17 00:00:00 2001 From: mikeller Date: Sat, 11 Nov 2017 18:46:30 +1300 Subject: [PATCH] Added RTC date/time to OSD. --- src/main/common/time.c | 33 ++++++++++++++++++++++----------- src/main/common/time.h | 3 ++- src/main/fc/settings.c | 1 + src/main/io/osd.c | 35 ++++++++++++++++++++++++++++++++++- src/main/io/osd.h | 1 + 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/main/common/time.c b/src/main/common/time.c index f7003af868..fc4f66df65 100644 --- a/src/main/common/time.c +++ b/src/main/common/time.c @@ -131,7 +131,7 @@ static void dateTimeWithOffset(dateTime_t *dateTimeOffset, dateTime_t *dateTimeI rtcTimeToDateTime(dateTimeOffset, offsetTime); } -static bool dateTimeFormat(char *buf, dateTime_t *dateTime, int16_t offsetMinutes) +static bool dateTimeFormat(char *buf, dateTime_t *dateTime, int16_t offsetMinutes, bool shortVersion) { dateTime_t local; @@ -153,13 +153,19 @@ static bool dateTimeFormat(char *buf, dateTime_t *dateTime, int16_t offsetMinute retVal = false; } - // Changes to this format might require updates in - // dateTimeSplitFormatted() - // Datetime is in ISO_8601 format, https://en.wikipedia.org/wiki/ISO_8601 - tfp_sprintf(buf, "%04u-%02u-%02uT%02u:%02u:%02u.%03u%c%02d:%02d", - dateTime->year, dateTime->month, dateTime->day, - dateTime->hours, dateTime->minutes, dateTime->seconds, dateTime->millis, - tz_hours >= 0 ? '+' : '-', ABS(tz_hours), tz_minutes); + if (shortVersion) { + tfp_sprintf(buf, "%04u-%02u-%02u %02u:%02u:%02u", + dateTime->year, dateTime->month, dateTime->day, + dateTime->hours, dateTime->minutes, dateTime->seconds); + } else { + // Changes to this format might require updates in + // dateTimeSplitFormatted() + // Datetime is in ISO_8601 format, https://en.wikipedia.org/wiki/ISO_8601 + tfp_sprintf(buf, "%04u-%02u-%02uT%02u:%02u:%02u.%03u%c%02d:%02d", + dateTime->year, dateTime->month, dateTime->day, + dateTime->hours, dateTime->minutes, dateTime->seconds, dateTime->millis, + tz_hours >= 0 ? '+' : '-', ABS(tz_hours), tz_minutes); + } return retVal; } @@ -181,12 +187,17 @@ uint16_t rtcTimeGetMillis(rtcTime_t *t) bool dateTimeFormatUTC(char *buf, dateTime_t *dt) { - return dateTimeFormat(buf, dt, 0); + return dateTimeFormat(buf, dt, 0, false); } bool dateTimeFormatLocal(char *buf, dateTime_t *dt) { - return dateTimeFormat(buf, dt, timeConfig()->tz_offsetMinutes); + return dateTimeFormat(buf, dt, timeConfig()->tz_offsetMinutes, false); +} + +bool dateTimeFormatLocalShort(char *buf, dateTime_t *dt) +{ + return dateTimeFormat(buf, dt, timeConfig()->tz_offsetMinutes, true); } void dateTimeUTCToLocal(dateTime_t *utcDateTime, dateTime_t *localDateTime) @@ -247,4 +258,4 @@ bool rtcSetDateTime(dateTime_t *dt) return rtcSet(&t); } -#endif \ No newline at end of file +#endif diff --git a/src/main/common/time.h b/src/main/common/time.h index d858153b87..feb70638d2 100644 --- a/src/main/common/time.h +++ b/src/main/common/time.h @@ -76,6 +76,7 @@ typedef struct _dateTime_s { // buf must be at least FORMATTED_DATE_TIME_BUFSIZE bool dateTimeFormatUTC(char *buf, dateTime_t *dt); bool dateTimeFormatLocal(char *buf, dateTime_t *dt); +bool dateTimeFormatLocalShort(char *buf, dateTime_t *dt); void dateTimeUTCToLocal(dateTime_t *utcDateTime, dateTime_t *localDateTime); // dateTimeSplitFormatted splits a formatted date into its date @@ -91,4 +92,4 @@ bool rtcSet(rtcTime_t *t); bool rtcGetDateTime(dateTime_t *dt); bool rtcSetDateTime(dateTime_t *dt); -#endif \ No newline at end of file +#endif diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 9a91fd4326..06651fa777 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -731,6 +731,7 @@ const clivalue_t valueTable[] = { { "osd_nvario_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_NUMERICAL_VARIO]) }, { "osd_esc_tmp_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_TMP]) }, { "osd_esc_rpm_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_ESC_RPM]) }, + { "osd_rtc_date_time_pos", VAR_UINT16 | MASTER_VALUE, .config.minmax = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_RTC_DATETIME]) }, { "osd_stat_max_spd", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_SPEED])}, { "osd_stat_max_dist", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats[OSD_STAT_MAX_DISTANCE])}, diff --git a/src/main/io/osd.c b/src/main/io/osd.c index 61ea8b18a6..7283d5ab14 100755 --- a/src/main/io/osd.c +++ b/src/main/io/osd.c @@ -309,6 +309,22 @@ STATIC_UNIT_TESTED void osdFormatTimer(char *buff, bool showSymbol, int timerInd osdFormatTime(buff, OSD_TIMER_PRECISION(timer), osdGetTimerValue(src)); } +#ifdef USE_RTC_TIME +bool printRtcDateTime(char *buffer) +{ + dateTime_t dateTime; + if (!rtcGetDateTime(&dateTime)) { + buffer[0] = '\0'; + + return false; + } + + dateTimeFormatLocalShort(buffer, &dateTime); + + return true; +} +#endif + static void osdDrawSingleElement(uint8_t item) { if (!VISIBLE(osdConfig()->item_pos[item]) || BLINK(item)) { @@ -723,6 +739,11 @@ static void osdDrawSingleElement(uint8_t item) break; #endif +#ifdef USE_RTC_TIME + case OSD_RTC_DATETIME: + printRtcDateTime(&buff[0]); + break; +#endif default: return; } @@ -787,6 +808,11 @@ static void osdDrawElements(void) osdDrawSingleElement(OSD_ESC_RPM); } #endif + +#ifdef USE_RTC_TIME + osdDrawSingleElement(OSD_RTC_DATETIME); +#endif + } void pgResetFn_osdConfig(osdConfig_t *osdConfig) @@ -869,7 +895,14 @@ void osdInit(displayPort_t *osdDisplayPortToUse) displayWrite(osdDisplayPort, 11, 10, CMS_STARTUP_HELP_TEXT3); #endif - displayResync(osdDisplayPort); +#ifdef USE_RTC_TIME + char dateTimeBuffer[FORMATTED_DATE_TIME_BUFSIZE]; + if (printRtcDateTime(&dateTimeBuffer[0])) { + displayWrite(osdDisplayPort, 5, 12, dateTimeBuffer); + } +#endif + +displayResync(osdDisplayPort); resumeRefreshAt = micros() + (4 * REFRESH_1S); } diff --git a/src/main/io/osd.h b/src/main/io/osd.h index ebbfca448b..3826513883 100755 --- a/src/main/io/osd.h +++ b/src/main/io/osd.h @@ -83,6 +83,7 @@ typedef enum { OSD_COMPASS_BAR, OSD_ESC_TMP, OSD_ESC_RPM, + OSD_RTC_DATETIME, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e;