Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / cms / cms_menu_misc.c
blob149244b0f7ba7ee647ab0e005151f3844961c1a3
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/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <math.h>
27 #include "platform.h"
29 #ifdef USE_CMS
31 #include "build/version.h"
33 #include "cms/cms.h"
34 #include "cms/cms_types.h"
35 #include "cms/cms_menu_ledstrip.h"
37 #include "common/utils.h"
39 #include "config/config.h"
40 #include "config/feature.h"
42 #include "drivers/time.h"
44 #include "fc/rc_controls.h"
46 #include "flight/mixer.h"
48 #include "pg/motor.h"
49 #include "pg/pg.h"
50 #include "pg/pg_ids.h"
51 #include "pg/rx.h"
53 #include "rx/rx.h"
55 #include "sensors/battery.h"
57 #include "cms_menu_misc.h"
60 // Misc
63 static const void *cmsx_menuRcOnEnter(displayPort_t *pDisp)
65 UNUSED(pDisp);
67 inhibitSaveMenu();
69 return NULL;
72 static const void *cmsx_menuRcConfirmBack(displayPort_t *pDisp, const OSD_Entry *self)
74 UNUSED(pDisp);
76 if (self && ((self->flags & OSD_MENU_ELEMENT_MASK) == OME_Back)) {
77 return NULL;
78 } else {
79 return MENU_CHAIN_BACK;
83 static int16_t rcDataInt[AUX4 + 1];
85 static const void *cmsx_menuRcOnDisplayUpdate(displayPort_t *pDisp, const OSD_Entry *selected)
87 UNUSED(pDisp);
88 UNUSED(selected);
90 for (int i = 0; i <= AUX4; i++) {
91 rcDataInt[i] = lroundf(rcData[i]);
94 return NULL;
98 // RC preview
100 static const OSD_Entry cmsx_menuRcEntries[] =
102 { "-- RC PREV --", OME_Label, NULL, NULL},
104 { "ROLL", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[ROLL], 1, 2500, 0 } },
105 { "PITCH", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[PITCH], 1, 2500, 0 } },
106 { "THR", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[THROTTLE], 1, 2500, 0 } },
107 { "YAW", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[YAW], 1, 2500, 0 } },
109 { "AUX1", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[AUX1], 1, 2500, 0 } },
110 { "AUX2", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[AUX2], 1, 2500, 0 } },
111 { "AUX3", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[AUX3], 1, 2500, 0 } },
112 { "AUX4", OME_INT16 | DYNAMIC, NULL, &(OSD_INT16_t){ &rcDataInt[AUX4], 1, 2500, 0 } },
114 { "BACK", OME_Back, NULL, NULL},
115 {NULL, OME_END, NULL, NULL}
118 CMS_Menu cmsx_menuRcPreview = {
119 #ifdef CMS_MENU_DEBUG
120 .GUARD_text = "XRCPREV",
121 .GUARD_type = OME_MENU,
122 #endif
123 .onEnter = cmsx_menuRcOnEnter,
124 .onExit = cmsx_menuRcConfirmBack,
125 .onDisplayUpdate = cmsx_menuRcOnDisplayUpdate,
126 .entries = cmsx_menuRcEntries
129 static uint16_t motorConfig_minthrottle;
130 static uint8_t motorConfig_digitalIdleOffsetValue;
131 static uint8_t rxConfig_fpvCamAngleDegrees;
133 static const void *cmsx_menuMiscOnEnter(displayPort_t *pDisp)
135 UNUSED(pDisp);
137 motorConfig_minthrottle = motorConfig()->minthrottle;
138 motorConfig_digitalIdleOffsetValue = motorConfig()->digitalIdleOffsetValue / 10;
139 rxConfig_fpvCamAngleDegrees = rxConfig()->fpvCamAngleDegrees;
141 return NULL;
144 static const void *cmsx_menuMiscOnExit(displayPort_t *pDisp, const OSD_Entry *self)
146 UNUSED(pDisp);
147 UNUSED(self);
149 motorConfigMutable()->minthrottle = motorConfig_minthrottle;
150 motorConfigMutable()->digitalIdleOffsetValue = 10 * motorConfig_digitalIdleOffsetValue;
151 rxConfigMutable()->fpvCamAngleDegrees = rxConfig_fpvCamAngleDegrees;
153 return NULL;
156 static const OSD_Entry menuMiscEntries[]=
158 { "-- MISC --", OME_Label, NULL, NULL },
160 { "MIN THR", OME_UINT16 | REBOOT_REQUIRED, NULL, &(OSD_UINT16_t){ &motorConfig_minthrottle, 1000, 2000, 1 } },
161 { "DIGITAL IDLE", OME_UINT8 | REBOOT_REQUIRED, NULL, &(OSD_UINT8_t) { &motorConfig_digitalIdleOffsetValue, 0, 200, 1 } },
162 { "FPV CAM ANGLE", OME_UINT8, NULL, &(OSD_UINT8_t) { &rxConfig_fpvCamAngleDegrees, 0, 90, 1 } },
163 { "RC PREV", OME_Submenu, cmsMenuChange, &cmsx_menuRcPreview},
165 { "BACK", OME_Back, NULL, NULL},
166 { NULL, OME_END, NULL, NULL}
169 CMS_Menu cmsx_menuMisc = {
170 #ifdef CMS_MENU_DEBUG
171 .GUARD_text = "XMISC",
172 .GUARD_type = OME_MENU,
173 #endif
174 .onEnter = cmsx_menuMiscOnEnter,
175 .onExit = cmsx_menuMiscOnExit,
176 .onDisplayUpdate = NULL,
177 .entries = menuMiscEntries
180 #endif // CMS