From 0652767f1c99bf5ec1ecc4ab171603ee5d310b7b Mon Sep 17 00:00:00 2001 From: Alexey Stankevich Date: Thu, 10 Jun 2021 01:06:08 +0300 Subject: [PATCH 1/2] Add OSD element for Aux channel value --- src/main/cli/settings.c | 4 ++++ src/main/cms/cms_menu_osd.c | 1 + src/main/osd/osd.c | 12 ++++++++++++ src/main/osd/osd.h | 5 +++++ src/main/osd/osd_elements.c | 7 +++++++ 5 files changed, 29 insertions(+) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index dbeae62459..167b0e6ee9 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -1413,6 +1413,7 @@ const clivalue_t valueTable[] = { { "osd_camera_frame_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_ELEMENT_CONFIG, offsetof(osdElementConfig_t, item_pos[OSD_CAMERA_FRAME]) }, { "osd_efficiency_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_ELEMENT_CONFIG, offsetof(osdElementConfig_t, item_pos[OSD_EFFICIENCY]) }, { "osd_total_flights_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_ELEMENT_CONFIG, offsetof(osdElementConfig_t, item_pos[OSD_TOTAL_FLIGHTS]) }, + { "osd_aux_pos", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 0, OSD_POSCFG_MAX }, PG_OSD_ELEMENT_CONFIG, offsetof(osdElementConfig_t, item_pos[OSD_AUX_VALUE]) }, // 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 @@ -1462,6 +1463,9 @@ const clivalue_t valueTable[] = { { "osd_stat_avg_cell_value", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_OSD_CONFIG, offsetof(osdConfig_t, stat_show_cell_value) }, { "osd_task_frequency", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { OSD_TASK_FREQUENCY_MIN, OSD_TASK_FREQUENCY_MAX }, PG_OSD_CONFIG, offsetof(osdConfig_t, task_frequency) }, { "osd_menu_background", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CMS_BACKGROUND }, PG_OSD_CONFIG, offsetof(osdConfig_t, cms_background_type) }, + { "osd_aux_channel", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, MAX_SUPPORTED_RC_CHANNEL_COUNT }, PG_OSD_CONFIG, offsetof(osdConfig_t, aux_channel) }, + { "osd_aux_scale", VAR_UINT16 | MASTER_VALUE, .config.minmaxUnsigned = { 1, 1000 }, PG_OSD_CONFIG, offsetof(osdConfig_t, aux_scale) }, + { "osd_aux_symbol", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 255 }, PG_OSD_CONFIG, offsetof(osdConfig_t, aux_symbol) }, #endif // end of #ifdef USE_OSD // PG_SYSTEM_CONFIG diff --git a/src/main/cms/cms_menu_osd.c b/src/main/cms/cms_menu_osd.c index 177a765acf..d2f0d20886 100644 --- a/src/main/cms/cms_menu_osd.c +++ b/src/main/cms/cms_menu_osd.c @@ -165,6 +165,7 @@ const OSD_Entry menuOsdActiveElemsEntries[] = {"RC CHANNELS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_RC_CHANNELS], DYNAMIC}, {"CAMERA FRAME", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_CAMERA_FRAME], DYNAMIC}, {"TOTAL FLIGHTS", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_TOTAL_FLIGHTS], DYNAMIC}, + {"AUX VALUE", OME_VISIBLE, NULL, &osdConfig_item_pos[OSD_AUX_VALUE], DYNAMIC}, {"BACK", OME_Back, NULL, NULL, 0}, {NULL, OME_END, NULL, NULL, 0} }; diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index 6909304ab8..b64f7e1e6b 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -119,6 +119,7 @@ timeUs_t osdFlyTime = 0; #if defined(USE_ACC) float osdGForce = 0; #endif +uint16_t osdAuxValue = 0; static bool showVisualBeeper = false; @@ -382,6 +383,10 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig) osdConfig->stat_show_cell_value = false; osdConfig->task_frequency = OSD_TASK_FREQUENCY_DEFAULT; osdConfig->cms_background_type = DISPLAY_BACKGROUND_TRANSPARENT; + + osdConfig->aux_channel = 0; + osdConfig->aux_scale = 200; + osdConfig->aux_symbol = 'A'; } void pgResetFn_osdElementConfig(osdElementConfig_t *osdElementConfig) @@ -940,6 +945,7 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) static bool osdStatsEnabled = false; static bool osdStatsVisible = false; static timeUs_t osdStatsRefreshTimeUs; + static timeUs_t osdAuxRefreshTimeUs = 0; // detect arm/disarm if (armState != ARMING_FLAG(ARMED)) { @@ -1026,6 +1032,12 @@ STATIC_UNIT_TESTED void osdRefresh(timeUs_t currentTimeUs) } #endif + if (VISIBLE(osdElementConfig()->item_pos[OSD_AUX_VALUE])) { + if (currentTimeUs > osdAuxRefreshTimeUs) { + osdAuxValue = (constrain(rcData[osdConfig()->aux_channel - 1], PWM_RANGE_MIN, PWM_RANGE_MAX) - PWM_RANGE_MIN) * osdConfig()->aux_scale / (PWM_RANGE_MAX - PWM_RANGE_MIN); + osdAuxRefreshTimeUs = currentTimeUs + REFRESH_1S; + } + } #ifdef USE_CMS if (!displayIsGrabbed(osdDisplayPort)) #endif diff --git a/src/main/osd/osd.h b/src/main/osd/osd.h index d6c1b2c944..5049fac38d 100644 --- a/src/main/osd/osd.h +++ b/src/main/osd/osd.h @@ -161,6 +161,7 @@ typedef enum { OSD_TOTAL_FLIGHTS, OSD_UP_DOWN_REFERENCE, OSD_TX_UPLINK_POWER, + OSD_AUX_VALUE, OSD_ITEM_COUNT // MUST BE LAST } osd_items_e; @@ -303,6 +304,9 @@ typedef struct osdConfig_s { uint16_t task_frequency; uint8_t cms_background_type; // For supporting devices, determines whether the CMS background is transparent or opaque uint8_t stat_show_cell_value; + uint8_t aux_channel; + uint16_t aux_scale; + uint8_t aux_symbol; } osdConfig_t; PG_DECLARE(osdConfig_t, osdConfig); @@ -337,6 +341,7 @@ extern float osdGForce; #ifdef USE_ESC_SENSOR extern escSensorData_t *osdEscDataCombined; #endif +extern uint16_t osdAuxValue; void osdInit(displayPort_t *osdDisplayPort, osdDisplayPortDevice_e displayPortDevice); void osdUpdate(timeUs_t currentTimeUs); diff --git a/src/main/osd/osd_elements.c b/src/main/osd/osd_elements.c index 952eb3bb66..e905630a55 100644 --- a/src/main/osd/osd_elements.c +++ b/src/main/osd/osd_elements.c @@ -1463,6 +1463,11 @@ static void osdElementVtxChannel(osdElementParms_t *element) } #endif // USE_VTX_COMMON +static void osdElementAuxValue(osdElementParms_t *element) +{ + tfp_sprintf(element->buff, "%c%d", osdConfig()->aux_symbol, osdAuxValue); +} + static void osdElementWarnings(osdElementParms_t *element) { bool elementBlinking = false; @@ -1556,6 +1561,7 @@ static const uint8_t osdElementDisplayOrder[] = { #ifdef USE_PERSISTENT_STATS OSD_TOTAL_FLIGHTS, #endif + OSD_AUX_VALUE, }; // Define the mapping between the OSD element id and the function to draw it @@ -1673,6 +1679,7 @@ const osdElementDrawFn osdElementDrawFunction[OSD_ITEM_COUNT] = { #ifdef USE_PERSISTENT_STATS [OSD_TOTAL_FLIGHTS] = osdElementTotalFlights, #endif + [OSD_AUX_VALUE] = osdElementAuxValue, }; // Define the mapping between the OSD element id and the function to draw its background (static part) From e78db489e21b26c10f20c3ea56d0e6b73a349429 Mon Sep 17 00:00:00 2001 From: Alexey Stankevich Date: Tue, 20 Jul 2021 22:38:36 +0300 Subject: [PATCH 2/2] Update OSD PG versions --- src/main/osd/osd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/osd/osd.c b/src/main/osd/osd.c index b64f7e1e6b..2b6396043c 100644 --- a/src/main/osd/osd.c +++ b/src/main/osd/osd.c @@ -146,9 +146,9 @@ escSensorData_t *osdEscDataCombined; STATIC_ASSERT(OSD_POS_MAX == OSD_POS(31,31), OSD_POS_MAX_incorrect); -PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 9); +PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 10); -PG_REGISTER_WITH_RESET_FN(osdElementConfig_t, osdElementConfig, PG_OSD_ELEMENT_CONFIG, 0); +PG_REGISTER_WITH_RESET_FN(osdElementConfig_t, osdElementConfig, PG_OSD_ELEMENT_CONFIG, 1); // Controls the display order of the OSD post-flight statistics. // Adjust the ordering here to control how the post-flight stats are presented.