From 28182706a431ff628f7fb74524522da34bdb0a61 Mon Sep 17 00:00:00 2001 From: Pieter Kruger Date: Wed, 15 May 2019 09:47:31 +1000 Subject: [PATCH] Add OSD profile names feature --- src/main/cli/settings.c | 7 +++++++ src/main/cms/cms_menu_osd.c | 3 +++ src/main/osd/osd.c | 6 +++++- src/main/osd/osd.h | 4 ++++ src/main/osd/osd_elements.c | 29 ++++++++++++++++++++++++++++- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index e74e314b4c..a971af774e 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -1242,6 +1242,10 @@ const clivalue_t valueTable[] = { { "osd_pid_profile_name_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PID_PROFILE_NAME]) }, #endif +#ifdef USE_OSD_PROFILES + { "osd_profile_name_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, item_pos[OSD_PROFILE_NAME]) }, +#endif + // OSD stats enabled flags are stored as bitmapped values inside a 32bit parameter // It is recommended to keep the settings order the same as the enumeration. This way the settings are displayed in the cli in the same order making it easier on the users { "osd_stat_rtc_date_time", VAR_UINT32 | MASTER_VALUE | MODE_BITSET, .config.bitpos = OSD_STAT_RTC_DATE_TIME, PG_OSD_CONFIG, offsetof(osdConfig_t, enabled_stats)}, @@ -1274,6 +1278,9 @@ const clivalue_t valueTable[] = { #ifdef USE_OSD_PROFILES { "osd_profile", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, OSD_PROFILE_COUNT }, PG_OSD_CONFIG, offsetof(osdConfig_t, osdProfileIndex) }, + { "osd_profile_1_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, OSD_PROFILE_NAME_LENGTH, STRING_FLAGS_NONE }, PG_OSD_CONFIG, offsetof(osdConfig_t, profile[0]) }, + { "osd_profile_2_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, OSD_PROFILE_NAME_LENGTH, STRING_FLAGS_NONE }, PG_OSD_CONFIG, offsetof(osdConfig_t, profile[1]) }, + { "osd_profile_3_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, OSD_PROFILE_NAME_LENGTH, STRING_FLAGS_NONE }, PG_OSD_CONFIG, offsetof(osdConfig_t, profile[2]) }, #endif #endif diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index d5145ba2eb..e2ef8a8ec1 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -117,6 +117,9 @@ const OSD_Entry menuOsdActiveElemsEntries[] = #ifdef USE_PROFILE_NAMES {"PID PROFILE NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PID_PROFILE_NAME], DYNAMIC}, {"RATE PROFILE NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RATE_PROFILE_NAME], DYNAMIC}, +#endif +#ifdef USE_OSD_PROFILES + {"OSD PROFILE NAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_PROFILE_NAME], DYNAMIC}, #endif {"DEBUG", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_DEBUG], DYNAMIC}, {"WARNINGS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_WARNINGS], DYNAMIC}, diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index a37024aeb0..30c743a821 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -128,7 +128,7 @@ static uint8_t osdStatsRowCount = 0; escSensorData_t *osdEscDataCombined; #endif -PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 5); +PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 6); void osdStatSetState(uint8_t statIndex, bool enabled) { @@ -264,6 +264,10 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) osdConfig->osdProfileIndex = 1; osdConfig->ahInvert = false; + + for (int i=0; i < OSD_PROFILE_COUNT; i++) { + osdConfig->profile[i][0] = '\0'; + } } static void osdDrawLogo(int x, int y) diff --git a/src/main/osd/osd.h b/src/main/osd/osd.h index 603bfed972..fa0bf0e685 100644 --- a/src/main/osd/osd.h +++ b/src/main/osd/osd.h @@ -31,6 +31,8 @@ extern const char * const osdTimerSourceNames[OSD_NUM_TIMER_TYPES]; #define OSD_ELEMENT_BUFFER_LENGTH 32 +#define OSD_PROFILE_NAME_LENGTH 16 + #ifdef USE_OSD_PROFILES #define OSD_PROFILE_COUNT 3 #else @@ -128,6 +130,7 @@ typedef enum { OSD_ESC_RPM_FREQ, OSD_RATE_PROFILE_NAME, OSD_PID_PROFILE_NAME, + OSD_PROFILE_NAME, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; @@ -249,6 +252,7 @@ typedef struct osdConfig_s { uint8_t osdProfileIndex; uint8_t overlay_radio_mode; uint8_t link_quality_alarm; + char profile[OSD_PROFILE_COUNT][OSD_PROFILE_NAME_LENGTH + 1]; } osdConfig_t; PG_DECLARE(osdConfig_t, osdConfig); diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index 08d57f987b..1c558daa29 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -684,6 +684,27 @@ static void osdElementPidProfileName(osdElementParms_t *element) } #endif +#ifdef USE_OSD_PROFILES +static void osdElementOsdProfileName(osdElementParms_t *element) +{ + uint8_t profileIndex = getCurrentOsdProfileIndex(); + + if (strlen(osdConfig()->profile[profileIndex - 1]) == 0) { + tfp_sprintf(element->buff, "OSD_%u", profileIndex); + } else { + unsigned i; + for (i = 0; i < OSD_PROFILE_NAME_LENGTH; i++) { + if (osdConfig()->profile[profileIndex - 1][i]) { + element->buff[i] = toupper((unsigned char)osdConfig()->profile[profileIndex - 1][i]); + } else { + break; + } + } + element->buff[i] = '\0'; + } +} +#endif + #ifdef USE_ESC_SENSOR static void osdElementEscTemperature(osdElementParms_t *element) { @@ -1373,6 +1394,10 @@ static const uint8_t osdElementDisplayOrder[] = { OSD_RATE_PROFILE_NAME, OSD_PID_PROFILE_NAME, #endif +#ifdef USE_OSD_PROFILES + OSD_PROFILE_NAME, +#endif + }; // Define the mapping between the OSD element id and the function to draw it @@ -1472,7 +1497,9 @@ const osdElementDrawFn osdElementDrawFunction[OSD_ITEM_COUNT] = { [OSD_RATE_PROFILE_NAME] = osdElementRateProfileName, [OSD_PID_PROFILE_NAME] = osdElementPidProfileName, #endif - +#ifdef USE_OSD_PROFILES + [OSD_PROFILE_NAME] = osdElementOsdProfileName, +#endif }; static void osdAddActiveElement(osd_items_e element)