MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

icon
Avatar
fushia_l@yahoo.it
Posts: 5
Hello I have an encoder knob that I would like to use for different functions. I have followed the advised given on this video
https://www.youtube.com/watch?v=nxnD6pBI-J8&list=PLyC6aoYnRBZYsC3b92-dXXPuegigJHVpj&index=41

to create mode selction switch and it works fine. It's 4 modes.

Now I would like to have 4 LEDs lighting up depending of which mode is currenlty active.

I can create an LED output easily triggered by ID events using the preconditions, but I cannot figure out how to trigger the LEDs depending on the modes.

Help please
2021-01-14 00:11
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4169
Supporter
Hi

You explane one fact with wrong words....
iconfushia_l@yahoo.it:


I can create an LED output easily triggered by ID events using the preconditions, but I cannot figure out how to trigger the LEDs depending on the modes.



Thats wrong ( whatever you mean it correct) ..... A Output is never realted to a Event.... It is always related to a OFFSET.
And the same is correct for a Precondition. As Idication fro a Precondition you can NOT use a EventID .... It must be always a Output Config that read a OFFSET !

In the Video it is perectly explaned.
The guy use the Encoder Button to Toggle a Offset ( 66C0) from 0 -1- 2-3- 0 - 1 -2 -3 -0 and so on.
Then he build a OUTPUT Config that simply read this Offset and use it as Precondtion.

For Your LED´s you will use the same Offset.... But here precondition is not needed .... You direclty work with it.

Solution:
For each LED you create a single Config ( Output).
Each Config use the needed LED . ( 4 Led´s 4 Configs)
ALL Configs use the same Offset.... In the Example 66C0 1 Byte INT
And now you need a formula in Transform field OR a setting in the Compare Tab.

For example the first LED should light if Mode selector is "0" .
Here you say....
Transform: if($=0,1,0) ...... Means if Value of Offset is currently "0" then show "1" (LED on) .... ELSE ( so if Mode Offset is not 0 and show 1, 2 or 3) then show "0" ( LED off)
OR you use Compare
There you enable the Compare and say IF Value is operator "=" and Value "0" in THEN field you say "1" and in ELSE field you say "0"
Both will do the same.... So choose what you like more.

The other 3 Configs work same.... Just with a different Formula.
E.g. the second LED must light if Offset show "1" but must be OFF if Offset is 0 , 2 or 3..... So here we would say if($=1,1,0)
Good Luck !
2021-01-14 10:54
Avatar
fushia_l@yahoo.it
Posts: 5
Many thanks for the detailed explanation. Yes I have managed to make it work and it works perfectly.
However I have noticed a few things that may be worth clarifying:
1- In order to toggle from value 0,1 and 2 I had to use the following formula if($=2,0,$+1). If I use this formula if($=3,0,$+1) it will output values from 0 to 3 (including 3). That's a bit odd as if the value is 3 than it should reverse back to 0 (and not outputting 3!).
EDIT: forget this question...:) I figured it out. The addition is done after the comparison, so obviously if $=2 it will add 1 and reset to 0 at the next iteration.

2- I have noticed that unticking the output lines does not always affect the behaviour (at times it does, at time it doesn't)

I have done some programming in C for arduino before (basic stuff) and I am trying to understand how mobiflight works.
What I understand so far is that an OFFSET is basically a way to refer to a memory address. when we create an output, we are reading the value stored at that address.
So if we look at the parking brake example, I assume that FS2020, depending whether the brake is engaged or not, will output a value 1 or 0 to the address 0BC8, which we can read if we want to light up an LED.
[Last edited by fushia_l@yahoo.it, 2021-01-15 08:59]
2021-01-14 23:01
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4169
Supporter
Nice you not simply copy it... Its cool if a user also think about it.

1. Here you must think in correct way.... "$" in a Input Config Formula is related to the "current" Value of the Offset.... So the value BEFORE the input happen.
Technical if you press a Input Button then Mobiflight make a single READ at first and request in FSUIPC the current Value of the Offset we like to write.
Then it set this readed value as a temporary Variable "$" .
As a guy with some programming skills you know.... There exist not only one correct formula..... There exist thousend. And all will work. Question is only what formula is more profitable and efficient.
For example:
Lets say a toggle 0,1,2,3 like you explane with a backstep from 3 to 0.
We can say.... if($=3,0,$+1) ..... We can also say .... if($>2,0,$+1) .... Or.... if($+1=4,0,$+1) .....

And finaly the most smart solution is ($+1)%4 Here we save the If condition and multiple internal steps.... This is just poor math.
If Value is currently "1" we say 1+1=2 And then 2 %MODULO 4 and that result in "2" . The swap Point.... If Value is currently "3" ... 3+1=4 4%4=0

****
2. Unticking Output Lines is not a "normal" procedure. Specialy if MF is still running this is not working correct.... Means a LED e.g. still light whatever Line is unticked. Simply cause it is no longer controlled but still on. Same if you activate a Config while MF is running. Then the Device get not "updated" until you send a new value or open the Config by hand ( what also internal execute a short Rfresh to it) .
So.... Please see the Option " Enable/Disable" Config by checkmark as a tool that should be used only in STOP mode and also only in special situations. I will say a "normal" user will never need to use those checkmarks.... Only advanced Users in special projects.

3. Mobiflight itself have no "memory" and technical also no global Variables.....
The "Offset" are a Part of FSUIPC.
So FSUIPC read a verry large raw Datastring from the Sim ( by simconnect) and order it to the "Offsets" . Mobiflight itself talk to FSUIPC. If you create e.g. a Output Config then Mobiflight simply read multiple times per second the specific Area of the FSUIPC data ( adressed via the Offset Number) .

If you like to know more.... You can download the full Mobiflight Code on Bitbucket. https://bitbucket.org/mobiflight/mobiflightfc/src/master/
Good Luck !
2021-01-15 13:15
Avatar
fushia_l@yahoo.it
Posts: 5
that's brilliant: :) "
iconQuote:

And finally the most smart solution is ($+1)%4 "


and thanks again for your time and for the detailed explanation!!! very helpful!
I believe I have sufficient understanding of this to start my project, so I have just ordered the parts I need to build my controller...:)
I will post pictures when it's done
cheers
Yesterday 12:49
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4169
Supporter
In case i not like to earn hornor for a thing i also just "copy" .....
The Modulo Formula is based on a other users idea ( i forgot the name) . I still use the "IF Function" for many years until this guy show me this better way.
Good Luck !
Today 01:57
icon