Sml update (#17541)

* fix sysvarsbug, update sml

* major rewrite
This commit is contained in:
gemu 2022-12-30 08:41:54 +01:00 committed by GitHub
parent 99d33e3023
commit 22803e3e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1321 additions and 1599 deletions

View File

@ -52,6 +52,14 @@ keywords if then else endif, or, and are better readable for beginners (others m
#endif #endif
#define MAXNVARS MAXVARS-MAXSVARS #define MAXNVARS MAXVARS-MAXSVARS
#ifdef USE_SML_M
#ifndef NO_USE_SML_SCRIPT_CMD
// allows several sml cmds from scripts, as well as access to sml registers
#undef USE_SML_SCRIPT_CMD
#define USE_SML_SCRIPT_CMD
#endif
#endif // USE_SML_M
#ifndef MAXFILT #ifndef MAXFILT
#define MAXFILT 5 #define MAXFILT 5
#endif #endif
@ -2645,6 +2653,7 @@ chknext:
} }
#endif //USE_SCRIPT_TASK #endif //USE_SCRIPT_TASK
#endif //ESP32 #endif //ESP32
#ifdef USE_ANGLE_FUNC #ifdef USE_ANGLE_FUNC
if (!strncmp(lp, "cos(", 4)) { if (!strncmp(lp, "cos(", 4)) {
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv); lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
@ -4309,8 +4318,18 @@ extern char *SML_GetSVal(uint32_t index);
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
lp++; lp++;
len = 0; len = 0;
if (sp) strlcpy(sp, SML_GetSVal(fvar), glob_script_mem.max_ssize); if (fvar > 0) {
goto strexit;; if (sp) strlcpy(sp, SML_GetSVal(fvar), glob_script_mem.max_ssize);
} else {
char sbuff[SCRIPT_MAXSSIZE];
fvar = fabs(fvar);
if (fvar < 1) {
fvar = 1;
}
dtostrfd(SML_GetVal(fvar), glob_script_mem.script_dprec, sbuff);
if (sp) strlcpy(sp, sbuff, glob_script_mem.max_ssize);
}
goto strexit;
} }
if (!strncmp(lp, "sml(", 4)) { if (!strncmp(lp, "sml(", 4)) {
float fvar1; float fvar1;
@ -6064,7 +6083,8 @@ int16_t retval;
#define SCRIPT_LOOP_NEST 3 #define SCRIPT_LOOP_NEST 3
int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) { int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
uint8_t vtype = 0, sindex, xflg, globvindex, fromscriptcmd = 0; uint8_t vtype = 0, sindex, xflg, fromscriptcmd = 0;
int16_t globvindex;
// 22 bytes per nested loop // 22 bytes per nested loop
uint8_t floop[SCRIPT_LOOP_NEST] = {0, 0, 0}; uint8_t floop[SCRIPT_LOOP_NEST] = {0, 0, 0};
int8_t loopdepth = -1; int8_t loopdepth = -1;
@ -6682,6 +6702,7 @@ getnext:
dfvar = &sysvar; dfvar = &sysvar;
if (ind.bits.settable) { if (ind.bits.settable) {
sysv_type = ind.index; sysv_type = ind.index;
globvindex = -1;
} else { } else {
sysv_type = 0; sysv_type = 0;
} }
@ -6759,33 +6780,36 @@ getnext:
break; break;
} }
// var was changed // var was changed
SetChanged(globvindex); if (globvindex >= 0) SetChanged(globvindex);
#ifdef USE_SCRIPT_GLOBVARS #ifdef USE_SCRIPT_GLOBVARS
if (glob_script_mem.type[globvindex].bits.global) { if (globvindex >= 0 ) {
script_udp_sendvar(varname, dfvar, 0); if (glob_script_mem.type[globvindex].bits.global) {
script_udp_sendvar(varname, dfvar, 0);
}
} }
#endif //USE_SCRIPT_GLOBVARS #endif //USE_SCRIPT_GLOBVARS
if (glob_script_mem.type[globvindex].bits.is_filter) { if (globvindex >= 0) {
if (globaindex >= 0) { if (glob_script_mem.type[globvindex].bits.is_filter) {
Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar); if (globaindex >= 0) {
} else { Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar);
if (glob_script_mem.arres == 2) { } else {
// fetch var preset if (glob_script_mem.arres == 2) {
lp++; // fetch var preset
while (*lp && *lp != SCRIPT_EOL) { lp++;
if (*lp == '}') { while (*lp && *lp != SCRIPT_EOL) {
lp++; if (*lp == '}') {
break; lp++;
break;
}
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
Set_MFilter(glob_script_mem.type[globvindex].index, fvar);
} }
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); } else {
Set_MFilter(glob_script_mem.type[globvindex].index, fvar);
}
} else {
Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar); Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar);
}
} }
} }
} }
if (sysv_type) { if (sysv_type) {
switch (sysv_type) { switch (sysv_type) {
case SCRIPT_LOGLEVEL: case SCRIPT_LOGLEVEL:
@ -6845,10 +6869,12 @@ getnext:
#endif #endif
if (!glob_script_mem.var_not_found) { if (!glob_script_mem.var_not_found) {
// var was changed // var was changed
SetChanged(globvindex); if (globvindex >= 0) SetChanged(globvindex);
#ifdef USE_SCRIPT_GLOBVARS #ifdef USE_SCRIPT_GLOBVARS
if (glob_script_mem.type[globvindex].bits.global) { if (globvindex >= 0) {
script_udp_sendvar(varname, 0, str); if (glob_script_mem.type[globvindex].bits.global) {
script_udp_sendvar(varname, 0, str);
}
} }
#endif //USE_SCRIPT_GLOBVARS #endif //USE_SCRIPT_GLOBVARS
if (saindex >= 0) { if (saindex >= 0) {

2844
tasmota/tasmota_xsns_sensor/xsns_53_sml.ino Normal file → Executable file

File diff suppressed because it is too large Load Diff