Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / cms / cms_types.h
bloba07e55eaaa4e7259f07f8aea55eaf4cd8fbea368
1 /*
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 // Menu element types
20 // XXX Upon separation, all OME would be renamed to CME_ or similar.
23 #pragma once
25 #include <stdint.h>
27 //type of elements
29 #ifndef __APPLE__
30 #define OSD_ENTRY_ATTR __attribute__((packed))
31 #else
32 #define OSD_ENTRY_ATTR
33 #endif
35 typedef enum
37 OME_Label,
38 OME_LabelFunc, // bool func(char *buf, unsigned bufsize) - returns wether buf should be printed
39 OME_Back,
40 OME_OSD_Exit,
41 OME_Submenu,
42 OME_Funcall,
43 OME_Bool,
44 OME_BoolFunc, // bool func(bool*):
45 OME_INT8,
46 OME_UINT8,
47 OME_UINT16,
48 OME_INT16,
49 OME_String,
50 OME_FLOAT, //only up to 255 value and cant be 2.55 or 25.5, just for PID's
51 OME_Setting,
52 //wlasciwosci elementow
53 OME_TAB,
54 OME_END,
55 OME_BACK_AND_END,
56 OME_Label_PAGE2_DATA,
58 // Debug aid
59 OME_MENU,
61 OME_MAX = OME_MENU
62 } OSD_MenuElement;
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);
68 typedef struct
70 const char * const text;
71 union
73 const CMSEntryFuncPtr func;
74 const CMSMenuOptFuncPtr menufunc;
75 int itemId;
77 const void * const data;
78 const uint8_t type; // from OSD_MenuElement
79 uint8_t flags;
80 } OSD_ENTRY_ATTR OSD_Entry;
82 // Bits in flags
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)
121 typedef enum {
122 CMS_DATA_TYPE_ANGULAR_RATE = (1 << CMS_DATA_TYPE_OFFSET),
123 } CMSDataType_e;
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);
142 typedef struct
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;
148 #endif
149 const CMSMenuFuncPtr onEnter;
150 const CMSMenuOnExitPtr onExit;
151 const CMSMenuFuncPtr onGlobalExit;
152 const OSD_Entry *entries;
153 } CMS_Menu;
155 typedef struct
157 uint8_t *val;
158 uint8_t min;
159 uint8_t max;
160 uint8_t step;
161 } OSD_UINT8_t;
163 typedef struct
165 int8_t *val;
166 int8_t min;
167 int8_t max;
168 int8_t step;
169 } OSD_INT8_t;
171 typedef struct
173 int16_t *val;
174 int16_t min;
175 int16_t max;
176 int16_t step;
177 } OSD_INT16_t;
179 typedef struct
181 uint16_t *val;
182 uint16_t min;
183 uint16_t max;
184 uint16_t step;
185 } OSD_UINT16_t;
187 typedef struct
189 uint8_t *val;
190 uint8_t min;
191 uint8_t max;
192 uint8_t step;
193 uint16_t multipler;
194 } OSD_FLOAT_t;
196 typedef struct OSD_SETTING_s {
197 const uint16_t val; // setting number, from the constants in settings_generated.h
198 const uint8_t step;
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)
206 typedef struct
208 uint8_t *val;
209 uint8_t max;
210 const char * const *names;
211 } OSD_TAB_t;
213 typedef struct
215 char *val;
216 } OSD_String_t;