Merge pull request #9608 from gemu2015/scripter-update

scripter update
This commit is contained in:
Theo Arends 2020-10-23 09:16:05 +02:00 committed by GitHub
commit 2ea0594f8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 25 deletions

View File

@ -420,8 +420,11 @@ struct SCRIPT_MEM {
#ifdef USE_SCRIPT_GLOBVARS
UDP_FLAGS udp_flags;
#endif
char web_mode;
} glob_script_mem;
bool event_handeled = false;
@ -768,8 +771,14 @@ char *script;
script_mem += size;
#ifdef SCRIPT_LARGE_VNBUFF
glob_script_mem.vnp_offset = (uint16_t*)script_mem;
size = vars*sizeof(uint16_t);
uint32_t alignedmem = (uint32_t)script_mem;
if (alignedmem&1) {
alignedmem++;
size = vars*sizeof(uint16_t)+1;
} else {
size = vars*sizeof(uint16_t);
}
glob_script_mem.vnp_offset = (uint16_t*)alignedmem;
#else
glob_script_mem.vnp_offset = (uint8_t*)script_mem;
size = vars*sizeof(uint8_t);
@ -3107,7 +3116,10 @@ chknext:
goto exit;
}
#endif // USE_FT5206
if (!strncmp(vname, "wm", 2)) {
fvar = glob_script_mem.web_mode;
goto exit;
}
if (!strncmp(vname, "wday", 4)) {
fvar = RtcTime.day_of_week;
goto exit;
@ -3718,6 +3730,29 @@ void esp32_beep(int32_t freq ,uint32_t len) {
//#define IFTHEN_DEBUG
char *scripter_sub(char *lp, uint8_t fromscriptcmd) {
lp += 1;
char *slp = lp;
uint8_t plen = 0;
while (*lp) {
if (*lp=='\n'|| *lp=='\r'|| *lp=='(') {
break;
}
lp++;
plen++;
}
if (fromscriptcmd) {
char *sp = glob_script_mem.scriptptr;
glob_script_mem.scriptptr = glob_script_mem.scriptptr_bu;
Run_Scripter(slp, plen, 0);
glob_script_mem.scriptptr = sp;
} else {
Run_Scripter(slp, plen, 0);
}
lp = slp;
return lp;
}
#define IF_NEST 8
// execute section of scripter
int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
@ -4107,7 +4142,16 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonParserObject *jo) {
goto next_line;
}
#endif //ESP32
else if (!strncmp(lp, "wcs", 3)) {
lp+=4;
// skip one space after cmd
char tmp[256];
Replace_Cmd_Vars(lp ,1 , tmp, sizeof(tmp));
WSContentFlush();
WSContentSend_P(PSTR("%s"),tmp);
WSContentFlush();
goto next_line;
}
else if (!strncmp(lp,"=>",2) || !strncmp(lp,"->",2) || !strncmp(lp,"+>",2) || !strncmp(lp,"print",5)) {
// execute cmd
uint8_t sflag = 0,pflg = 0,svmqtt,swll;
@ -4170,25 +4214,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonParserObject *jo) {
goto next_line;
} else if (!strncmp(lp, "=#", 2)) {
// subroutine
lp += 1;
char *slp = lp;
uint8_t plen = 0;
while (*lp) {
if (*lp=='\n'|| *lp=='\r'|| *lp=='(') {
break;
}
lp++;
plen++;
}
if (fromscriptcmd) {
char *sp = glob_script_mem.scriptptr;
glob_script_mem.scriptptr = glob_script_mem.scriptptr_bu;
Run_Scripter(slp, plen, 0);
glob_script_mem.scriptptr = sp;
} else {
Run_Scripter(slp, plen, 0);
}
lp = slp;
lp = scripter_sub(lp, fromscriptcmd);
goto next_line;
} else if (!strncmp(lp, "=(", 2)) {
lp += 2;
@ -6474,10 +6500,10 @@ uint32_t cnt;
}
void ScriptWebShow(char mc) {
uint8_t web_script,xflg = 0;
uint8_t web_script;
glob_script_mem.web_mode = mc;
if (mc=='w' || mc=='x') {
if (mc=='x') {
xflg = 1;
mc='$';
}
web_script = Run_Scripter(">w", -2, 0);
@ -6543,11 +6569,22 @@ void ScriptWebShow(char mc) {
} else {
goto nextwebline;
}
} else if (!strncmp(lp, "%=#", 3)) {
// subroutine
lp = scripter_sub(lp + 1, 0);
goto nextwebline;
}
Replace_Cmd_Vars(lp, 1, tmp, sizeof(tmp));
char *lin = tmp;
if ((!mc && (*lin!='$')) || (mc=='w' && (*lin!='$'))) {
/*if (!mc || mc=='w') {
if (*lin=='$') {
lin++;
if (!strncmp(lin,"gc(", 3)) {
goto exgc;
}
}*/
// normal web section
if (*lin=='@') {
lin++;