Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / cms / cms_menu_firmware.c
blob34f0075e3fbcddb5da393ad1f06e4761f0332ca4
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 // Firmware related menu contents and support functions
25 #include <ctype.h>
27 #include <stdbool.h>
28 #include <string.h>
30 #include "platform.h"
32 #ifdef USE_CMS
34 #include "build/version.h"
36 #include "cms/cms.h"
37 #include "cms/cms_types.h"
39 #include "common/printf.h"
41 #include "config/config.h"
43 #include "drivers/system.h"
45 #include "fc/board_info.h"
46 #include "fc/runtime_config.h"
48 #include "pg/board.h"
50 #include "sensors/acceleration.h"
51 #include "sensors/barometer.h"
52 #include "sensors/gyro.h"
54 #include "cms_menu_firmware.h"
57 // Calibration
59 #define CALIBRATION_STATUS_MAX_LENGTH 6
61 #define CALIBRATION_STATUS_OFF " --- "
62 #define CALIBRATION_STATUS_NOK " NOK "
63 #define CALIBRATION_STATUS_WAIT "WAIT "
64 #define CALIBRATION_STATUS_OK " OK "
66 static char gyroCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
67 #if defined(USE_ACC)
68 static char accCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
69 #endif
70 #if defined(USE_BARO)
71 static char baroCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
72 #endif
74 static const void *cmsx_CalibrationOnDisplayUpdate(displayPort_t *pDisp, const OSD_Entry *selected)
76 UNUSED(pDisp);
77 UNUSED(selected);
79 tfp_sprintf(gyroCalibrationStatus, sensors(SENSOR_GYRO) ? gyroIsCalibrationComplete() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
80 #if defined(USE_ACC)
81 tfp_sprintf(accCalibrationStatus, sensors(SENSOR_ACC) ? accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_NOK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
82 #endif
83 #if defined(USE_BARO)
84 tfp_sprintf(baroCalibrationStatus, sensors(SENSOR_BARO) ? baroIsCalibrationComplete() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
85 #endif
87 return NULL;
90 static const void *cmsCalibrateGyro(displayPort_t *pDisp, const void *self)
92 UNUSED(pDisp);
93 UNUSED(self);
95 if (sensors(SENSOR_GYRO)) {
96 gyroStartCalibration(false);
99 return NULL;
102 #if defined(USE_ACC)
103 static const void *cmsCalibrateAcc(displayPort_t *pDisp, const void *self)
105 UNUSED(pDisp);
106 UNUSED(self);
108 if (sensors(SENSOR_ACC)) {
109 accStartCalibration();
112 return MENU_CHAIN_BACK;
114 #endif
116 #if defined(USE_BARO)
117 static const void *cmsCalibrateBaro(displayPort_t *pDisp, const void *self)
119 UNUSED(pDisp);
120 UNUSED(self);
122 if (sensors(SENSOR_BARO)) {
123 baroStartCalibration();
126 return NULL;
128 #endif
130 #if defined(USE_ACC)
131 static const OSD_Entry menuCalibrateAccEntries[] = {
132 { "--- CALIBRATE ACC ---", OME_Label, NULL, NULL },
133 { "PLACE ON A LEVEL SURFACE", OME_Label, NULL, NULL},
134 { "MAKE SURE CRAFT IS STILL", OME_Label, NULL, NULL},
135 { " ", OME_Label, NULL, NULL},
136 { "START CALIBRATION", OME_Funcall, cmsCalibrateAcc, NULL },
137 { "BACK", OME_Back, NULL, NULL },
138 { NULL, OME_END, NULL, NULL}
141 CMS_Menu cmsx_menuCalibrateAcc = {
142 #ifdef CMS_MENU_DEBUG
143 .GUARD_text = "ACCCALIBRATION",
144 .GUARD_type = OME_MENU,
145 #endif
146 .onEnter = NULL,
147 .onExit = NULL,
148 .onDisplayUpdate = NULL,
149 .entries = menuCalibrateAccEntries
152 const void *cmsCalibrateAccMenu(displayPort_t *pDisp, const void *self)
154 UNUSED(self);
156 if (sensors(SENSOR_ACC)) {
157 cmsMenuChange(pDisp, &cmsx_menuCalibrateAcc);
160 return NULL;
163 #endif
165 static const OSD_Entry menuCalibrationEntries[] = {
166 { "--- CALIBRATE ---", OME_Label, NULL, NULL },
167 { "GYRO", OME_Funcall | DYNAMIC, cmsCalibrateGyro, gyroCalibrationStatus },
168 #if defined(USE_ACC)
169 { "ACC", OME_Funcall | DYNAMIC, cmsCalibrateAccMenu, accCalibrationStatus },
170 #endif
171 #if defined(USE_BARO)
172 { "BARO", OME_Funcall | DYNAMIC, cmsCalibrateBaro, baroCalibrationStatus },
173 #endif
174 { "BACK", OME_Back, NULL, NULL },
175 { NULL, OME_END, NULL, NULL}
178 static CMS_Menu cmsx_menuCalibration = {
179 #ifdef CMS_MENU_DEBUG
180 .GUARD_text = "MENUCALIBRATION",
181 .GUARD_type = OME_MENU,
182 #endif
183 .onEnter = NULL,
184 .onExit = NULL,
185 .onDisplayUpdate = cmsx_CalibrationOnDisplayUpdate,
186 .entries = menuCalibrationEntries
189 // Info
191 #if defined(USE_BOARD_INFO)
192 static char manufacturerId[MAX_MANUFACTURER_ID_LENGTH + 1];
193 static char boardName[MAX_BOARD_NAME_LENGTH + 1];
195 static const void *cmsx_FirmwareInit(displayPort_t *pDisp)
197 UNUSED(pDisp);
199 strncpy(manufacturerId, getManufacturerId(), MAX_MANUFACTURER_ID_LENGTH + 1);
200 strncpy(boardName, getBoardName(), MAX_BOARD_NAME_LENGTH + 1);
202 return NULL;
204 #endif
206 static const OSD_Entry menuFirmwareEntries[] = {
207 { "--- INFO ---", OME_Label, NULL, NULL },
208 { "FWID", OME_String, NULL, FC_FIRMWARE_IDENTIFIER },
209 { "FWVER", OME_String, NULL, FC_VERSION_STRING },
210 { "GITREV", OME_String, NULL, __REVISION__ },
211 { "TARGET", OME_String, NULL, __TARGET__ },
212 #if defined(USE_BOARD_INFO)
213 { "MFR", OME_String, NULL, manufacturerId },
214 { "BOARD", OME_String, NULL, boardName },
215 #endif
216 { "--- SETUP ---", OME_Label, NULL, NULL },
217 { "CALIBRATE", OME_Submenu, cmsMenuChange, &cmsx_menuCalibration},
218 { "BACK", OME_Back, NULL, NULL },
219 { NULL, OME_END, NULL, NULL}
222 CMS_Menu cmsx_menuFirmware = {
223 #ifdef CMS_MENU_DEBUG
224 .GUARD_text = "MENUFIRMWARE",
225 .GUARD_type = OME_MENU,
226 #endif
227 #if defined(USE_BOARD_INFO)
228 .onEnter = cmsx_FirmwareInit,
229 #else
230 .onEnter = NULL,
231 #endif
232 .onExit = NULL,
233 .onDisplayUpdate = NULL,
234 .entries = menuFirmwareEntries
236 #endif