Merge pull request #11299 from daleckystepan/vtx-start-bit
[betaflight.git] / src / main / cms / cms_menu_main.c
blob3863687177ecd952d1e01c602c7d80abef5a306f
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
22 // Main menu structure and support functions
25 #include <stdbool.h>
27 #include "platform.h"
29 #ifdef USE_CMS
31 #include "cms/cms.h"
32 #include "cms/cms_types.h"
34 // Sub menus
36 #include "cms/cms_menu_imu.h"
37 #include "cms/cms_menu_blackbox.h"
38 #include "cms/cms_menu_failsafe.h"
39 #include "cms/cms_menu_firmware.h"
40 #include "cms/cms_menu_ledstrip.h"
41 #include "cms/cms_menu_misc.h"
42 #include "cms/cms_menu_osd.h"
43 #include "cms/cms_menu_power.h"
44 #include "cms/cms_menu_saveexit.h"
46 #ifdef USE_PERSISTENT_STATS
47 #include "cms/cms_menu_persistent_stats.h"
48 #endif
50 // VTX supplied menus
52 #include "cms/cms_menu_vtx_common.h"
54 #include "common/printf.h"
56 #include "config/config.h"
58 #include "fc/core.h"
59 #include "fc/runtime_config.h"
61 #include "sensors/acceleration.h"
63 #include "cms_menu_main.h"
65 #define CALIBRATION_STATUS_MAX_LENGTH 9
67 #define CALIBRATION_STATUS_REQUIRED "REQUIRED"
68 #define CALIBRATION_STATUS_ACTIVE " ACTIVE"
69 #define CALIBRATION_STATUS_COMPLETE "COMPLETE"
71 #if defined(USE_ACC)
72 static char accCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
73 #endif
75 // Features
77 static const OSD_Entry menuFeaturesEntries[] =
79 {"--- FEATURES ---", OME_Label, NULL, NULL},
81 #if defined(USE_BLACKBOX)
82 {"BLACKBOX", OME_Submenu, cmsMenuChange, &cmsx_menuBlackbox},
83 #endif
84 #if defined(USE_VTX_CONTROL)
85 #if defined(USE_VTX_RTC6705) || defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)
86 {"VTX", OME_Funcall, cmsSelectVtx, NULL},
87 #endif
88 #endif // VTX_CONTROL
89 #ifdef USE_LED_STRIP
90 {"LED STRIP", OME_Submenu, cmsMenuChange, &cmsx_menuLedstrip},
91 #endif // LED_STRIP
92 {"POWER", OME_Submenu, cmsMenuChange, &cmsx_menuPower},
93 #ifdef USE_CMS_FAILSAFE_MENU
94 {"FAILSAFE", OME_Submenu, cmsMenuChange, &cmsx_menuFailsafe},
95 #endif
96 #ifdef USE_PERSISTENT_STATS
97 {"PERSISTENT STATS", OME_Submenu, cmsMenuChange, &cmsx_menuPersistentStats},
98 #endif
99 {"BACK", OME_Back, NULL, NULL},
100 {NULL, OME_END, NULL, NULL}
103 static CMS_Menu cmsx_menuFeatures = {
104 #ifdef CMS_MENU_DEBUG
105 .GUARD_text = "MENUFEATURES",
106 .GUARD_type = OME_MENU,
107 #endif
108 .onEnter = NULL,
109 .onExit = NULL,
110 .onDisplayUpdate = NULL,
111 .entries = menuFeaturesEntries,
114 static const void *cmsx_SaveExitMenu(displayPort_t *pDisplay, const void *ptr)
116 UNUSED(ptr);
118 cmsMenuChange(pDisplay, getSaveExitMenu());
120 return NULL;
124 #define SETUP_POPUP_MAX_ENTRIES 1 // Increase as new entries are added
126 static OSD_Entry setupPopupMenuEntries[SETUP_POPUP_MAX_ENTRIES + 3];
128 static bool setupPopupMenuBuild(void)
130 uint8_t menuIndex = 0;
131 updateArmingStatus();
133 cmsAddMenuEntry(&setupPopupMenuEntries[menuIndex], "-- SETUP MENU --", OME_Label, NULL, NULL);
135 // Add menu entries for uncompleted setup tasks
136 #if defined(USE_ACC)
137 if (sensors(SENSOR_ACC) && (getArmingDisableFlags() & ARMING_DISABLED_ACC_CALIBRATION)) {
138 cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], "CALIBRATE ACC", OME_Funcall | DYNAMIC, cmsCalibrateAccMenu, accCalibrationStatus);
140 #endif
142 cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], "EXIT", OME_Back | DYNAMIC, NULL, NULL);
143 cmsAddMenuEntry(&setupPopupMenuEntries[++menuIndex], "NULL", OME_END, NULL, NULL);
145 return (menuIndex > 2); // return true if any setup items were added
148 static const void *setupPopupMenuOnDisplayUpdate(displayPort_t *pDisp, const OSD_Entry *selected)
150 UNUSED(pDisp);
151 UNUSED(selected);
153 #if defined(USE_ACC)
154 // Update the ACC calibration status message.
155 tfp_sprintf(accCalibrationStatus, accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_COMPLETE : CALIBRATION_STATUS_REQUIRED : CALIBRATION_STATUS_ACTIVE);
156 #endif
158 return NULL;
161 CMS_Menu cmsx_menuSetupPopup = {
162 #ifdef CMS_MENU_DEBUG
163 .GUARD_text = "SETUPPOPUP",
164 .GUARD_type = OME_MENU,
165 #endif
166 .onEnter = NULL,
167 .onExit = NULL,
168 .onDisplayUpdate = setupPopupMenuOnDisplayUpdate,
169 .entries = setupPopupMenuEntries,
172 // Main
173 static const void *mainMenuOnEnter(displayPort_t *pDisp)
175 if (setupPopupMenuBuild()) {
176 // If setup issues were found then switch to the dynamically constructed menu
177 cmsMenuChange(pDisp, &cmsx_menuSetupPopup);
179 return NULL;
182 static const OSD_Entry menuMainEntries[] =
184 {"-- MAIN --", OME_Label, NULL, NULL},
186 {"PROFILE", OME_Submenu, cmsMenuChange, &cmsx_menuImu},
187 {"FEATURES", OME_Submenu, cmsMenuChange, &cmsx_menuFeatures},
188 #ifdef USE_OSD
189 {"OSD", OME_Submenu, cmsMenuChange, &cmsx_menuOsd},
190 #endif
191 {"FC&FIRMWARE", OME_Submenu, cmsMenuChange, &cmsx_menuFirmware},
192 {"MISC", OME_Submenu, cmsMenuChange, &cmsx_menuMisc},
193 {"SAVE/EXIT", OME_Funcall, cmsx_SaveExitMenu, NULL},
194 {NULL, OME_END, NULL, NULL},
197 CMS_Menu cmsx_menuMain = {
198 #ifdef CMS_MENU_DEBUG
199 .GUARD_text = "MENUMAIN",
200 .GUARD_type = OME_MENU,
201 #endif
202 .onEnter = mainMenuOnEnter,
203 .onExit = NULL,
204 .onDisplayUpdate = NULL,
205 .entries = menuMainEntries,
208 #endif