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 // Firmware related menu contents and support functions
34 #include "build/version.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"
50 #include "sensors/acceleration.h"
51 #include "sensors/barometer.h"
52 #include "sensors/gyro.h"
54 #include "cms_menu_firmware.h"
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
];
68 static char accCalibrationStatus
[CALIBRATION_STATUS_MAX_LENGTH
];
71 static char baroCalibrationStatus
[CALIBRATION_STATUS_MAX_LENGTH
];
74 static const void *cmsx_CalibrationOnDisplayUpdate(displayPort_t
*pDisp
, const OSD_Entry
*selected
)
79 tfp_sprintf(gyroCalibrationStatus
, sensors(SENSOR_GYRO
) ? gyroIsCalibrationComplete() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
81 tfp_sprintf(accCalibrationStatus
, sensors(SENSOR_ACC
) ? accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_NOK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
84 tfp_sprintf(baroCalibrationStatus
, sensors(SENSOR_BARO
) ? baroIsCalibrationComplete() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
90 static const void *cmsCalibrateGyro(displayPort_t
*pDisp
, const void *self
)
95 if (sensors(SENSOR_GYRO
)) {
96 gyroStartCalibration(false);
103 static const void *cmsCalibrateAcc(displayPort_t
*pDisp
, const void *self
)
108 if (sensors(SENSOR_ACC
)) {
109 accStartCalibration();
112 return MENU_CHAIN_BACK
;
116 #if defined(USE_BARO)
117 static const void *cmsCalibrateBaro(displayPort_t
*pDisp
, const void *self
)
122 if (sensors(SENSOR_BARO
)) {
123 baroStartCalibration();
131 static const OSD_Entry menuCalibrateAccEntries
[] = {
132 { "--- CALIBRATE ACC ---", OME_Label
, NULL
, NULL
, 0 },
133 { "PLACE ON A LEVEL SURFACE", OME_Label
, NULL
, NULL
, 0},
134 { "MAKE SURE CRAFT IS STILL", OME_Label
, NULL
, NULL
, 0},
135 { " ", OME_Label
, NULL
, NULL
, 0},
136 { "START CALIBRATION", OME_Funcall
, cmsCalibrateAcc
, NULL
, 0 },
137 { "BACK", OME_Back
, NULL
, NULL
, 0 },
138 { NULL
, OME_END
, NULL
, NULL
, 0 }
141 CMS_Menu cmsx_menuCalibrateAcc
= {
142 #ifdef CMS_MENU_DEBUG
143 .GUARD_text
= "ACCCALIBRATION",
144 .GUARD_type
= OME_MENU
,
148 .onDisplayUpdate
= NULL
,
149 .entries
= menuCalibrateAccEntries
152 const void *cmsCalibrateAccMenu(displayPort_t
*pDisp
, const void *self
)
156 if (sensors(SENSOR_ACC
)) {
157 cmsMenuChange(pDisp
, &cmsx_menuCalibrateAcc
);
165 static const OSD_Entry menuCalibrationEntries
[] = {
166 { "--- CALIBRATE ---", OME_Label
, NULL
, NULL
, 0 },
167 { "GYRO", OME_Funcall
, cmsCalibrateGyro
, gyroCalibrationStatus
, DYNAMIC
},
169 { "ACC", OME_Funcall
, cmsCalibrateAccMenu
, accCalibrationStatus
, DYNAMIC
},
171 #if defined(USE_BARO)
172 { "BARO", OME_Funcall
, cmsCalibrateBaro
, baroCalibrationStatus
, DYNAMIC
},
174 { "BACK", OME_Back
, NULL
, NULL
, 0 },
175 { NULL
, OME_END
, NULL
, NULL
, 0 }
178 static CMS_Menu cmsx_menuCalibration
= {
179 #ifdef CMS_MENU_DEBUG
180 .GUARD_text
= "MENUCALIBRATION",
181 .GUARD_type
= OME_MENU
,
185 .onDisplayUpdate
= cmsx_CalibrationOnDisplayUpdate
,
186 .entries
= menuCalibrationEntries
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
)
199 strncpy(manufacturerId
, getManufacturerId(), MAX_MANUFACTURER_ID_LENGTH
+ 1);
200 strncpy(boardName
, getBoardName(), MAX_BOARD_NAME_LENGTH
+ 1);
206 static const OSD_Entry menuFirmwareEntries
[] = {
207 { "--- INFO ---", OME_Label
, NULL
, NULL
, 0 },
208 { "FWID", OME_String
, NULL
, FC_FIRMWARE_IDENTIFIER
, 0 },
209 { "FWVER", OME_String
, NULL
, FC_VERSION_STRING
, 0 },
210 { "GITREV", OME_String
, NULL
, __REVISION__
, 0 },
211 { "TARGET", OME_String
, NULL
, __TARGET__
, 0 },
212 #if defined(USE_BOARD_INFO)
213 { "MFR", OME_String
, NULL
, manufacturerId
, 0 },
214 { "BOARD", OME_String
, NULL
, boardName
, 0 },
216 { "--- SETUP ---", OME_Label
, NULL
, NULL
, 0 },
217 { "CALIBRATE", OME_Submenu
, cmsMenuChange
, &cmsx_menuCalibration
, 0},
218 { "BACK", OME_Back
, NULL
, NULL
, 0 },
219 { NULL
, OME_END
, NULL
, NULL
, 0 }
222 CMS_Menu cmsx_menuFirmware
= {
223 #ifdef CMS_MENU_DEBUG
224 .GUARD_text
= "MENUFIRMWARE",
225 .GUARD_type
= OME_MENU
,
227 #if defined(USE_BOARD_INFO)
228 .onEnter
= cmsx_FirmwareInit
,
233 .onDisplayUpdate
= NULL
,
234 .entries
= menuFirmwareEntries