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/>.
31 #include "cms/cms_types.h"
32 #include "cms/cms_menu_power.h"
34 #include "config/feature.h"
36 #include "sensors/battery.h"
37 #include "sensors/current.h"
38 #include "sensors/voltage.h"
40 #include "config/config.h"
42 voltageMeterSource_e batteryConfig_voltageMeterSource
;
43 currentMeterSource_e batteryConfig_currentMeterSource
;
45 uint16_t batteryConfig_vbatmincellvoltage
;
46 uint16_t batteryConfig_vbatmaxcellvoltage
;
47 uint16_t batteryConfig_vbatwarningcellvoltage
;
49 uint8_t voltageSensorADCConfig_vbatscale
;
51 int16_t currentSensorADCConfig_scale
;
52 int16_t currentSensorADCConfig_offset
;
54 #ifdef USE_VIRTUAL_CURRENT_METER
55 int16_t currentSensorVirtualConfig_scale
;
56 uint16_t currentSensorVirtualConfig_offset
;
59 static const void *cmsx_Power_onEnter(displayPort_t
*pDisp
)
63 batteryConfig_voltageMeterSource
= batteryConfig()->voltageMeterSource
;
64 batteryConfig_currentMeterSource
= batteryConfig()->currentMeterSource
;
66 batteryConfig_vbatmincellvoltage
= batteryConfig()->vbatmincellvoltage
;
67 batteryConfig_vbatmaxcellvoltage
= batteryConfig()->vbatmaxcellvoltage
;
68 batteryConfig_vbatwarningcellvoltage
= batteryConfig()->vbatwarningcellvoltage
;
70 voltageSensorADCConfig_vbatscale
= voltageSensorADCConfig(0)->vbatscale
;
72 currentSensorADCConfig_scale
= currentSensorADCConfig()->scale
;
73 currentSensorADCConfig_offset
= currentSensorADCConfig()->offset
;
75 #ifdef USE_VIRTUAL_CURRENT_METER
76 currentSensorVirtualConfig_scale
= currentSensorVirtualConfig()->scale
;
77 currentSensorVirtualConfig_offset
= currentSensorVirtualConfig()->offset
;
83 static const void *cmsx_Power_onExit(displayPort_t
*pDisp
, const OSD_Entry
*self
)
88 batteryConfigMutable()->voltageMeterSource
= batteryConfig_voltageMeterSource
;
89 batteryConfigMutable()->currentMeterSource
= batteryConfig_currentMeterSource
;
91 batteryConfigMutable()->vbatmincellvoltage
= batteryConfig_vbatmincellvoltage
;
92 batteryConfigMutable()->vbatmaxcellvoltage
= batteryConfig_vbatmaxcellvoltage
;
93 batteryConfigMutable()->vbatwarningcellvoltage
= batteryConfig_vbatwarningcellvoltage
;
95 voltageSensorADCConfigMutable(0)->vbatscale
= voltageSensorADCConfig_vbatscale
;
97 currentSensorADCConfigMutable()->scale
= currentSensorADCConfig_scale
;
98 currentSensorADCConfigMutable()->offset
= currentSensorADCConfig_offset
;
100 #ifdef USE_VIRTUAL_CURRENT_METER
101 currentSensorVirtualConfigMutable()->scale
= currentSensorVirtualConfig_scale
;
102 currentSensorVirtualConfigMutable()->offset
= currentSensorVirtualConfig_offset
;
108 static const OSD_Entry cmsx_menuPowerEntries
[] =
110 { "-- POWER --", OME_Label
, NULL
, NULL
},
112 { "V METER", OME_TAB
| REBOOT_REQUIRED
, NULL
, &(OSD_TAB_t
){ &batteryConfig_voltageMeterSource
, VOLTAGE_METER_COUNT
- 1, voltageMeterSourceNames
} },
113 { "I METER", OME_TAB
| REBOOT_REQUIRED
, NULL
, &(OSD_TAB_t
){ &batteryConfig_currentMeterSource
, CURRENT_METER_COUNT
- 1, currentMeterSourceNames
} },
115 { "VBAT CLMIN", OME_UINT16
, NULL
, &(OSD_UINT16_t
) { &batteryConfig_vbatmincellvoltage
, VBAT_CELL_VOTAGE_RANGE_MIN
, VBAT_CELL_VOTAGE_RANGE_MAX
, 1 } },
116 { "VBAT CLMAX", OME_UINT16
, NULL
, &(OSD_UINT16_t
) { &batteryConfig_vbatmaxcellvoltage
, VBAT_CELL_VOTAGE_RANGE_MIN
, VBAT_CELL_VOTAGE_RANGE_MAX
, 1 } },
117 { "VBAT CLWARN", OME_UINT16
, NULL
, &(OSD_UINT16_t
) { &batteryConfig_vbatwarningcellvoltage
, VBAT_CELL_VOTAGE_RANGE_MIN
, VBAT_CELL_VOTAGE_RANGE_MAX
, 1 } },
119 { "VBAT SCALE", OME_UINT8
, NULL
, &(OSD_UINT8_t
){ &voltageSensorADCConfig_vbatscale
, VBAT_SCALE_MIN
, VBAT_SCALE_MAX
, 1 } },
121 { "IBAT SCALE", OME_INT16
, NULL
, &(OSD_INT16_t
){ ¤tSensorADCConfig_scale
, -16000, 16000, 5 } },
122 { "IBAT OFFSET", OME_INT16
, NULL
, &(OSD_INT16_t
){ ¤tSensorADCConfig_offset
, -32000, 32000, 5 } },
124 #ifdef USE_VIRTUAL_CURRENT_METER
125 { "IBAT VIRT SCALE", OME_INT16
, NULL
, &(OSD_INT16_t
){ ¤tSensorVirtualConfig_scale
, -16000, 16000, 5 } },
126 { "IBAT VIRT OFFSET", OME_UINT16
, NULL
, &(OSD_UINT16_t
){ ¤tSensorVirtualConfig_offset
, 0, 16000, 5 } },
129 { "BACK", OME_Back
, NULL
, NULL
},
130 { NULL
, OME_END
, NULL
, NULL
}
133 CMS_Menu cmsx_menuPower
= {
134 #ifdef CMS_MENU_DEBUG
135 .GUARD_text
= "MENUPWR",
136 .GUARD_type
= OME_MENU
,
138 .onEnter
= cmsx_Power_onEnter
,
139 .onExit
= cmsx_Power_onExit
,
140 .onDisplayUpdate
= NULL
,
141 .entries
= cmsx_menuPowerEntries