vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / main / cms / cms_menu_battery.c
blobc6abcdace1b26711e49dbfe7cf0edbd09327b878
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #ifdef USE_CMS
25 #include "common/utils.h"
27 #include "config/feature.h"
29 #include "cms/cms.h"
30 #include "cms/cms_types.h"
31 #include "cms/cms_menu_misc.h"
33 #include "fc/config.h"
34 #include "fc/rc_controls.h"
35 #include "fc/settings.h"
37 #include "sensors/battery.h"
39 // Battery menu
41 static uint8_t battDispProfileIndex;
42 static uint8_t battProfileIndex;
43 static bool featureProfAutoswitchEnabled;
44 static char battProfileIndexString[] = " p";
47 static long cmsx_menuBattery_onEnter(const OSD_Entry *from)
49 UNUSED(from);
51 battProfileIndex = getConfigBatteryProfile();
52 battDispProfileIndex = battProfileIndex + 1;
53 battProfileIndexString[1] = '0' + battDispProfileIndex;
54 featureProfAutoswitchEnabled = feature(FEATURE_BAT_PROFILE_AUTOSWITCH);
56 return 0;
59 static long cmsx_menuBattery_onExit(const OSD_Entry *self)
61 UNUSED(self);
63 setConfigBatteryProfile(battProfileIndex);
64 activateBatteryProfile();
66 if (featureProfAutoswitchEnabled) {
67 featureSet(FEATURE_BAT_PROFILE_AUTOSWITCH);
68 } else {
69 featureClear(FEATURE_BAT_PROFILE_AUTOSWITCH);
72 return 0;
75 static long cmsx_onBatteryProfileIndexChange(displayPort_t *displayPort, const void *ptr)
77 UNUSED(displayPort);
78 UNUSED(ptr);
80 battProfileIndex = battDispProfileIndex - 1;
81 battProfileIndexString[1] = '0' + battDispProfileIndex;
82 batteryDisableProfileAutoswitch();
84 return 0;
87 static long cmsx_menuBattSettings_onEnter(const OSD_Entry *from)
89 UNUSED(from);
91 setConfigBatteryProfile(battProfileIndex);
93 return 0;
96 static const OSD_Entry menuBattSettingsEntries[]=
98 OSD_LABEL_DATA_ENTRY("-- BATT SETTINGS --", battProfileIndexString),
100 #ifdef USE_ADC
101 OSD_SETTING_ENTRY("CELLS", SETTING_BAT_CELLS),
102 OSD_SETTING_ENTRY("CELL DET.", SETTING_VBAT_CELL_DETECT_VOLTAGE),
103 OSD_SETTING_ENTRY("CELL MAX", SETTING_VBAT_MAX_CELL_VOLTAGE),
104 OSD_SETTING_ENTRY("CELL WARN", SETTING_VBAT_WARNING_CELL_VOLTAGE),
105 OSD_SETTING_ENTRY("CELL MIN", SETTING_VBAT_MIN_CELL_VOLTAGE),
106 #endif /* USE_ADC */
107 OSD_SETTING_ENTRY("CAP UNIT", SETTING_BATTERY_CAPACITY_UNIT),
108 OSD_SETTING_ENTRY("CAPACITY", SETTING_BATTERY_CAPACITY),
109 OSD_SETTING_ENTRY("CAP WARN", SETTING_BATTERY_CAPACITY_WARNING),
110 OSD_SETTING_ENTRY("CAP CRIT", SETTING_BATTERY_CAPACITY_CRITICAL),
112 OSD_BACK_AND_END_ENTRY,
115 static CMS_Menu cmsx_menuBattSettings = {
116 #ifdef CMS_MENU_DEBUG
117 .GUARD_text = "XBATT",
118 .GUARD_type = OME_MENU,
119 #endif
120 .onEnter = cmsx_menuBattSettings_onEnter,
121 .onExit = NULL,
122 .onGlobalExit = NULL,
123 .entries = menuBattSettingsEntries
126 static OSD_Entry menuBatteryEntries[]=
128 OSD_LABEL_ENTRY("-- BATTERY --"),
130 #ifdef USE_ADC
131 OSD_BOOL_ENTRY("PROF AUTOSWITCH", &featureProfAutoswitchEnabled),
132 #endif
133 OSD_UINT8_CALLBACK_ENTRY("PROF", cmsx_onBatteryProfileIndexChange, (&(const OSD_UINT8_t){ &battDispProfileIndex, 1, MAX_BATTERY_PROFILE_COUNT, 1})),
134 OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuBattSettings),
136 OSD_BACK_AND_END_ENTRY,
139 CMS_Menu cmsx_menuBattery = {
140 #ifdef CMS_MENU_DEBUG
141 .GUARD_text = "XBATT",
142 .GUARD_type = OME_MENU,
143 #endif
144 .onEnter = cmsx_menuBattery_onEnter,
145 .onExit = cmsx_menuBattery_onExit,
146 .onGlobalExit = NULL,
147 .entries = menuBatteryEntries
150 #endif // CMS