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"
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
];
67 static char accCalibrationStatus
[CALIBRATION_STATUS_MAX_LENGTH
];
70 static char baroCalibrationStatus
[CALIBRATION_STATUS_MAX_LENGTH
];
73 static const void *cmsx_CalibrationOnDisplayUpdate(displayPort_t
*pDisp
, const OSD_Entry
*selected
)
78 tfp_sprintf(gyroCalibrationStatus
, sensors(SENSOR_GYRO
) ? gyroIsCalibrationComplete() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
80 tfp_sprintf(accCalibrationStatus
, sensors(SENSOR_ACC
) ? accIsCalibrationComplete() ? accHasBeenCalibrated() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_NOK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
83 tfp_sprintf(baroCalibrationStatus
, sensors(SENSOR_BARO
) ? baroIsCalibrated() ? CALIBRATION_STATUS_OK
: CALIBRATION_STATUS_WAIT
: CALIBRATION_STATUS_OFF
);
89 static const void *cmsCalibrateGyro(displayPort_t
*pDisp
, const void *self
)
94 if (sensors(SENSOR_GYRO
)) {
95 gyroStartCalibration(false);
102 static const void *cmsCalibrateAcc(displayPort_t
*pDisp
, const void *self
)
107 if (sensors(SENSOR_ACC
)) {
108 accStartCalibration();
111 return MENU_CHAIN_BACK
;
115 #if defined(USE_BARO)
116 static const void *cmsCalibrateBaro(displayPort_t
*pDisp
, const void *self
)
121 if (sensors(SENSOR_BARO
)) {
122 baroStartCalibration();
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
,
147 .onDisplayUpdate
= NULL
,
148 .entries
= menuCalibrateAccEntries
151 const void *cmsCalibrateAccMenu(displayPort_t
*pDisp
, const void *self
)
155 if (sensors(SENSOR_ACC
)) {
156 cmsMenuChange(pDisp
, &cmsx_menuCalibrateAcc
);
164 static const OSD_Entry menuCalibrationEntries
[] = {
165 { "--- CALIBRATE ---", OME_Label
, NULL
, NULL
},
166 { "GYRO", OME_Funcall
| DYNAMIC
, cmsCalibrateGyro
, gyroCalibrationStatus
},
168 { "ACC", OME_Funcall
| DYNAMIC
, cmsCalibrateAccMenu
, accCalibrationStatus
},
170 #if defined(USE_BARO)
171 { "BARO", OME_Funcall
| DYNAMIC
, cmsCalibrateBaro
, baroCalibrationStatus
},
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
,
184 .onDisplayUpdate
= cmsx_CalibrationOnDisplayUpdate
,
185 .entries
= menuCalibrationEntries
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
)
198 strncpy(manufacturerId
, getManufacturerId(), MAX_MANUFACTURER_ID_LENGTH
+ 1);
199 strncpy(boardName
, getBoardName(), MAX_BOARD_NAME_LENGTH
+ 1);
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
},
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
,
226 #if defined(USE_BOARD_INFO)
227 .onEnter
= cmsx_FirmwareInit
,
232 .onDisplayUpdate
= NULL
,
233 .entries
= menuFirmwareEntries