2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
19 #include "config/config_reset.h"
20 #include "config/parameter_group.h"
21 #include "config/parameter_group_ids.h"
23 #include "common/string_light.h"
24 #include "common/maths.h"
26 #include "programming/logic_condition.h"
27 #include "programming/global_variables.h"
30 #include "io/osd/custom_elements.h"
32 #include "drivers/osd_symbols.h"
34 PG_REGISTER_ARRAY_WITH_RESET_FN(osdCustomElement_t
, MAX_CUSTOM_ELEMENTS
, osdCustomElements
, PG_OSD_CUSTOM_ELEMENTS_CONFIG
, 1);
36 void pgResetFn_osdCustomElements(osdCustomElement_t
*instance
)
38 for (int i
= 0; i
< MAX_CUSTOM_ELEMENTS
; i
++) {
39 RESET_CONFIG(osdCustomElement_t
, &instance
[i
],
40 .part
[0] = {.type
= CUSTOM_ELEMENT_TYPE_NONE
, .value
= 0},
41 .part
[1] = {.type
= CUSTOM_ELEMENT_TYPE_NONE
, .value
= 0},
42 .part
[2] = {.type
= CUSTOM_ELEMENT_TYPE_NONE
, .value
= 0},
43 .visibility
= {.type
= CUSTOM_ELEMENT_VISIBILITY_ALWAYS
, .value
= 0},
44 .osdCustomElementText
= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
49 bool isCustomelementVisible(const osdCustomElement_t
* customElement
){
50 if(customElement
->visibility
.type
== CUSTOM_ELEMENT_VISIBILITY_ALWAYS
){
54 if(customElement
->visibility
.type
== CUSTOM_ELEMENT_VISIBILITY_GV
&& gvGet(customElement
->visibility
.value
)){
58 if(customElement
->visibility
.type
== CUSTOM_ELEMENT_VISIBILITY_LOGIC_CON
&& logicConditionGetValue(customElement
->visibility
.value
)){
65 uint8_t customElementDrawPart(char *buff
, uint8_t customElementIndex
, uint8_t customElementItemIndex
){
66 const osdCustomElement_t
* customElement
= osdCustomElements(customElementIndex
);
67 const int customPartType
= osdCustomElements(customElementIndex
)->part
[customElementItemIndex
].type
;
68 const int customPartValue
= osdCustomElements(customElementIndex
)->part
[customElementItemIndex
].value
;
70 switch (customPartType
) {
71 case CUSTOM_ELEMENT_TYPE_GV
:
73 osdFormatCentiNumber(buff
, (int32_t) gvGet(customPartValue
) * (int32_t) 100, 1, 0, 0, 6, false);
76 case CUSTOM_ELEMENT_TYPE_GV_FLOAT
:
78 osdFormatCentiNumber(buff
, (int32_t) gvGet(customPartValue
), 1, 2, 0, 6, false);
81 case CUSTOM_ELEMENT_TYPE_GV_SMALL
:
83 osdFormatCentiNumber(buff
, (int32_t) ((gvGet(customPartValue
) % 1000 ) * (int32_t) 100), 1, 0, 0, 3, false);
86 case CUSTOM_ELEMENT_TYPE_GV_SMALL_FLOAT
:
88 osdFormatCentiNumber(buff
, (int32_t) ((gvGet(customPartValue
) % 100) * (int32_t) 10), 1, 1, 0, 2, false);
91 case CUSTOM_ELEMENT_TYPE_ICON_GV
:
93 *buff
= (uint8_t)gvGet(customPartValue
);
96 case CUSTOM_ELEMENT_TYPE_ICON_STATIC
:
98 *buff
= (uint8_t)customPartValue
;
101 case CUSTOM_ELEMENT_TYPE_TEXT
:
103 for (int i
= 0; i
< OSD_CUSTOM_ELEMENT_TEXT_SIZE
; i
++) {
104 if (customElement
->osdCustomElementText
[i
] == 0){
107 *buff
= sl_toupper((unsigned char)customElement
->osdCustomElementText
[i
]);
110 return OSD_CUSTOM_ELEMENT_TEXT_SIZE
;
117 void customElementDrawElement(char *buff
, uint8_t customElementIndex
){
119 if(customElementIndex
>= MAX_CUSTOM_ELEMENTS
){
123 static uint8_t prevLength
[MAX_CUSTOM_ELEMENTS
];
125 uint8_t buffSeek
= 0;
126 const osdCustomElement_t
* customElement
= osdCustomElements(customElementIndex
);
127 if(isCustomelementVisible(customElement
))
129 for (uint8_t i
= 0; i
< CUSTOM_ELEMENTS_PARTS
; ++i
) {
130 uint8_t currentSeek
= customElementDrawPart(buff
, customElementIndex
, i
);
132 buffSeek
+= currentSeek
;
136 for (uint8_t i
= buffSeek
; i
< prevLength
[customElementIndex
]; i
++) {
139 prevLength
[customElementIndex
] = buffSeek
;