edgetx icon indicating copy to clipboard operation
edgetx copied to clipboard

getSwitchIndex("L01") does return nil if switch is not defined -- Similar problem with getSourceIndex("CH1" or "TR1")

Open ChrisOhara57 opened this issue 2 years ago • 9 comments

Is there an existing issue for this problem?

  • [X] I have searched the existing issues

What part of EdgeTX is the focus of this bug?

Transmitter firmware

Current Behavior

I write scripts in LUA. Usually I look for magic numbers, in this case it is the switch index of Logical Switch L01. I use this number as reference by adding up values to get the index position of the other logical switches.

Changing my existing code to use getSwitchIndex("L01") got me into trouble. In fact I do get 36 only if the logical switch L01 is really defined. Otherwise I do get nil.

The work around at the moment is: check whether the switch is defined - if not create a dummy L01 - read its index - delete L01

Expected Behavior

I expect that I always get L01 = 36 (at least on a x9lites) because that's the reserved index for L01.

If it is really necessary to return the result whether the switch is defined then I would prefer to have two return values - one for the Index and one (true/false) whether the switch is defined or not. The number of the switch index L01 does always exist and therefore should always be returned as a value.

I think this behavior does make sense for hardware switches. If for example a radio does not have a switch "SD" then there is also no index number reserved for the switch in the index list. So nil is ok then.

Steps To Reproduce

Write small Lua with

getSwitchIndex("L01") 

and check for nil (if L01 is not defined in the model)

Version

2.8.0

Transmitter

FrSky X9 Lite / Lite S

Anything else?

No response

ChrisOhara57 avatar Jan 22 '23 20:01 ChrisOhara57