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

Unable to get VTX power labels (#70 Betaflight LUA)

Open skorzo opened this issue 6 years ago • 19 comments

Currently running: Betaflight 4.1.1 (omnibus F4 V6) OpenTx 2.3.1 (Taranis 9XD plus) TBS Pro Race v2 (smartaudio 2.1) Betaflight LUA compilation #70 https://ci.betaflight.tech/job/Betaflight%20Lua%20-%20X7,%20X9,%20X9D,%20X9D+,%20X10,%20X12/lastSuccessfulBuild/artifact/

I have set up the Vtx tables and then I put the model_name.lua in /BF/VTX

Lua Script is working fine but power labels are not showing. I get "0" and "1" values and not my labels (25, 200, 400)

skorzo avatar Dec 09 '19 08:12 skorzo

Same here with SA 1.0, getting 0 and 1 values. With SA 2.0 Tbs Race device I have getting 200 correct value, but cant change it to another power.

asizon avatar Dec 09 '19 08:12 asizon

Sorry, but only my 2.0 device is in Betaflight 4.2 version, I think that for get correct model.lua file 4.2 is needed, but I cant change power level, only 200.

asizon avatar Dec 09 '19 08:12 asizon

@Asizon, @skorzo can you paste your "model_name.lua" here, and also confirm that the model_name part matches the "Model Name" in your transmitter?

rj-cooper avatar Dec 09 '19 09:12 rj-cooper

@Asizon, @skorzo can you paste your "model_name.lua" here, and also confirm that the model_name part matches the "Model Name" in your transmitter?

Please find it attached.

Rooster_R9M.zip

The name matches the "Model Name", even with the "_" for "Rooster_R9M" When the name does not match, the shown power values are the legacy ones.

Thanks!

skorzo avatar Dec 09 '19 10:12 skorzo

IMG_20191209_074049 Model name correct, matches with transmitter model name. Also .lua file seems show correct values AK200R5.zip . with this setup,Lua show me 200 power value, but cant change it.

asizon avatar Dec 09 '19 12:12 asizon

IMG_20191209_074337 With this test using SA 1.0, Lua show me 0 and 1 power values. AK200R4.zip

asizon avatar Dec 09 '19 12:12 asizon

It's a bug in the vtx lua script and/or betaflight configurator. I'll look at it today and see if I can get you a fix...

rj-cooper avatar Dec 09 '19 12:12 rj-cooper

powerTable = { [7]=25 , [16]=200, [25]=600, }, The indexing is the problem. The tables are using the powervalues as indexes, but I believe these tables should be indexed from 0 as the range of vtx_power is 0 to 7. Also when we try getting the number of elements of a table like that using # the result will be 0. Probably because the element at index = 1 is nil.

klutvott123 avatar Dec 09 '19 12:12 klutvott123

@klutvott123 yes - the index shouldn't be the index as for some SA versions it's set in dB rather than an index. Will it be best to have a powertable like the following?

powerTable = {
    { 7, "25" },
    {16, "200"},
    {25, "600"},
}

which would look like the following for the old SA1.0 style settings

powerTable = {
    {0, "25" },
    {1, "200"},
    {2  "600"},
}

rj-cooper avatar Dec 09 '19 12:12 rj-cooper

@frozenskys That would probably work. Do we need the powervalues for the lua script? Wouldn't it be easiest to just not add them to the table since we're just using the labels?

klutvott123 avatar Dec 09 '19 12:12 klutvott123

@klutvott123 I need to check how the power levels work... if we are only sending the "BF power index" or label to BF then that's OK - if it's expecting the dB value or the "VTX power index" then no... Would definitely be an easier change if we only need the labels.

@asizon can you try changing the powerTable line in your lua file to the following, copy to your radio, and retest?

powerTable = { [0]=25 , [1]=200, [2]=600, },

rj-cooper avatar Dec 09 '19 13:12 rj-cooper

@frozenskys Ok, Lua's show me correct values, but only can change between 200 and 600 IMG_20191209_141703 IMG_20191209_141718

asizon avatar Dec 09 '19 13:12 asizon

@Asizon OK - but does it actually change the VTX power levels? I'm not at my bench so can't test this for myself...

You can also try

powerTable = { [1]=25, [2]=200, [3]=600, },

and see if that gives you all three power levels?

rj-cooper avatar Dec 09 '19 13:12 rj-cooper

Done! three power levels available, checked with Betaflight Configurator and the power changes are effective.

asizon avatar Dec 09 '19 13:12 asizon

@klutvott123 that would seem to say that we just need the labels - but need to start with an index of 1... so I'd say it's just a change to the configurator to write the correct values...

rj-cooper avatar Dec 09 '19 13:12 rj-cooper

Fix for the configurator looks simple - I'll give it a test when I get back and open a PR if it's OK...

rj-cooper avatar Dec 09 '19 15:12 rj-cooper

@frozenskys Nice! I would test if I could but I don't actually own a VTX lol.

klutvott123 avatar Dec 09 '19 17:12 klutvott123

@skorzo while I'm working on the fix for the configurator, setting your powerTable in the lua file to the following should get it working for you...

powerTable = { [1]=25 , [2]=100, [3]=400, },

rj-cooper avatar Dec 09 '19 19:12 rj-cooper

@skorzo while I'm working on the fix for the configurator, setting your powerTable in the lua file to the following should get it working for you...

powerTable = { [1]=25 , [2]=100, [3]=400, },

Yes, it works! Label is shown and power is correctly changed. Many thanks for your job

skorzo avatar Dec 09 '19 20:12 skorzo