Formula
A formula is an expression made of:
- Operators: can be the basic mathematics operations, logic operators, compare operators or basic string operators.
- Operands: can be literals (numbers and strings used as constants) and references to tags.
Round brackets are supported as priority operators. The operator $ will be used to call functions and, in particular, to referring to a tag (see below for examples).
The attach to dialog allow to use a formula to calculate the value to return.
Commands
Enter edit mode | |
Save the entered formula inside the formulas' library to have the possibility to reuse the same formula inside other places of the project. | |
Open the formulas' library to select an already defined formula. | |
Removing the entered formula | |
Confirming the entered formula |
When you are in edit mode you can simple edit the formula and double click tags or functions from the library to add them inside the formula.
Example of formulas are:
- $('Tag1')+$('Tag2')
- $('Tag1')&$('Tag2')
- $('Tag1')>$('Tag2')?$('Tag1'):$('Tag2')
- $Pow(2,$('Tag2'))
- $Contains($('Tag1'),$('Tag2'))
Syntax for formula
Basic Operations | |
---|---|
'Text' |
String literal |
NUMBER | Number literal, e.g. 169857 or 13.547 |
String( … ) | Cast to string (note there is not $) |
Number( … ) | Cast to number (note there is not $) |
$FuncName( param1, param2, … ) | General function call. (Both default and user ones) |
$(‘TagName’) |
Tag, or widget property, or recipe, etc. Note that tag name must be string literal |
$(‘TagName’)[index] |
Element of a array tag. Note that tag name must be string literal |
exp1 ? exp2 : exp3 |
Ternary expression. If exp1 is true, then is taken exp2, otherwise is taken exp3. This is like using if/then/else statement |
Math Operators | |
---|---|
+ |
Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Module |
Bitwise Operators | |
---|---|
& | Sets each bit to 1 if both bits are 1 |
| | Sets each bit to 1 if one of two bits is 1 |
~ | Inverts all the bits |
^ | Sets each bit to 1 if only one of two bits is 1 |
<< | Shifts left by pushing zeros in from the right and let the leftmost bits fall off |
>> | Shifts right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |
>>> | Shifts right by pushing zeros in from the left, and let the rightmost bits fall off |
Logical Operators | |
---|---|
&& | AND |
|| | OR |
! | NOT |
Compare Operators | |
---|---|
< | Less than |
<= | Less than or equal to |
> | Greater than |
>= | Greater than or equal to |
== | Equal to |
!= | Not equal to |
Use predefined formula from the library
To insert a project or a predefined formula:
- Open the formulas' library
- Select the formula to use
- Confirm the selected formula
- Enter the arguments required from the selected formula
Add user formulas into the library
After entering a new formula, using SAVE button is possible to store the new formula inside the project folder to make it available from the formulas’ library.
A user formula could be retrieved from the formulas’ library as for the other predefined formulas.