update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / main / cms / cms_menu_firmware.c
blob25073a93aa36a562ad4806e1ef09fc4d08c3b449
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"
56 // Calibration
58 #define CALIBRATION_STATUS_MAX_LENGTH 6
60 #define CALIBRATION_STATUS_OFF " --- "
61 #define CALIBRATION_STATUS_NOK " NOK "
62 #define CALIBRATION_STATUS_WAIT "WAIT "
63 #define CALIBRATION_STATUS_OK " OK "
65 static char gyroCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
66 #if defined(USE_ACC)
67 static char accCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
68 #endif
69 #if defined(USE_BARO)
70 static char baroCalibrationStatus[CALIBRATION_STATUS_MAX_LENGTH];
71 #endif
73 static const void *cmsx_CalibrationOnDisplayUpdate(displayPort_t *pDisp, const OSD_Entry *selected)
75 UNUSED(pDisp);
76 UNUSED(selected);
78 tfp_sprintf(gyroCalibrationStatus, sensors(SENSOR_GYRO) ? gyroIsCalibrationComplete() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
79 #if defined(USE_ACC)
80 tfp_sprintf(accCalibrationStatus, sensors(SENSOR_ACC) ? accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_NOK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
81 #endif
82 #if defined(USE_BARO)
83 tfp_sprintf(baroCalibrationStatus, sensors(SENSOR_BARO) ? baroIsCalibrated() ? CALIBRATION_STATUS_OK : CALIBRATION_STATUS_WAIT: CALIBRATION_STATUS_OFF);
84 #endif
86 return NULL;
89 static const void *cmsCalibrateGyro(displayPort_t *pDisp, const void *self)
91 UNUSED(pDisp);
92 UNUSED(self);
94 if (sensors(SENSOR_GYRO)) {
95 gyroStartCalibration(false);
98 return NULL;
101 #if defined(USE_ACC)
102 static const void *cmsCalibrateAcc(displayPort_t *pDisp, const void *self)
104 UNUSED(pDisp);
105 UNUSED(self);
107 if (sensors(SENSOR_ACC)) {
108 accStartCalibration();
111 return MENU_CHAIN_BACK;
113 #endif
115 #if defined(USE_BARO)
116 static const void *cmsCalibrateBaro(displayPort_t *pDisp, const void *self)
118 UNUSED(pDisp);
119 UNUSED(self);
121 if (sensors(SENSOR_BARO)) {
122 baroStartCalibration();
125 return NULL;
127 #endif
129 #if defined(USE_ACC)
130 static const OSD_Entry menuCalibrateAccEntries[] = {
131 { "--- CALIBRATE ACC ---", OME_Label, NULL, NULL },
132 { "PLACE ON A LEVEL SURFACE", OME_Label, NULL, NULL},
133 { "MAKE SURE CRAFT IS STILL", OME_Label, NULL, NULL},
134 { " ", OME_Label, NULL, NULL},
135 { "START CALIBRATION", OME_Funcall, cmsCalibrateAcc, NULL },
136 { "BACK", OME_Back, NULL, NULL },
137 { NULL, OME_END, NULL, NULL}
140 CMS_Menu cmsx_menuCalibrateAcc = {
141 #ifdef CMS_MENU_DEBUG
142 .GUARD_text = "ACCCALIBRATION",
143 .GUARD_type = OME_MENU,
144 #endif
145 .onEnter = NULL,
146 .onExit = NULL,
147 .onDisplayUpdate = NULL,
148 .entries = menuCalibrateAccEntries
151 const void *cmsCalibrateAccMenu(displayPort_t *pDisp, const void *self)
153 UNUSED(self);
155 if (sensors(SENSOR_ACC)) {
156 cmsMenuChange(pDisp, &cmsx_menuCalibrateAcc);
159 return NULL;
162 #endif
164 static const OSD_Entry menuCalibrationEntries[] = {
165 { "--- CALIBRATE ---", OME_Label, NULL, NULL },
166 { "GYRO", OME_Funcall | DYNAMIC, cmsCalibrateGyro, gyroCalibrationStatus },
167 #if defined(USE_ACC)
168 { "ACC", OME_Funcall | DYNAMIC, cmsCalibrateAccMenu, accCalibrationStatus },
169 #endif
170 #if defined(USE_BARO)
171 { "BARO", OME_Funcall | DYNAMIC, cmsCalibrateBaro, baroCalibrationStatus },
172 #endif
173 { "BACK", OME_Back, NULL, NULL },
174 { NULL, OME_END, NULL, NULL}
177 static CMS_Menu cmsx_menuCalibration = {
178 #ifdef CMS_MENU_DEBUG
179 .GUARD_text = "MENUCALIBRATION",
180 .GUARD_type = OME_MENU,
181 #endif
182 .onEnter = NULL,
183 .onExit = NULL,
184 .onDisplayUpdate = cmsx_CalibrationOnDisplayUpdate,
185 .entries = menuCalibrationEntries
188 // Info
190 #if defined(USE_BOARD_INFO)
191 static char manufacturerId[MAX_MANUFACTURER_ID_LENGTH + 1];
192 static char boardName[MAX_BOARD_NAME_LENGTH + 1];
194 static const void *cmsx_FirmwareInit(displayPort_t *pDisp)
196 UNUSED(pDisp);
198 strncpy(manufacturerId, getManufacturerId(), MAX_MANUFACTURER_ID_LENGTH + 1);
199 strncpy(boardName, getBoardName(), MAX_BOARD_NAME_LENGTH + 1);
201 return NULL;
203 #endif
205 static const OSD_Entry menuFirmwareEntries[] = {
206 { "--- INFO ---", OME_Label, NULL, NULL },
207 { "FWID", OME_String, NULL, FC_FIRMWARE_IDENTIFIER },
208 { "FWVER", OME_String, NULL, FC_VERSION_STRING },
209 { "GITREV", OME_String, NULL, __REVISION__ },
210 { "TARGET", OME_String, NULL, __TARGET__ },
211 #if defined(USE_BOARD_INFO)
212 { "MFR", OME_String, NULL, manufacturerId },
213 { "BOARD", OME_String, NULL, boardName },
214 #endif
215 { "--- SETUP ---", OME_Label, NULL, NULL },
216 { "CALIBRATE", OME_Submenu, cmsMenuChange, &cmsx_menuCalibration},
217 { "BACK", OME_Back, NULL, NULL },
218 { NULL, OME_END, NULL, NULL}
221 CMS_Menu cmsx_menuFirmware = {
222 #ifdef CMS_MENU_DEBUG
223 .GUARD_text = "MENUFIRMWARE",
224 .GUARD_type = OME_MENU,
225 #endif
226 #if defined(USE_BOARD_INFO)
227 .onEnter = cmsx_FirmwareInit,
228 #else
229 .onEnter = NULL,
230 #endif
231 .onExit = NULL,
232 .onDisplayUpdate = NULL,
233 .entries = menuFirmwareEntries
235 #endif