getValue (94) upsets Companion and TX

Help with any software/desktop related issues. e.g. companion9x, eePe, etc
Post Reply
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

getValue (94) upsets Companion and TX

Post by Richard »

I am trying to read the SC switch, but OpenTx does not like it, showing (error) in the screen.
I am running 2.0.18
This is the Lua:

local getval=0
local strval=0
local outputs = {"Cons", "Read","SF","SC"}
local switch = 1024
local active=0
local data
local scswitch=1024

function run(store)
switch=getValue (94)
scswitch=getValue(97)
if switch <0 and active==0 then
active=1
gval=getValue (218)
model.setGlobalVariable(0, 8, ((gval/2.4414)-1024))
strval=(((model.getGlobalVariable(0,8))+1024)*2.4414)/10
end
return gval*10.24, strval*10.24,switch, scswitch
end
return {run=run, output=outputs}

If I use (95) or (97) fir the variable switch, everything is fine, but I try (94) the lua gets the error. When I use switch=getValue (97) and scswitch= get value (94), I can see in the screen: SF = 100 (or -100) and SC =100 ( or 0 or -100), depending on the position of the switches.

Can someone help, please?
Richard

User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: getValue (94) upsets Companion and TX

Post by Kilrah »

What are you actually trying to read? Calling getValue with a constant has been deprecated for at least a year, you should use getFieldInfo at runtime to retrieve the correct index.

https://opentx.gitbooks.io/opentx-lua-r ... Value.html
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: getValue (94) upsets Companion and TX

Post by Richard »

What I want to achieve, is to read the consumption from the FCS 150 current sensor, save it in a GV location at the end of the flight, and read it back at the beginning of the next flight to accumulate the battery consumption, instead of using a timer, to guesstimate the flight time. I saw this storing/reading in a lua example, and it mostly seems to work, with the exception that I cannot use my motor shoot-down switch (SC) to control the read/write.
Anyhow, I will take a look at the link you provided, and see if that helps me with that.
Richard
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: getValue (94) upsets Companion and TX

Post by Richard »

Kilrah, The link you are making reference to is for 2.0.19, anyhow, the codes are the same as for 2.0.18. Regardless, when I change the instruction from getValue('sf') to getFieldInfo('sf'), was even worse, as in this case, never mind which switch I use I get (error) in the screen.
Attachments
screen.jpg
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: getValue (94) upsets Companion and TX

Post by Kilrah »

You can't just swap it in like that, read getFieldInfo()'s doc to see how to use it...

https://opentx.gitbooks.io/opentx-lua-r ... dInfo.html

Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: getValue (94) upsets Companion and TX

Post by Richard »

It looks that either I am too fool or we don't understand each other. getFieldInfo() seems to be an excellent tool to find out the field information. As a matter of fact, I confirmed the code (94) that I was using for SC is correct, and the name I was using for GPS speed was wrong, but what I need is to "read" the position of the switch (1024-0-(-1024)), which I can do. However, the problem is that the instruction "if switch <0 and active==0 then" goes nuts when I use switch=getValue (94) instead of switch=getValue (97). To walk around this, I had to define an special function that sets GV9 to -100 when SC is up and GV9=100 when SC is down, and make switch=getValue ('gvar9') to run the if.....then.
What I may need though is a lead on the value limits for the switches and sliders, as they seems not to be same. I suspect that the value I am getting from SC is in a different magnitude than that form SF, and that could be the reason for the problem.

One other thing I noticed today is that I cannot represent a number bigger than 3199 in the output. When the number I represent is 3200 it appears a minus sign and from there on, it counts backward.
Richard
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: getValue (94) upsets Companion and TX

Post by Richard »

I finally understood what Kilrah was trying to explain on the parameters code. Simply, the ID codes CANNOT BE USED in Opentx Luas. Instead the parameters names should be used. In my case, 'sc' will make things work. I further successfully used other names as 'consumption', 'distance', and will soon verify those related with the GPS data.
Richard

Post Reply

Return to “Software”