Added RTC date/time to OSD.

This commit is contained in:
mikeller 2017-11-11 18:46:30 +13:00
parent 0c84506336
commit 968efb86bf
5 changed files with 60 additions and 13 deletions

View File

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

View File

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

View File

@ -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])},

View File

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

View File

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