1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Merge pull request #4543 from mikeller/added_rtc_date_time_to_osd

Added RTC date/time to OSD.
This commit is contained in:
Michael Keller 2017-11-12 03:17:55 +13:00 committed by GitHub
commit 41806636d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,6 +153,11 @@ static bool dateTimeFormat(char *buf, dateTime_t *dateTime, int16_t offsetMinute
retVal = false;
}
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
@ -160,6 +165,7 @@ static bool dateTimeFormat(char *buf, dateTime_t *dateTime, int16_t offsetMinute
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)

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

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)) {
@ -717,6 +733,11 @@ static void osdDrawSingleElement(uint8_t item)
break;
#endif
#ifdef USE_RTC_TIME
case OSD_RTC_DATETIME:
printRtcDateTime(&buff[0]);
break;
#endif
default:
return;
}
@ -781,6 +802,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)
@ -863,7 +889,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;