Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add battery voltage warnings setup via LUA from radio #515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add battery voltage warnings setup via LUA from radio
Related to #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.
  • Loading branch information
vishwamartur committed Dec 29, 2024
commit 6f2f28244c45fa8e8061c243b64fa5940dd89af6
46 changes: 46 additions & 0 deletions src/SCRIPTS/BF/battery_voltage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local MSP_SET_BATTERY_CONFIG = 210
local MSP_BATTERY_CONFIG = 211

local batteryConfig = {
warningVoltage = 0,
minVoltage = 0,
batteryType = 0
}

local function processMspReply(cmd, payload, err)
if cmd == MSP_BATTERY_CONFIG and not err then
batteryConfig.warningVoltage = payload[1]
batteryConfig.minVoltage = payload[2]
batteryConfig.batteryType = payload[3]
end
end

local function getBatteryConfig()
protocol.mspRead(MSP_BATTERY_CONFIG)
mspProcessTxQ()
processMspReply(mspPollReply())
end

local function setBatteryConfig()
local values = {
batteryConfig.warningVoltage,
batteryConfig.minVoltage,
batteryConfig.batteryType
}
protocol.mspWrite(MSP_SET_BATTERY_CONFIG, values)
mspProcessTxQ()
processMspReply(mspPollReply())
end

local function init()
getBatteryConfig()
end

local function run(event)
if event == EVT_VIRTUAL_ENTER then
setBatteryConfig()
end
return 0
end

return { init = init, run = run }
2 changes: 2 additions & 0 deletions src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ if apiVersion >= 1.45 and features.osdSD then
PageFiles[#PageFiles + 1] = { title = "OSD Elements", script = "pos_osd.lua" }
end

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

return PageFiles
1 change: 1 addition & 0 deletions src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ local function createPopupMenu()
if apiVersion >= 1.44 then
popupMenu[#popupMenu + 1] = { t = "board info", f = function() confirm("CONFIRM/pwm.lua") end }
end
popupMenu[#popupMenu + 1] = { t = "battery settings", f = function() confirm("battery_voltage.lua") end }
end

local function processMspReply(cmd,rx_buf,err)
Expand Down