LUA scripting expert wanted for HELIOS prblem
-
Hi weepop here,
I am trying to add function to my helios profile and have come up against a problem.
Some rotary controls in BMS call backs have both toggle up and down plus individual call backs for each position , eg the rotary switches for UHF backup frequencies, (see section 2.16 in key file). These are no problem I can allocate a call back and an image output to them.
However some only have toggle up and down and no individual position, eg the rotary UHF channel above the frequency switches.The problem with these is I cannot tell the difference between a position being reached by either toggling up or down. This means I cannot send correct call back ie up or down. I can control image output for each position, in this case 01 to 19 but not the call back .
The answer would be individual call backs for each position but I don`t think the devs will do that.
So we come to the title of this post, can it be done with a LUA script which recognises if the switch is increasing or decreasing its position and so send appropriate call back? If you are an expert or even just OK at LUA scripting please have a look and see if you can help me.
regards weepop
-
OK no response so here is more info:-
I have decided the way to go with the channel switch is to leave the encoder output driving the in game channel switch but to make it also drive a rotary switch in helios which can be made invisible. Then to use the position of the rotary switch to drive the helios channel display.
All I need to know is the LUA script to cause the rotary to add or subtract one step from its current position.See picture showing required LUA script on a sample three position rotary
-
Never used Helios before. Is there some way to have it store variables? Like say, the current position of the rotary? All it needs to do is compare the stored rotary position with the Trigger Value, which I understand is the encoder position, and see if its higher or lower. If higher, increment the current position of the rotary. If lower, decrement.
By the way, its Lua, not LUA.
Actually, looking at the page there, it looks like you can have different instructions for whether the encoder was decremented or incremented? Either way, you still need to be able to see the current position of the rotary. Your script is going to be something along the lines of rotaryPosition = rotaryPosition + 1 for the increment, and -1 for the decrement.
-
Thanks Blu3wolf
Still struggling but I have found I can just call the individual positions of the switch (1) (2) etc in the Lua script and make the position step once up or down.
I am now trying to write a script that will recognise any position and step it up or down. The new picture shows an example with just three positions out of possible nineteen but the script is not recognised. Can you give me any pointers to improve it. -
This post is deleted! -
Cant you just use this for the decrement,
a = TriggerValue - 1 return a
and this for the increment?
a = TriggerValue + 1 return a
-
I tried it but no response.
I am encouraged by being able to step once with:-
if (2)
then
return (1) ;
endI just need to make it look at all cases, I presume my attempt at else/if is not allowed, so I hoped you might know the correct way to make it look further if
the first expression is false. -
Well, elseif should be one word. Also,
If (2)
Always returns true, so it will never get to the elseifs. So it will always do the
Return (1)
Line, which is obviously not what you want.
Does the encoder have the same number of positions as the rotary switch?
-
Does the encoder have the same number of positions as the rotary switch?
No and I have just come to the conclusion that this is my problem. The encoder only has two positions, inc or dec and the switch I am trying to drive has 19.
So what I need to know is how to name the Action Value and then either take one away or add one to when Trigger value = dec or inc. Ideas follow:-
For channel starting at default position 6 to dec or inc by 1.
(ActionValue) = a
a = 6
if (TriggerValue)
then
return a = a - 1
end(ActionValue) = a
a = 6
if (TriggerValue)
then
return a = a + 1
endI Will be trying this later today and would value your comments.
-
Well, to me it looks like you need to be able to read the position of the switch, to do what you want. Or store it in a global variable. This is the sort of thing that it would help to have details on the lua implementation for Helios.
-
I am just about ready to surrender, but before I do , I downloaded the helios program from Git Hub .
It looks too complicated for me to understand but there are references to trigger and action values that might make sense to someone with programming knowledge……Help!!
-
I am just about ready to surrender, but before I do , I downloaded the helios program from Git Hub .
It looks too complicated for me to understand but there are references to trigger and action values that might make sense to someone with programming knowledge……Help!!
I never used Lua before but i’ll take a look this evening at it if you don’t find something.
-
I have a sinking feeling that this is one of those bits of Helios that have not been finished
-
Decrement:
rotary = rotary or 1
if rotary > 1 then
rotary = rotary - 1
else
rotary = 19
end
return rotaryThe increments script would be similar
rotary = rotary or 1
if rotary < 19 then
rotary = rotary + 1
else
rotary = 1
end
return rotaryNote that these assume helios is started with the virtual knob in the number 1 position.
-
WOW Blu3wolf
That is very close to the solution. The only problem is that the two directions each remember there own stopping positions and carry on from that point.
eg Starting at 1, pressing inc three times results in 4 but then pressing dec starts again at 1 and steps back to 19 instead of starting at 4 and stepping to 3.
Pressing inc again starts from 4 and steps to 5.
Definitely on the right track though .
Cheers weepop
-
Then its a problem with the lua implementation. rotary in that script should be a global variable, and it should remember its value because of the line, rotary = rotary or 1.
That line basically says
if not rotary then rotary = 1 end
That expression should only evaluate as true when rotary hasnt been set. If it thinks rotary hasnt been set when it changes scripts, then the variables are not truly global. For it to be a valid implementation of lua, there should be some way of making such a variable global. I dont know enough about Helios to say if there is such a way, though. I really hoped that would work. It seems like there needs to be some variable store that can be accessed by all scripts for this method to work.
Does the encoder TriggerValue have any detail other than inc/dec? If you run the script,
return TriggerValue
what action value do you get?
The only other idea I have at the moment, is if some variable can be passed to the increment/decrement function to start with - like if the TriggerValue could contain the current rotary position, for instance. But Im not sure that will be possible.
-
Sorry, not sure if I follow 100% but are you making allowances for this situation:
Rotary is at start position, say 1
User inadvertently clicks counter-clockwise a few times
Make sure Rotarty stays at 1 and does not end up at 0 or negative number… -
Sorry, not sure if I follow 100% but are you making allowances for this situation:
Rotary is at start position, say 1
User inadvertently clicks counter-clockwise a few times
Make sure Rotarty stays at 1 and does not end up at 0 or negative number…With the script above I posted, the rotary wraps around, so it will first go to 19, then 18, 17, etc. It never gets to zero, but wraps from 19 to 1 and vice versa.
The issue above is that the rotary value is not synced up between the two scripts. Im not sure of there is a way to do that. Perhaps storing the variable in a text file that is written to and read by each script? Really need documentation for or experimentation on, helios and its lua implementation, to try to get any further.
-
Blu3wolf
Because the “in game” appearance of the channel change switch also passes from 19 to 1 I think I can make this work by only having either the inc or the dec
scripted and not both of them. This will only mean pilot can go one way with the switch. Not really a problem so I am going to attempt to implement this.I will post result.
Thanks for your input
weepop
-
Okay, the repo wouldn’t build and the last commit was 7 months ago, so if you get that^ to work that is probably best.