betaflight-tx-lua-scripts icon indicating copy to clipboard operation
betaflight-tx-lua-scripts copied to clipboard

Add battery voltage warnings setup via LUA from radio

Open vishwamartur opened this issue 1 year ago • 1 comments

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.

vishwamartur avatar Dec 29 '24 17:12 vishwamartur

Is there a reason why this can't just be a regular page like the rest of them? 🙂

klutvott123 avatar Feb 07 '25 20:02 klutvott123

I wanted to built something like this on my own, but saw your PR - thank you and I hope it gets merged at some point.

After compiling the script, I can however not open the battery page, when selecting it on a monochrome display, I get the error that battery_voltage.lua was not found. After moving the file to the SCRIPTS/BF/PAGES folder (currently it is in the SCRIPTS/BF folder), it finds the file, but then I get the error

Syntax error ?:0 attempt to index field 'fields' (a nil value).

Looking through the other page files, all start with

local template = assert(loadScript(radio.template))()
local margin = template.margin
local indent = template.indent
local lineSpacing = template.lineSpacing
local tableSpacing = template.tableSpacing
local sp = template.listSpacing.field
local yMinLim = radio.yMinLimit
local x = margin
local y = yMinLim - lineSpacing
local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end }
local labels = {}
local fields = {}

and have a different syntax. So I think it needs to be modified to work, before it can be merged.

Also you set the MSP commands to 210 and 211 - however they are defined as

#define MSP_SELECT_SETTING              210  // in message:  Select setting number (0-2)
#define MSP_SET_HEADING                 211  // in message:  Define a new heading hold direction

So would that even work?

Forceu avatar Jul 21 '25 09:07 Forceu

This is not the correct way to do it. Closing

klutvott123 avatar Aug 01 '25 22:08 klutvott123