diff --git a/SCRIPTING.md b/SCRIPTING.md index fd8285d..7ae0986 100644 --- a/SCRIPTING.md +++ b/SCRIPTING.md @@ -52,6 +52,7 @@ In general, scripts conform to the following BNF: gpio_pwm | serial_out | if then [else ] endif | + while do done | print | println | system | @@ -208,6 +209,11 @@ if then [else ] endif ``` Classic "if then else" expression. Sequences of actions must be terminated with the (optional) "else" and the "endif". Can be nested. +``` +while do done +``` +Classic "while" loop. Can be nested. Make sure that loops terminate quickly (about a second) to avoid a watchdog timeout reset. + ## Expressions Expressions evaluate to a (string) value. A single constant, a string, or a variable are the basic expressions. Expressions can be combined by operators. If more than one operator is used in an expression, all expressions are stricly evaluated from left to right. CAUTION: arithmetical preceedence does not (yet) apply automatically like in other programming languages. However, the preceedence can be fully controlled by brackets. diff --git a/firmware/0x00000.bin b/firmware/0x00000.bin index 18cba3c..84b0f95 100644 Binary files a/firmware/0x00000.bin and b/firmware/0x00000.bin differ diff --git a/firmware/0x10000.bin b/firmware/0x10000.bin index e4a34fc..2664d01 100644 Binary files a/firmware/0x10000.bin and b/firmware/0x10000.bin differ diff --git a/firmware/sha1sums b/firmware/sha1sums index 2698582..d1f0106 100644 --- a/firmware/sha1sums +++ b/firmware/sha1sums @@ -1,2 +1,2 @@ -10e10e08f05ad126cf205ec87f50412f8642841f 0x00000.bin -4831e82954d459e4efc2fd470c8e7cb4d28e528a 0x10000.bin +fc934837e57507b0e318ae84738b9838584efbab 0x00000.bin +e35e62cba7daba715dc97b08c77ea93bee07c966 0x10000.bin diff --git a/user/lang.c b/user/lang.c index 8a5182c..d1ff3f0 100644 --- a/user/lang.c +++ b/user/lang.c @@ -663,7 +663,7 @@ int ICACHE_FLASH_ATTR parse_action(int next_token, bool doit) { while (next_token < max_token && !is_token(next_token, "on") && !is_token(next_token, "config") && !is_token(next_token, "else") - && !is_token(next_token, "endif")) { + && !is_token(next_token, "endif") && !is_token(next_token, "done")) { bool is_nl = false; if (doit) { @@ -854,6 +854,38 @@ int ICACHE_FLASH_ATTR parse_action(int next_token, bool doit) { } } + + else if (is_token(next_token, "while")) { + uint32_t if_val = 0; + char *if_char; + int if_len; + Value_Type if_type; + int exp_token; + int repeat_token = next_token; + + len_check(3); + exp_token = next_token + 1; + if ((next_token = parse_expression(next_token + 1, &if_char, &if_len, &if_type, doit)) == -1) + return -1; + if (syn_chk && !is_token(next_token, "do")) + return syntax_error(next_token, "'do' expected"); + + if (doit) { + if_val = atoi(if_char); + if (if_val != 0) + lang_log("while %s %s... (done) \r\n", my_token[exp_token++], my_token[exp_token]); + } + if ((next_token = parse_action(next_token + 1, doit && if_val != 0)) == -1) + return -1; + if (syn_chk && !is_token(next_token - 1, "done")) { + return syntax_error(next_token - 1, "'done' expected"); + } + if (!syn_chk && doit && if_val != 0) { + next_token = repeat_token; + } + } + + else if (is_token(next_token, "settimer")) { len_check(2); uint32_t timer_no = atoi(my_token[next_token + 1]); @@ -1108,7 +1140,7 @@ int ICACHE_FLASH_ATTR parse_action(int next_token, bool doit) { } - if (is_token(next_token, "endif")) + if (is_token(next_token, "endif") || is_token(next_token, "done")) next_token++; return next_token; diff --git a/user/user_config.h b/user/user_config.h index 08b7f67..49a4528 100644 --- a/user/user_config.h +++ b/user/user_config.h @@ -1,7 +1,7 @@ #ifndef _USER_CONFIG_ #define _USER_CONFIG_ -#define ESP_UBROKER_VERSION "V2.0.4" +#define ESP_UBROKER_VERSION "V2.0.5" #define WIFI_SSID "ssid" #define WIFI_PASSWORD "password"