From 3beae506fe02b86742323b3445e9ffa321f594db Mon Sep 17 00:00:00 2001 From: Mr D - RC Date: Wed, 15 Jan 2025 13:45:27 +0000 Subject: [PATCH] Added extra format to COE Added extra number format `0.00` to Custom OSD Elements. As the enum has shifted from 7.x anyway. I have inserted these formats in the appropriate place in the enum. - Enums inserted at 11 and 23 - Added `END` type to CUSTOM_ELEMENT_TYPE enum. To automatically handle future changes - Added fail in MSP is the type is not in the valid range --- src/main/fc/cli.c | 6 +++--- src/main/fc/fc_msp.c | 6 +++++- src/main/io/osd/custom_elements.c | 10 +++++++++ src/main/io/osd/custom_elements.h | 35 +++++++++++++++++-------------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/main/fc/cli.c b/src/main/fc/cli.c index eaca5eb2608..62697014c31 100644 --- a/src/main/fc/cli.c +++ b/src/main/fc/cli.c @@ -2803,11 +2803,11 @@ static void osdCustom(char *cmdline){ int32_t i = args[INDEX]; if ( i >= 0 && i < MAX_CUSTOM_ELEMENTS && - args[PART0_TYPE] >= 0 && args[PART0_TYPE] <= 26 && + args[PART0_TYPE] >= 0 && args[PART0_TYPE] < CUSTOM_ELEMENT_TYPE_END && args[PART0_VALUE] >= 0 && args[PART0_VALUE] <= UINT8_MAX && - args[PART1_TYPE] >= 0 && args[PART1_TYPE] <= 26 && + args[PART1_TYPE] >= 0 && args[PART1_TYPE] < CUSTOM_ELEMENT_TYPE_END && args[PART1_VALUE] >= 0 && args[PART1_VALUE] <= UINT8_MAX && - args[PART2_TYPE] >= 0 && args[PART2_TYPE] <= 26 && + args[PART2_TYPE] >= 0 && args[PART2_TYPE] < CUSTOM_ELEMENT_TYPE_END && args[PART2_VALUE] >= 0 && args[PART2_VALUE] <= UINT8_MAX && args[VISIBILITY_TYPE] >= 0 && args[VISIBILITY_TYPE] <= 2 && args[VISIBILITY_VALUE] >= 0 && args[VISIBILITY_VALUE] <= UINT8_MAX diff --git a/src/main/fc/fc_msp.c b/src/main/fc/fc_msp.c index 0125b4ce914..b4b6fce2824 100644 --- a/src/main/fc/fc_msp.c +++ b/src/main/fc/fc_msp.c @@ -3520,7 +3520,11 @@ static mspResult_e mspFcProcessInCommand(uint16_t cmdMSP, sbuf_t *src) sbufReadU8Safe(&tmp_u8, src); if ((dataSize == (OSD_CUSTOM_ELEMENT_TEXT_SIZE - 1) + (CUSTOM_ELEMENTS_PARTS * 3) + 4) && (tmp_u8 < MAX_CUSTOM_ELEMENTS)) { for (int i = 0; i < CUSTOM_ELEMENTS_PARTS; i++) { - osdCustomElementsMutable(tmp_u8)->part[i].type = sbufReadU8(src); + uint8_t type = sbufReadU8(src); + if (type >= CUSTOM_ELEMENT_TYPE_END) + return MSP_RESULT_ERROR; + + osdCustomElementsMutable(tmp_u8)->part[i].type = type; osdCustomElementsMutable(tmp_u8)->part[i].value = sbufReadU16(src); } osdCustomElementsMutable(tmp_u8)->visibility.type = sbufReadU8(src); diff --git a/src/main/io/osd/custom_elements.c b/src/main/io/osd/custom_elements.c index df84ddd76b0..72e1dc779f7 100644 --- a/src/main/io/osd/custom_elements.c +++ b/src/main/io/osd/custom_elements.c @@ -98,6 +98,11 @@ uint8_t customElementDrawPart(char *buff, uint8_t customElementIndex, uint8_t cu osdFormatCentiNumber(buff, (int32_t) (constrain(gvGet(customPartValue), -99, 99) * (int32_t) 10), 1, 1, 0, 3, false); return 3; } + case CUSTOM_ELEMENT_TYPE_GV_FLOAT_1_2: + { + osdFormatCentiNumber(buff, (int32_t) (constrain(gvGet(customPartValue), -999, 999) * (int32_t) 10), 1, 2, 0, 4, false); + return 4; + } case CUSTOM_ELEMENT_TYPE_GV_FLOAT_2_1: { osdFormatCentiNumber(buff, (int32_t) (constrain(gvGet(customPartValue), -999, 999) * (int32_t) 10), 1, 1, 0, 4, false); @@ -154,6 +159,11 @@ uint8_t customElementDrawPart(char *buff, uint8_t customElementIndex, uint8_t cu osdFormatCentiNumber(buff, (int32_t) (constrain(logicConditionGetValue(customPartValue), -99, 99) * (int32_t) 10), 1, 1, 0, 3, false); return 3; } + case CUSTOM_ELEMENT_TYPE_LC_FLOAT_1_2: + { + osdFormatCentiNumber(buff, (int32_t) (constrain(logicConditionGetValue(customPartValue), -999, 999) * (int32_t) 10), 1, 2, 0, 4, false); + return 4; + } case CUSTOM_ELEMENT_TYPE_LC_FLOAT_2_1: { osdFormatCentiNumber(buff, (int32_t) (constrain(logicConditionGetValue(customPartValue), -999, 999) * (int32_t) 10), 1, 1, 0, 4, false); diff --git a/src/main/io/osd/custom_elements.h b/src/main/io/osd/custom_elements.h index 9c12ede6734..8f5ee158811 100644 --- a/src/main/io/osd/custom_elements.h +++ b/src/main/io/osd/custom_elements.h @@ -35,22 +35,25 @@ typedef enum { CUSTOM_ELEMENT_TYPE_GV_4 = 8, CUSTOM_ELEMENT_TYPE_GV_5 = 9, CUSTOM_ELEMENT_TYPE_GV_FLOAT_1_1 = 10, - CUSTOM_ELEMENT_TYPE_GV_FLOAT_2_1 = 11, - CUSTOM_ELEMENT_TYPE_GV_FLOAT_2_2 = 12, - CUSTOM_ELEMENT_TYPE_GV_FLOAT_3_1 = 13, - CUSTOM_ELEMENT_TYPE_GV_FLOAT_3_2 = 14, - CUSTOM_ELEMENT_TYPE_GV_FLOAT_4_1 = 15, - CUSTOM_ELEMENT_TYPE_LC_1 = 16, - CUSTOM_ELEMENT_TYPE_LC_2 = 17, - CUSTOM_ELEMENT_TYPE_LC_3 = 18, - CUSTOM_ELEMENT_TYPE_LC_4 = 19, - CUSTOM_ELEMENT_TYPE_LC_5 = 20, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_1_1 = 21, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_2_1 = 22, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_2_2 = 23, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_3_1 = 24, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_3_2 = 25, - CUSTOM_ELEMENT_TYPE_LC_FLOAT_4_1 = 26, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_1_2 = 11, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_2_1 = 12, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_2_2 = 13, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_3_1 = 14, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_3_2 = 15, + CUSTOM_ELEMENT_TYPE_GV_FLOAT_4_1 = 16, + CUSTOM_ELEMENT_TYPE_LC_1 = 17, + CUSTOM_ELEMENT_TYPE_LC_2 = 18, + CUSTOM_ELEMENT_TYPE_LC_3 = 19, + CUSTOM_ELEMENT_TYPE_LC_4 = 20, + CUSTOM_ELEMENT_TYPE_LC_5 = 21, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_1_1 = 22, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_1_2 = 23, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_2_1 = 24, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_2_2 = 25, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_3_1 = 26, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_3_2 = 27, + CUSTOM_ELEMENT_TYPE_LC_FLOAT_4_1 = 28, + CUSTOM_ELEMENT_TYPE_END // Must be last } osdCustomElementType_e; typedef enum {