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)
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
32 #include "cms/cms_types.h"
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"
52 #include "cms/cms_menu_vtx_common.h"
54 #include "common/printf.h"
56 #include "config/config.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"
72 static char accCalibrationStatus
[CALIBRATION_STATUS_MAX_LENGTH
];
77 static const OSD_Entry menuFeaturesEntries
[] =
79 {"--- FEATURES ---", OME_Label
, NULL
, NULL
},
81 #if defined(USE_BLACKBOX)
82 {"BLACKBOX", OME_Submenu
, cmsMenuChange
, &cmsx_menuBlackbox
},
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
},
90 {"LED STRIP", OME_Submenu
, cmsMenuChange
, &cmsx_menuLedstrip
},
92 {"POWER", OME_Submenu
, cmsMenuChange
, &cmsx_menuPower
},
93 #ifdef USE_CMS_FAILSAFE_MENU
94 {"FAILSAFE", OME_Submenu
, cmsMenuChange
, &cmsx_menuFailsafe
},
96 #ifdef USE_PERSISTENT_STATS
97 {"PERSISTENT STATS", OME_Submenu
, cmsMenuChange
, &cmsx_menuPersistentStats
},
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
,
110 .onDisplayUpdate
= NULL
,
111 .entries
= menuFeaturesEntries
,
114 static const void *cmsx_SaveExitMenu(displayPort_t
*pDisplay
, const void *ptr
)
118 cmsMenuChange(pDisplay
, getSaveExitMenu());
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
137 if (sensors(SENSOR_ACC
) && (getArmingDisableFlags() & ARMING_DISABLED_ACC_CALIBRATION
)) {
138 cmsAddMenuEntry(&setupPopupMenuEntries
[++menuIndex
], "CALIBRATE ACC", OME_Funcall
| DYNAMIC
, cmsCalibrateAccMenu
, accCalibrationStatus
);
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
)
154 // Update the ACC calibration status message.
155 tfp_sprintf(accCalibrationStatus
, accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_COMPLETE
: CALIBRATION_STATUS_REQUIRED
: CALIBRATION_STATUS_ACTIVE
);
161 CMS_Menu cmsx_menuSetupPopup
= {
162 #ifdef CMS_MENU_DEBUG
163 .GUARD_text
= "SETUPPOPUP",
164 .GUARD_type
= OME_MENU
,
168 .onDisplayUpdate
= setupPopupMenuOnDisplayUpdate
,
169 .entries
= setupPopupMenuEntries
,
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
);
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
},
189 {"OSD", OME_Submenu
, cmsMenuChange
, &cmsx_menuOsd
},
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
,
202 .onEnter
= mainMenuOnEnter
,
204 .onDisplayUpdate
= NULL
,
205 .entries
= menuMainEntries
,