Skip to content

Commit 6f2f282

Browse files
committed
Add battery voltage warnings setup via LUA from radio
Related to betaflight#505 Add battery voltage warning and minimum values configuration via LUA scripts from the radio. * **New LUA Script**: Add `src/SCRIPTS/BF/battery_voltage.lua` to handle battery voltage warning and minimum values configuration. * Define functions to read and set battery voltage warning values for different battery types (Li-ion, LiPo). * Use MSP commands to communicate with the flight controller. * **Pages Update**: Modify `src/SCRIPTS/BF/pages.lua` to include a new page entry for battery settings configuration. * Add a new page entry with the title "Battery Settings" and script "battery_voltage.lua". * **UI Update**: Modify `src/SCRIPTS/BF/ui.lua` to include the new battery settings page in the UI menu. * Add the new battery settings page to the UI menu.
1 parent 1a90024 commit 6f2f282

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/SCRIPTS/BF/battery_voltage.lua

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local MSP_SET_BATTERY_CONFIG = 210
2+
local MSP_BATTERY_CONFIG = 211
3+
4+
local batteryConfig = {
5+
warningVoltage = 0,
6+
minVoltage = 0,
7+
batteryType = 0
8+
}
9+
10+
local function processMspReply(cmd, payload, err)
11+
if cmd == MSP_BATTERY_CONFIG and not err then
12+
batteryConfig.warningVoltage = payload[1]
13+
batteryConfig.minVoltage = payload[2]
14+
batteryConfig.batteryType = payload[3]
15+
end
16+
end
17+
18+
local function getBatteryConfig()
19+
protocol.mspRead(MSP_BATTERY_CONFIG)
20+
mspProcessTxQ()
21+
processMspReply(mspPollReply())
22+
end
23+
24+
local function setBatteryConfig()
25+
local values = {
26+
batteryConfig.warningVoltage,
27+
batteryConfig.minVoltage,
28+
batteryConfig.batteryType
29+
}
30+
protocol.mspWrite(MSP_SET_BATTERY_CONFIG, values)
31+
mspProcessTxQ()
32+
processMspReply(mspPollReply())
33+
end
34+
35+
local function init()
36+
getBatteryConfig()
37+
end
38+
39+
local function run(event)
40+
if event == EVT_VIRTUAL_ENTER then
41+
setBatteryConfig()
42+
end
43+
return 0
44+
end
45+
46+
return { init = init, run = run }

src/SCRIPTS/BF/pages.lua

+2
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ if apiVersion >= 1.45 and features.osdSD then
6464
PageFiles[#PageFiles + 1] = { title = "OSD Elements", script = "pos_osd.lua" }
6565
end
6666

67+
PageFiles[#PageFiles + 1] = { title = "Battery Settings", script = "battery_voltage.lua" }
68+
6769
return PageFiles

src/SCRIPTS/BF/ui.lua

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ local function createPopupMenu()
9797
if apiVersion >= 1.44 then
9898
popupMenu[#popupMenu + 1] = { t = "board info", f = function() confirm("CONFIRM/pwm.lua") end }
9999
end
100+
popupMenu[#popupMenu + 1] = { t = "battery settings", f = function() confirm("battery_voltage.lua") end }
100101
end
101102

102103
local function processMspReply(cmd,rx_buf,err)

0 commit comments

Comments
 (0)