The major features of IF statement are:
- Support IF, ELSEIF, ELSE
- Support not only comparison but also using logical expression as condition
- Support run multiple commands
- Support nested IF statement
- All the commands run by IF statement will go to the BACKLOG!
- No limit for logical operators, parenthesis and nested IF statement. Depends on your RAM!
Extended Backus-Naur Form of IF statement:
<if-statement> ::=
IF "(" <logical-expression> ")" <statement-list> {ELSEIF "(" <logical-expression> ")" <statement-list>} [ELSE <statement-list>] ENDIF
<logical-expression> :=
<comparison-expression> |
(<comparison-expression> | <logical-expression>) {(AND | OR) <logical-expression>} |
"(" <logical-expression ")" {(AND | OR) <logical expression>}
<comparison-expression> ::=
<math-expression> ("=" | "<" | ">" | "|" | "==" | "<=" | ">=" | "!=") <math-expression>
<statement-list> ::=
<statement> {";" <statement>}
<statement> ::=
<Sonoff-Tasmota-command> | <if-statement>
In English:
If statement support 3 format:
1. IF (<condition>) <statement-list> ENDIF
2. IF (<condition>) <statement-list> ELSE <statement-list> ENDIF
3. IF (<condition>) <statement-list> [ELSEIF (<condition>) <statement-list> ]* ELSE <statement-list> ENDIF
<condition> is a logical expression which can be:
1. A comparison expression for example:
VAR1 >= 10
2. Multiple comparison expression with logical operator "AND" or "OR" between them. "AND" has higher priority than "OR". Fox example:
UPTIME > 100 AND MEM1 == 1 OR MEM2 == 1
3. Parenthesis can be used to change the priority of logical expression. For example:
UPTIME > 100 AND (MEM1 == 1 OR MEM2 == 1)
<statement-list> can be:
1. A Sonoff-Tasmota command. For example:
ledpower on
2. A IF statement ("IF .... ENDIF")
3. Multiple Sonoff-Tasmota command or IF statement split with ";". For example:
Power1 off; Ledpower on; if (mem1 == 0) Var1 Var1+1; mem1==1 endif; Delay 10; POWER1 on
4. Do not need to lead with "BACKLOG" for multiple commands.
Add command Buzzer with optional parameters <number of beeps>,<duration of beep in 100mS steps>,<duration of silence in 100mS steps> enabled when a buzzer is configured (#5988)
* Refactor energy commands
* Add define USE_ENERGY_MARGIN_DETECTION to disable Energy Margin and Power Limit detection
* Add define USE_ENERGY_POWER_LIMIT to disable Energy Power Limit detection while Energy Margin detection is active
Working fine with MAX3165 and a PT100 probe.
Using a modified version of Adafruit MAX31865 library. Added a default
constructor in order to allow lazy initialization once GPIO definitions
were loaded.
Tested on a Sonoff TH PCB Board 2.1 2018-06-15 using the following GPIO
mapping:
GPIO Orig Func SSPI I/O HEADER HEADER2 S-JACK
15 BOOT MODE CLK O 1
14 MISO I 2 TIP
4 MOSI O 3 RING1
VCC 1 VCC 4 RING3
2 DBG BOOT ~CS O 5 EXP-LOG
GND 4 GND RING2
HEADER2 is a 4-pin .1 header glued in the middle of the PCB to connect
to several GPIO locations on the Sonoff TH PCB.
TODO: Merge with MAX31855 code.