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/>.
20 // XXX Upon separation, all OME would be renamed to CME_ or similar.
30 #define OSD_ENTRY_ATTR __attribute__((packed))
32 #define OSD_ENTRY_ATTR
38 OME_LabelFunc
, // bool func(char *buf, unsigned bufsize) - returns wether buf should be printed
44 OME_BoolFunc
, // bool func(bool*):
50 OME_FLOAT
, //only up to 255 value and cant be 2.55 or 25.5, just for PID's
52 //wlasciwosci elementow
64 typedef long (*CMSEntryFuncPtr
)(displayPort_t
*displayPort
, const void *ptr
);
65 // This is a function used in the func member if the type is OME_Submenu.
66 typedef char * (*CMSMenuOptFuncPtr
)(void);
70 const char * const text
;
73 const CMSEntryFuncPtr func
;
74 const CMSMenuOptFuncPtr menufunc
;
77 const void * const data
;
78 const uint8_t type
; // from OSD_MenuElement
80 } OSD_ENTRY_ATTR OSD_Entry
;
83 #define PRINT_VALUE (1 << 0) // Value has been changed, need to redraw
84 #define PRINT_LABEL (1 << 1) // Text label should be printed
85 #define DYNAMIC (1 << 2) // Value should be updated dynamically
86 #define OPTSTRING (1 << 3) // (Temporary) Flag for OME_Submenu, indicating func should be called to get a string to display.
87 #define READONLY (1 << 4) // Indicates that the value is read-only and p->data points directly to it - applies to [U]INT(8|16)
89 #define OSD_LABEL_ENTRY(label) ((OSD_Entry){ label, {.func = NULL}, NULL, OME_Label, 0 })
90 #define OSD_LABEL_DATA_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, 0 })
91 #define OSD_LABEL_DATA_DYN_ENTRY(label, data) ((OSD_Entry){ label, {.func = NULL}, data, OME_Label, DYNAMIC })
92 #define OSD_LABEL_FUNC_DYN_ENTRY(label, fn) ((OSD_Entry){ label, {.func = NULL}, fn, OME_LabelFunc, DYNAMIC })
93 #define OSD_LABEL_PAGE2_ENTRY(label, p2text) ((OSD_Entry){ label, {.func = NULL}, p2text, OME_Label_PAGE2_DATA, 0 })
94 #define OSD_BACK_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_Back, 0 })
95 #define OSD_BACK_AND_END_ENTRY ((OSD_Entry){ "BACK", {.func = NULL}, NULL, OME_BACK_AND_END, 0 })
96 #define OSD_SUBMENU_ENTRY(label, menu) ((OSD_Entry){ label, {.func = NULL}, menu, OME_Submenu, 0 })
97 #define OSD_FUNC_CALL_ENTRY(label, fn) ((OSD_Entry){ label, {.func = fn}, NULL, OME_Funcall, 0 })
98 #define OSD_BOOL_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_Bool, 0 })
99 #define OSD_BOOL_CALLBACK_ENTRY(label, cb, val) ((OSD_Entry){ label, {.func = cb}, val, OME_Bool, 0 })
100 #define OSD_BOOL_FUNC_ENTRY(label, fn) ((OSD_Entry){ label, {.func = NULL}, fn, OME_BoolFunc, 0 })
101 #define OSD_INT8_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT8, DYNAMIC })
102 #define OSD_UINT8_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT8, 0 })
103 #define OSD_UINT8_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT8, DYNAMIC })
104 #define OSD_UINT8_CALLBACK_ENTRY(label, cb, val)((OSD_Entry){ label, {.func = cb}, val, OME_UINT8, 0 })
105 #define OSD_UINT16_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, 0 })
106 #define OSD_UINT16_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, DYNAMIC })
107 #define OSD_UINT16_RO_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_UINT16, DYNAMIC | READONLY })
108 #define OSD_INT16_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, 0 })
109 #define OSD_INT16_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, DYNAMIC })
110 #define OSD_INT16_RO_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_INT16, DYNAMIC | READONLY })
111 #define OSD_STRING_ENTRY(label, str) ((OSD_Entry){ label, {.func = NULL}, str, OME_String, 0 })
112 #define OSD_TAB_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_TAB, 0 })
113 #define OSD_TAB_DYN_ENTRY(label, val) ((OSD_Entry){ label, {.func = NULL}, val, OME_TAB, DYNAMIC })
114 #define OSD_TAB_CALLBACK_ENTRY(label, cb, val) ((OSD_Entry){ label, {.func = cb}, val, OME_TAB, 0 })
116 #define OSD_END_ENTRY ((OSD_Entry){ NULL, {.func = NULL}, NULL, OME_END, 0 })
118 // Data type for OME_Setting. Uses upper 4 bits
119 // of flags, leaving 16 data types.
120 #define CMS_DATA_TYPE_OFFSET (4)
122 CMS_DATA_TYPE_ANGULAR_RATE
= (1 << CMS_DATA_TYPE_OFFSET
),
125 // Use a function and data type to make sure switches are exhaustive
126 static inline CMSDataType_e
CMS_DATA_TYPE(const OSD_Entry
*entry
) { return entry
->flags
& 0xF0; }
128 typedef long (*CMSMenuFuncPtr
)(const OSD_Entry
*from
);
130 // Special return value(s) for function chaining by CMSMenuFuncPtr
131 #define MENU_CHAIN_BACK (-1) // Causes automatic cmsMenuBack
134 onExit function is called with self:
135 (1) Pointer to an OSD_Entry when cmsMenuBack() was called.
136 Point to an OSD_Entry with type == OME_Back if BACK was selected.
137 (2) NULL if called from menu exit (forced exit at top level).
140 typedef long (*CMSMenuOnExitPtr
)(const OSD_Entry
*self
);
144 #ifdef CMS_MENU_DEBUG
145 // These two are debug aids for menu content creators.
146 const char *GUARD_text
;
147 const OSD_MenuElement GUARD_type
;
149 const CMSMenuFuncPtr onEnter
;
150 const CMSMenuOnExitPtr onExit
;
151 const CMSMenuFuncPtr onGlobalExit
;
152 const OSD_Entry
*entries
;
196 typedef struct OSD_SETTING_s
{
197 const uint16_t val
; // setting number, from the constants in settings_generated.h
199 } __attribute__((packed
)) OSD_SETTING_t
;
201 #define OSD_SETTING_ENTRY_STEP_TYPE(name, setting, step, type) { name, { NULL }, &(const OSD_SETTING_t){ setting, step }, OME_Setting, type }
202 #define OSD_SETTING_ENTRY_TYPE(name, setting, type) OSD_SETTING_ENTRY_STEP_TYPE(name, setting, 0, type)
203 #define OSD_SETTING_ENTRY_STEP(name, setting, step) OSD_SETTING_ENTRY_STEP_TYPE(name, setting, step, 0)
204 #define OSD_SETTING_ENTRY(name, setting) OSD_SETTING_ENTRY_STEP(name, setting, 0)
210 const char * const *names
;