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