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
PaulH
Posts: 15
Can I use any operators from NCalc in the transform formula?

As an example:
instead of if(1,0,1) I would like to use not $.

Paul
2021-04-18 14:04
Avatar
StephanHo
Moderator
From: EDDG, Germany
Posts: 1705
Supporter
Hi Paul,

what is the sense of your formula?
If 1 set 0 else set 1
What works ist: if (true,0,1) but the result is always 0 also if(true,1,0) where the result is always 1. Same with false. Then you can also insert a 0 or a 1 into this transform field.
The sense of transform is to manipulate either the present value of an offset or a config reference.

You are right, you can use all operators from NCalc, like they are published.
Grüße,
Stephan
2021-04-18 14:27
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4647
Supporter
Hi

I think that Paul´s request is related to a INPUT !

Basicly the quoted Formula will not work.... Cause it miss the realtion ta a Value.
iconPaulH:

if(1,0,1)


The IF part need to be adressed to a value..... in our Case "$" so correctly it´s if($=1,0,1) OR if($=0,1,0)

BUT thats not the fact.

Paul is basicly right. The NOT Command is a part of NCalc. In theroy this should work..... But i think the result is finaly a TRUE or FALSE.
In a Bitwise System True and False can work..... But in a Integer 1 Byte Decimal Offset ???? Can a UINT8 have the status True/False ?

I will check this out...... Please also make testings and report when you find the correct Syntax !
Good Luck !
2021-04-18 15:21
Avatar
PaulH
Posts: 15
Well I did a short example:

- Input Button to Offset 0x66C5 (Int 1 Byte) set value on Press with if($,0,1)
- Output from same Offset 0x66C5 to Pin (LED) as $

This toogles the value with every press of the button between values 0 and 1 (LED off and on).

But using not $ does nothing at all. The value stays the same.

I would have expected that any non-zero int ($>0) would be interpreted as TRUE (as all non typed programming languages would do) and the operator NOT would produce a result of FALSE which is a zero int. And vice versa.

Paul
2021-04-18 20:23
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4647
Supporter
I check your idea and i see a interesting logic.

Normaly we not say "if($,0,1) " as i explane above we define a situation for $ ..... like if($=1,0,1)
With this way we are flexible and can manage all Situations.... Also "Non-Bool" Inputs.

It looks like your syntax is related to TRUE and FALSE.
if($,0,1) is working! ..... It took me some minutes to understand that behavour !

Without a definition $ here is checked for TRUE or FALSE .....
With "if($,0,1) " we say.... IF ..TRUE (So Value is >0 means "1" in our case )... THEN Set "0" ... ELSE if FALSE (Value =0 ) then Set "1"

***************
About NOT..... Here i find no way. Looks like "not" is only a indicator to define, but not a executing command.
You should request for informations on GitHub Page of the Creators of NCalc for more information or for the correct syntax! MF just use it.... We not build it !

***************

Last Note:
Let me ask.... Why do you need it ? We work for years with the old IF Statement without trouble..... Advanced Users work with a Modulo like ($+1)%2 and it work too.
I not see the problem at the moment.
We work today with Computers in the Ghz Speed and Multicore. The time is gone we need to short down a code or avoid a IF condition to increase speed of code.
Whatever you create 5000 If Conditions in a loop..... You will not feel a huge difference to 5000 "not" commands.
And please NOT tell me your intention is to save 1,5 seconds of lifetime in case you need to type less keys while input the formula in your way :P
Good Luck !
2021-04-19 13:33
icon