Skip to content

Commit

Permalink
Added extra format to COE
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MrD-RC committed Jan 15, 2025
1 parent c9016a9 commit 3beae50
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/main/fc/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/main/fc/fc_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/main/io/osd/custom_elements.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 19 additions & 16 deletions src/main/io/osd/custom_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3beae50

Please sign in to comment.