mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
some fixes and enhancements
This commit is contained in:
parent
0bfa5af3ad
commit
a2857e1c53
@ -431,8 +431,9 @@ struct SCRIPT_MEM {
|
|||||||
IPAddress script_udp_remote_ip;
|
IPAddress script_udp_remote_ip;
|
||||||
#endif // USE_SCRIPT_GLOBVARS
|
#endif // USE_SCRIPT_GLOBVARS
|
||||||
char web_mode;
|
char web_mode;
|
||||||
uint8_t glob_script = 0;
|
char *glob_script = 0;
|
||||||
uint8_t fast_script = 0;
|
char *fast_script = 0;
|
||||||
|
char *web_pages[5];
|
||||||
uint32_t script_lastmillis;
|
uint32_t script_lastmillis;
|
||||||
bool event_handeled = false;
|
bool event_handeled = false;
|
||||||
#ifdef USE_BUTTON_EVENT
|
#ifdef USE_BUTTON_EVENT
|
||||||
@ -573,6 +574,16 @@ char *script;
|
|||||||
float fvalues[MAXVARS];
|
float fvalues[MAXVARS];
|
||||||
struct T_INDEX vtypes[MAXVARS];
|
struct T_INDEX vtypes[MAXVARS];
|
||||||
|
|
||||||
|
|
||||||
|
//char strings[MAXSVARS*SCRIPT_MAXSSIZE];
|
||||||
|
//char *strings_p = strings;
|
||||||
|
char *strings_op = (char*)calloc(MAXSVARS*SCRIPT_MAXSSIZE, 1);
|
||||||
|
char *strings_p = strings_op;
|
||||||
|
if (!strings_op) {
|
||||||
|
free(imemptr);
|
||||||
|
return -7;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
uint32_t imemp = (uint32_t)imemptr;
|
uint32_t imemp = (uint32_t)imemptr;
|
||||||
imemp += (MAXVARS*10);
|
imemp += (MAXVARS*10);
|
||||||
@ -598,13 +609,10 @@ char *script;
|
|||||||
char *vnames_p = vnames;
|
char *vnames_p = vnames;
|
||||||
char **vnp_p = vnp;
|
char **vnp_p = vnp;
|
||||||
|
|
||||||
char strings[MAXSVARS*SCRIPT_MAXSSIZE];
|
|
||||||
char *snp[MAXSVARS];
|
char *snp[MAXSVARS];
|
||||||
|
|
||||||
struct M_FILT mfilt[MAXFILT];
|
struct M_FILT mfilt[MAXFILT];
|
||||||
|
|
||||||
char *strings_p = strings;
|
|
||||||
|
|
||||||
char **snp_p = snp;
|
char **snp_p = snp;
|
||||||
uint8_t numperm = 0;
|
uint8_t numperm = 0;
|
||||||
uint8_t numflt = 0;
|
uint8_t numflt = 0;
|
||||||
@ -681,6 +689,7 @@ char *script;
|
|||||||
numflt++;
|
numflt++;
|
||||||
if (numflt>MAXFILT) {
|
if (numflt>MAXFILT) {
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -6;
|
return -6;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -707,6 +716,7 @@ char *script;
|
|||||||
nvars++;
|
nvars++;
|
||||||
if (nvars>MAXNVARS) {
|
if (nvars>MAXNVARS) {
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vtypes[vars].bits.is_filter) {
|
if (vtypes[vars].bits.is_filter) {
|
||||||
@ -717,7 +727,7 @@ char *script;
|
|||||||
if (isdigit(*op)) {
|
if (isdigit(*op)) {
|
||||||
// lenght define follows
|
// lenght define follows
|
||||||
uint16_t flen = atoi(op);
|
uint16_t flen = atoi(op);
|
||||||
if (flen>MAX_ARRAY_SIZE) {
|
if (flen > MAX_ARRAY_SIZE) {
|
||||||
// limit array size
|
// limit array size
|
||||||
flen = MAX_ARRAY_SIZE;
|
flen = MAX_ARRAY_SIZE;
|
||||||
}
|
}
|
||||||
@ -740,12 +750,14 @@ char *script;
|
|||||||
svars++;
|
svars++;
|
||||||
if (svars>MAXSVARS) {
|
if (svars>MAXSVARS) {
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vars++;
|
vars++;
|
||||||
if (vars>MAXVARS) {
|
if (vars>MAXVARS) {
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -797,6 +809,7 @@ char *script;
|
|||||||
script_mem = (uint8_t*)special_malloc(script_mem_size);
|
script_mem = (uint8_t*)special_malloc(script_mem_size);
|
||||||
if (!script_mem) {
|
if (!script_mem) {
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,6 +891,7 @@ char *script;
|
|||||||
if (index > MAXVNSIZ) {
|
if (index > MAXVNSIZ) {
|
||||||
free(glob_script_mem.script_mem);
|
free(glob_script_mem.script_mem);
|
||||||
if (imemptr) free(imemptr);
|
if (imemptr) free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -887,7 +901,9 @@ char *script;
|
|||||||
|
|
||||||
// copy string variables
|
// copy string variables
|
||||||
char *cp1 = glob_script_mem.glob_snp;
|
char *cp1 = glob_script_mem.glob_snp;
|
||||||
char *sp = strings;
|
//char *sp = strings;
|
||||||
|
char *sp = strings_op;
|
||||||
|
|
||||||
for (count = 0; count<svars; count++) {
|
for (count = 0; count<svars; count++) {
|
||||||
strcpy(cp1,sp);
|
strcpy(cp1,sp);
|
||||||
sp += strlen(sp) + 1;
|
sp += strlen(sp) + 1;
|
||||||
@ -967,12 +983,13 @@ char *script;
|
|||||||
#ifdef USE_SCRIPT_GLOBVARS
|
#ifdef USE_SCRIPT_GLOBVARS
|
||||||
if (glob_script_mem.udp_flags.udp_used) {
|
if (glob_script_mem.udp_flags.udp_used) {
|
||||||
Script_Init_UDP();
|
Script_Init_UDP();
|
||||||
glob_script_mem.glob_script = Run_Scripter(">G", -2, 0);
|
if (Run_Scripter(">G", -2, 0) == 99) {glob_script_mem.glob_script = glob_script_mem.section_ptr + 2;} else {glob_script_mem.glob_script = 0;}
|
||||||
}
|
}
|
||||||
#endif //USE_SCRIPT_GLOBVARS
|
#endif //USE_SCRIPT_GLOBVARS
|
||||||
|
|
||||||
if (imemptr) {
|
if (imemptr) {
|
||||||
free(imemptr);
|
free(imemptr);
|
||||||
|
if (strings_p) free(strings_p);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -982,6 +999,8 @@ char *script;
|
|||||||
#define SCRIPT_UDP_BUFFER_SIZE 128
|
#define SCRIPT_UDP_BUFFER_SIZE 128
|
||||||
#define SCRIPT_UDP_PORT 1999
|
#define SCRIPT_UDP_PORT 1999
|
||||||
|
|
||||||
|
//#define SCRIPT_DEBUG_UDP
|
||||||
|
|
||||||
void Restart_globvars(void) {
|
void Restart_globvars(void) {
|
||||||
Script_Stop_UDP();
|
Script_Stop_UDP();
|
||||||
Script_Init_UDP();
|
Script_Init_UDP();
|
||||||
@ -1002,25 +1021,36 @@ void Script_Init_UDP() {
|
|||||||
if (glob_script_mem.udp_flags.udp_connected) return;
|
if (glob_script_mem.udp_flags.udp_connected) return;
|
||||||
|
|
||||||
if (glob_script_mem.Script_PortUdp.beginMulticast(WiFi.localIP(), IPAddress(239,255,255,250), SCRIPT_UDP_PORT)) {
|
if (glob_script_mem.Script_PortUdp.beginMulticast(WiFi.localIP(), IPAddress(239,255,255,250), SCRIPT_UDP_PORT)) {
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP "SCRIPT UDP started"));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP "SCRIPT UDP started"));
|
||||||
|
#endif
|
||||||
glob_script_mem.udp_flags.udp_connected = 1;
|
glob_script_mem.udp_flags.udp_connected = 1;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP "SCRIPT UDP failed"));
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP "SCRIPT UDP failed"));
|
||||||
|
#endif
|
||||||
glob_script_mem.udp_flags.udp_connected = 0;
|
glob_script_mem.udp_flags.udp_connected = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Script_PollUdp(void) {
|
void Script_PollUdp(void) {
|
||||||
if (TasmotaGlobal.global_state.network_down) return;
|
if (TasmotaGlobal.global_state.network_down) return;
|
||||||
if (!glob_script_mem.udp_flags.udp_used) return;
|
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||||
if (glob_script_mem.udp_flags.udp_connected ) {
|
if (glob_script_mem.udp_flags.udp_connected ) {
|
||||||
|
uint32_t timeout = millis();
|
||||||
while (glob_script_mem.Script_PortUdp.parsePacket()) {
|
while (glob_script_mem.Script_PortUdp.parsePacket()) {
|
||||||
|
// not more then 500 ms
|
||||||
|
if (millis() - timeout > 500) { break;}
|
||||||
char packet_buffer[SCRIPT_UDP_BUFFER_SIZE];
|
char packet_buffer[SCRIPT_UDP_BUFFER_SIZE];
|
||||||
int32_t len = glob_script_mem.Script_PortUdp.read(packet_buffer, SCRIPT_UDP_BUFFER_SIZE - 1);
|
int32_t len = glob_script_mem.Script_PortUdp.read(packet_buffer, SCRIPT_UDP_BUFFER_SIZE - 1);
|
||||||
packet_buffer[len] = 0;
|
packet_buffer[len] = 0;
|
||||||
glob_script_mem.script_udp_remote_ip = glob_script_mem.Script_PortUdp.remoteIP();
|
glob_script_mem.script_udp_remote_ip = glob_script_mem.Script_PortUdp.remoteIP();
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
//AddLog(LOG_LEVEL_DEBUG, PSTR("UDP: Packet %s - %d - %s"), packet_buffer, len, script_udp_remote_ip.toString().c_str());
|
//AddLog(LOG_LEVEL_DEBUG, PSTR("UDP: Packet %s - %d - %s"), packet_buffer, len, script_udp_remote_ip.toString().c_str());
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("UDP: Packet %s - %d - %_I"), packet_buffer, len, (uint32_t)glob_script_mem.script_udp_remote_ip);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("UDP: Packet %s - %d - %_I"), packet_buffer, len, (uint32_t)glob_script_mem.script_udp_remote_ip);
|
||||||
|
#endif
|
||||||
char *lp=packet_buffer;
|
char *lp=packet_buffer;
|
||||||
if (!strncmp(lp,"=>", 2)) {
|
if (!strncmp(lp,"=>", 2)) {
|
||||||
lp += 2;
|
lp += 2;
|
||||||
@ -1039,10 +1069,14 @@ void Script_PollUdp(void) {
|
|||||||
uint32_t index;
|
uint32_t index;
|
||||||
uint32_t res = match_vars(vnam, &fp, &sp, &index);
|
uint32_t res = match_vars(vnam, &fp, &sp, &index);
|
||||||
if (res == NUM_RES) {
|
if (res == NUM_RES) {
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("num var found - %s - %d - %d"), vnam, res, index);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("num var found - %s - %d - %d"), vnam, res, index);
|
||||||
|
#endif
|
||||||
*fp=CharToFloat(cp + 1);
|
*fp=CharToFloat(cp + 1);
|
||||||
} else if (res == STR_RES) {
|
} else if (res == STR_RES) {
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("string var found - %s - %d - %d"), vnam, res, index);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("string var found - %s - %d - %d"), vnam, res, index);
|
||||||
|
#endif
|
||||||
strlcpy(sp, cp + 1, SCRIPT_MAXSSIZE);
|
strlcpy(sp, cp + 1, SCRIPT_MAXSSIZE);
|
||||||
} else {
|
} else {
|
||||||
// error var not found
|
// error var not found
|
||||||
@ -1051,8 +1085,8 @@ void Script_PollUdp(void) {
|
|||||||
// mark changed
|
// mark changed
|
||||||
glob_script_mem.last_udp_ip = glob_script_mem.Script_PortUdp.remoteIP();
|
glob_script_mem.last_udp_ip = glob_script_mem.Script_PortUdp.remoteIP();
|
||||||
SetChanged(index);
|
SetChanged(index);
|
||||||
if (glob_script_mem.glob_script == 99) {
|
if (glob_script_mem.glob_script) {
|
||||||
Run_Scripter(">G", 2, 0);
|
Run_Scripter(glob_script_mem.glob_script, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1076,10 +1110,14 @@ void script_udp_sendvar(char *vname,float *fp,char *sp) {
|
|||||||
char flstr[16];
|
char flstr[16];
|
||||||
dtostrfd(*fp, 8, flstr);
|
dtostrfd(*fp, 8, flstr);
|
||||||
strcat(sbuf, flstr);
|
strcat(sbuf, flstr);
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("num var updated - %s"), sbuf);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("num var updated - %s"), sbuf);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
strcat(sbuf, sp);
|
strcat(sbuf, sp);
|
||||||
|
#ifdef SCRIPT_DEBUG_UDP
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("string var updated - %s"), sbuf);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("string var updated - %s"), sbuf);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
glob_script_mem.Script_PortUdp.beginPacket(IPAddress(239, 255, 255, 250), SCRIPT_UDP_PORT);
|
glob_script_mem.Script_PortUdp.beginPacket(IPAddress(239, 255, 255, 250), SCRIPT_UDP_PORT);
|
||||||
// Udp.print(String("RET UC: ") + String(recv_Packet));
|
// Udp.print(String("RET UC: ") + String(recv_Packet));
|
||||||
@ -1225,8 +1263,14 @@ void Set_MFVal(uint8_t index, uint16_t bind, float val) {
|
|||||||
if (count==index) {
|
if (count==index) {
|
||||||
uint16_t maxind = mflp->numvals & AND_FILT_MASK;
|
uint16_t maxind = mflp->numvals & AND_FILT_MASK;
|
||||||
if (!bind) {
|
if (!bind) {
|
||||||
if (val < 0 || val >= maxind) val = 0;
|
|
||||||
mflp->index = val;
|
if (val < 0) {
|
||||||
|
// shift whole array by value
|
||||||
|
} else {
|
||||||
|
// set array index value
|
||||||
|
if (val < 0 || val >= maxind) val = 0;
|
||||||
|
mflp->index = val;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (bind >= 1 && bind <= maxind) {
|
if (bind >= 1 && bind <= maxind) {
|
||||||
mflp->rbuff[bind-1] = val;
|
mflp->rbuff[bind-1] = val;
|
||||||
@ -1448,6 +1492,8 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, int8_t coff
|
|||||||
}
|
}
|
||||||
return cpos;
|
return cpos;
|
||||||
}
|
}
|
||||||
|
uint32_t ipos = glob_script_mem.files[fref].position();
|
||||||
|
glob_script_mem.files[fref].seek(0, SeekSet);
|
||||||
uint32_t tsfrom = tstamp2l(ts_from);
|
uint32_t tsfrom = tstamp2l(ts_from);
|
||||||
uint32_t tsto = tstamp2l(ts_to);
|
uint32_t tsto = tstamp2l(ts_to);
|
||||||
uint16_t lines = 0;
|
uint16_t lines = 0;
|
||||||
@ -1514,21 +1560,36 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, int8_t coff
|
|||||||
if (colpos >= coffs && curpos < numa) {
|
if (colpos >= coffs && curpos < numa) {
|
||||||
if (a_len[curpos]) {
|
if (a_len[curpos]) {
|
||||||
float fval = CharToFloat(rstr);
|
float fval = CharToFloat(rstr);
|
||||||
if (mflg[curpos] == 3) {
|
uint8_t flg = 1;
|
||||||
|
if ((mflg[curpos] & 1) == 1) {
|
||||||
// absolute values, build diffs
|
// absolute values, build diffs
|
||||||
float tmp = fval;
|
if (!(mflg[curpos] & 0x80)) {
|
||||||
fval -= lastv[curpos];
|
lastv[curpos] = fval;
|
||||||
lastv[curpos] = tmp;
|
mflg[curpos] |= 0x80;
|
||||||
|
flg = 0;
|
||||||
|
} else {
|
||||||
|
if (!(mflg[curpos] & 2)) {
|
||||||
|
float tmp = fval;
|
||||||
|
fval -= lastv[curpos];
|
||||||
|
// must be positive value
|
||||||
|
#ifndef EXTRACT_DIFF_NOCHK
|
||||||
|
if (fval < 0) fval = 0;
|
||||||
|
#endif
|
||||||
|
lastv[curpos] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// average values
|
// average values
|
||||||
//AddLog(LOG_LEVEL_INFO, PSTR("cpos %d colp %d numa %d - %s %d"),curpos, colpos, a_len[curpos], rstr, (uint32_t)fval);
|
//AddLog(LOG_LEVEL_INFO, PSTR("cpos %d colp %d numa %d - %s %d - %d"),curpos, colpos, a_len[curpos], rstr, (uint32_t)fval, flg);
|
||||||
summs[curpos] += fval;
|
if (flg) {
|
||||||
accnt[curpos] += 1;
|
summs[curpos] += fval;
|
||||||
if (accnt[curpos] == accum) {
|
accnt[curpos] += 1;
|
||||||
*a_ptr[curpos]++ = summs[curpos] / accum;
|
if (accnt[curpos] == accum) {
|
||||||
summs[curpos] = 0;
|
*a_ptr[curpos]++ = summs[curpos] / accum;
|
||||||
accnt[curpos] = 0;
|
summs[curpos] = 0;
|
||||||
a_len[curpos]--;
|
accnt[curpos] = 0;
|
||||||
|
a_len[curpos]--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -1542,6 +1603,11 @@ int32_t extract_from_file(uint8_t fref, char *ts_from, char *ts_to, int8_t coff
|
|||||||
lastpos = glob_script_mem.files[fref].position();
|
lastpos = glob_script_mem.files[fref].position();
|
||||||
colpos = 0;
|
colpos = 0;
|
||||||
lines ++;
|
lines ++;
|
||||||
|
if (lines == 1) {
|
||||||
|
if (ipos) {
|
||||||
|
glob_script_mem.files[fref].seek(ipos, SeekSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rstr[sindex] = iob;
|
rstr[sindex] = iob;
|
||||||
@ -2050,13 +2116,13 @@ chknext:
|
|||||||
case 'a':
|
case 'a':
|
||||||
#ifdef USE_ANGLE_FUNC
|
#ifdef USE_ANGLE_FUNC
|
||||||
if (!strncmp(lp, "acos(", 5)) {
|
if (!strncmp(lp, "acos(", 5)) {
|
||||||
lp=GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
|
||||||
fvar = acosf(fvar);
|
fvar = acosf(fvar);
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!strncmp(lp, "abs(", 4)) {
|
if (!strncmp(lp, "abs(", 4)) {
|
||||||
lp=GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
||||||
fvar = fabs(fvar);
|
fvar = fabs(fvar);
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
@ -2107,12 +2173,11 @@ chknext:
|
|||||||
float *fps;
|
float *fps;
|
||||||
lp = get_array_by_name(lp, &fps, &alens);
|
lp = get_array_by_name(lp, &fps, &alens);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
if (alend != alens) {
|
if (alens < alend) {
|
||||||
fvar = -1;
|
alend = alens;
|
||||||
} else {
|
|
||||||
memcpy(fpd, fps, alend * sizeof(float));
|
|
||||||
fvar = 0;
|
|
||||||
}
|
}
|
||||||
|
memcpy(fpd, fps, alend * sizeof(float));
|
||||||
|
fvar = alend;
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2128,13 +2193,12 @@ chknext:
|
|||||||
#ifdef USE_BUTTON_EVENT
|
#ifdef USE_BUTTON_EVENT
|
||||||
if (!strncmp(lp, "bt[", 3)) {
|
if (!strncmp(lp, "bt[", 3)) {
|
||||||
// tasmota button state
|
// tasmota button state
|
||||||
GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar, gv);
|
||||||
uint32_t index = fvar;
|
uint32_t index = fvar;
|
||||||
if (index<1 || index>MAX_KEYS) index = 1;
|
if (index<1 || index>MAX_KEYS) index = 1;
|
||||||
fvar = glob_script_mem.script_button[index - 1];
|
fvar = glob_script_mem.script_button[index - 1];
|
||||||
glob_script_mem.script_button[index - 1] |= 0x80;
|
glob_script_mem.script_button[index - 1] |= 0x80;
|
||||||
len++;
|
goto nfuncexit;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
#endif //USE_BUTTON_EVENT
|
#endif //USE_BUTTON_EVENT
|
||||||
break;
|
break;
|
||||||
@ -2143,19 +2207,17 @@ chknext:
|
|||||||
// var changed
|
// var changed
|
||||||
struct T_INDEX ind;
|
struct T_INDEX ind;
|
||||||
uint8_t vtype;
|
uint8_t vtype;
|
||||||
isvar(lp + 4, &vtype, &ind, 0, 0, gv);
|
lp = isvar(lp + 4, &vtype, &ind, 0, 0, gv);
|
||||||
if (!ind.bits.constant) {
|
if (!ind.bits.constant) {
|
||||||
uint8_t index = glob_script_mem.type[ind.index].index;
|
uint8_t index = glob_script_mem.type[ind.index].index;
|
||||||
if (glob_script_mem.fvars[index] != glob_script_mem.s_fvars[index]) {
|
if (glob_script_mem.fvars[index] != glob_script_mem.s_fvars[index]) {
|
||||||
// var has changed
|
// var has changed
|
||||||
glob_script_mem.s_fvars[index] = glob_script_mem.fvars[index];
|
glob_script_mem.s_fvars[index] = glob_script_mem.fvars[index];
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
len++;
|
goto nfuncexit;
|
||||||
goto exit;
|
|
||||||
} else {
|
} else {
|
||||||
fvar = 0;
|
fvar = 0;
|
||||||
len++;
|
goto nfuncexit;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2648,6 +2710,19 @@ chknext:
|
|||||||
fvar = UfsInfo(fvar, 0);
|
fvar = UfsInfo(fvar, 0);
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
|
if (!strncmp(lp, "frn(", 4)) {
|
||||||
|
// rename a file
|
||||||
|
char fn_from[glob_script_mem.max_ssize + 1];
|
||||||
|
lp = GetStringArgument(lp + 4, OPER_EQU, fn_from, 0);
|
||||||
|
SCRIPT_SKIP_SPACES
|
||||||
|
|
||||||
|
char fn_to[glob_script_mem.max_ssize + 1];
|
||||||
|
lp = GetStringArgument(lp, OPER_EQU, fn_to, 0);
|
||||||
|
SCRIPT_SKIP_SPACES
|
||||||
|
|
||||||
|
fvar = ufsp->rename(fn_from, fn_to);
|
||||||
|
goto nfuncexit;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_FEXTRACT
|
#ifdef USE_FEXTRACT
|
||||||
if (!strncmp(lp, "fxt(", 4)) {
|
if (!strncmp(lp, "fxt(", 4)) {
|
||||||
@ -2667,25 +2742,29 @@ chknext:
|
|||||||
|
|
||||||
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
uint8_t coffs = fvar;
|
int8_t coffs = fvar;
|
||||||
|
if (coffs >= 0) {
|
||||||
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
||||||
SCRIPT_SKIP_SPACES
|
|
||||||
int16_t accum = fvar;
|
|
||||||
|
|
||||||
uint16_t a_len[MAX_EXT_ARRAYS];
|
|
||||||
float *a_ptr[MAX_EXT_ARRAYS];
|
|
||||||
|
|
||||||
uint8_t index = 0;
|
|
||||||
while (index < MAX_EXT_ARRAYS) {
|
|
||||||
lp = get_array_by_name(lp, &a_ptr[index], &a_len[index]);
|
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
index++;
|
int16_t accum = fvar;
|
||||||
if (*lp == ')' || *lp == '\n') {
|
|
||||||
break;
|
uint16_t a_len[MAX_EXT_ARRAYS];
|
||||||
|
float *a_ptr[MAX_EXT_ARRAYS];
|
||||||
|
|
||||||
|
uint8_t index = 0;
|
||||||
|
while (index < MAX_EXT_ARRAYS) {
|
||||||
|
lp = get_array_by_name(lp, &a_ptr[index], &a_len[index]);
|
||||||
|
SCRIPT_SKIP_SPACES
|
||||||
|
index++;
|
||||||
|
if (*lp == ')' || *lp == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
fvar = extract_from_file(fref, ts_from, ts_to, coffs, a_ptr, a_len, index, accum);
|
||||||
|
} else {
|
||||||
|
fvar = extract_from_file(fref, ts_from, ts_to, coffs, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
fvar = extract_from_file(fref, ts_from, ts_to, coffs, a_ptr, a_len, index, accum);
|
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
#endif // USE_FEXTRACT
|
#endif // USE_FEXTRACT
|
||||||
@ -2712,7 +2791,7 @@ chknext:
|
|||||||
for (uint32_t cnt = 0; cnt < alen; cnt++) {
|
for (uint32_t cnt = 0; cnt < alen; cnt++) {
|
||||||
dtostrfd(*fa, glob_script_mem.script_dprec, dstr);
|
dtostrfd(*fa, glob_script_mem.script_dprec, dstr);
|
||||||
fa++;
|
fa++;
|
||||||
if (cnt < (len - 1)) {
|
if (cnt < (alen - 1)) {
|
||||||
strcat(dstr,"\t");
|
strcat(dstr,"\t");
|
||||||
} else {
|
} else {
|
||||||
if (!append) {
|
if (!append) {
|
||||||
@ -3526,12 +3605,22 @@ chknext:
|
|||||||
#endif //USE_ANGLE_FUNC
|
#endif //USE_ANGLE_FUNC
|
||||||
|
|
||||||
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
|
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
|
||||||
|
extern char *SML_GetSVal(uint32_t index);
|
||||||
|
|
||||||
if (!strncmp(lp, "sml[", 4)) {
|
if (!strncmp(lp, "sml[", 4)) {
|
||||||
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
fvar = SML_GetVal(fvar);
|
fvar = SML_GetVal(fvar);
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
|
if (!strncmp(lp, "smls[", 5)) {
|
||||||
|
lp = GetNumericArgument(lp + 5, OPER_EQU, &fvar, gv);
|
||||||
|
SCRIPT_SKIP_SPACES
|
||||||
|
lp++;
|
||||||
|
len = 0;
|
||||||
|
if (sp) strlcpy(sp, SML_GetSVal(fvar), glob_script_mem.max_ssize);
|
||||||
|
goto strexit;;
|
||||||
|
}
|
||||||
if (!strncmp(lp, "sml(", 4)) {
|
if (!strncmp(lp, "sml(", 4)) {
|
||||||
float fvar1;
|
float fvar1;
|
||||||
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar1, gv);
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar1, gv);
|
||||||
@ -4801,27 +4890,34 @@ int16_t retval;
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,floop=0,globvindex,fromscriptcmd=0;
|
uint8_t vtype = 0, sindex, xflg, floop = 0, globvindex, fromscriptcmd = 0;
|
||||||
char *lp_next;
|
char *lp_next;
|
||||||
int16_t globaindex,saindex;
|
int16_t globaindex, saindex;
|
||||||
struct T_INDEX ind;
|
struct T_INDEX ind;
|
||||||
uint8_t operand,lastop,numeric = 1,if_state[IF_NEST],if_exe[IF_NEST],if_result[IF_NEST],and_or,ifstck = 0;
|
uint8_t operand, lastop, numeric = 1, if_state[IF_NEST], if_exe[IF_NEST], if_result[IF_NEST], and_or, ifstck = 0;
|
||||||
if_state[ifstck] = 0;
|
if_state[ifstck] = 0;
|
||||||
if_result[ifstck] = 0;
|
if_result[ifstck] = 0;
|
||||||
if_exe[ifstck] = 1;
|
if_exe[ifstck] = 1;
|
||||||
char cmpstr[SCRIPT_MAXSSIZE];
|
char cmpstr[SCRIPT_MAXSSIZE];
|
||||||
|
float *dfvar, *cv_count, cv_max, cv_inc;
|
||||||
|
char *cv_ptr;
|
||||||
|
float fvar = 0, fvar1, sysvar, swvar;
|
||||||
|
uint8_t section = 0, sysv_type = 0, swflg = 0;
|
||||||
|
|
||||||
|
char *lp;
|
||||||
|
if (tlen == 0) {
|
||||||
|
section = 1;
|
||||||
|
lp = (char*)type;
|
||||||
|
} else {
|
||||||
|
lp = glob_script_mem.scriptptr;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t check = 0;
|
uint8_t check = 0;
|
||||||
if (tlen<0) {
|
if (tlen<0) {
|
||||||
tlen = abs(tlen);
|
tlen = abs(tlen);
|
||||||
check = 1;
|
check = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float *dfvar,*cv_count,cv_max,cv_inc;
|
|
||||||
char *cv_ptr;
|
|
||||||
float fvar = 0,fvar1,sysvar,swvar;
|
|
||||||
uint8_t section = 0,sysv_type = 0,swflg = 0;
|
|
||||||
|
|
||||||
char *lp = glob_script_mem.scriptptr;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// check line
|
// check line
|
||||||
@ -5405,7 +5501,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
}
|
}
|
||||||
#endif //USE_SCRIPT_GLOBVARS
|
#endif //USE_SCRIPT_GLOBVARS
|
||||||
if (glob_script_mem.type[globvindex].bits.is_filter) {
|
if (glob_script_mem.type[globvindex].bits.is_filter) {
|
||||||
if (globaindex>=0) {
|
if (globaindex >= 0) {
|
||||||
Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar);
|
Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar);
|
||||||
} else {
|
} else {
|
||||||
Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar);
|
Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar);
|
||||||
@ -5620,7 +5716,7 @@ void ScripterEvery100ms(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
if (glob_script_mem.fast_script == 99) Run_Scripter(">F", 2, 0);
|
if (glob_script_mem.fast_script) Run_Scripter(glob_script_mem.fast_script, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6093,10 +6189,22 @@ void SaveScriptEnd(void) {
|
|||||||
Run_Scripter(">B\n", 3, 0);
|
Run_Scripter(">B\n", 3, 0);
|
||||||
Run_Scripter(">BS", 3, 0);
|
Run_Scripter(">BS", 3, 0);
|
||||||
|
|
||||||
glob_script_mem.fast_script = Run_Scripter(">F", -2, 0);
|
//glob_script_mem.fast_script = Run_Scripter(">F", -2, 0);
|
||||||
|
if (Run_Scripter(">F", -2, 0) == 99) {glob_script_mem.fast_script = glob_script_mem.section_ptr + 2;} else {glob_script_mem.fast_script = 0;}
|
||||||
|
|
||||||
|
script_set_web_pages();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void script_set_web_pages(void) {
|
||||||
|
if (Run_Scripter(">W", -2, 0) == 99) {glob_script_mem.web_pages[0] = glob_script_mem.section_ptr;} else {glob_script_mem.web_pages[0] = 0;}
|
||||||
|
if (Run_Scripter(">w ", -3, 0) == 99) {glob_script_mem.web_pages[1] = glob_script_mem.section_ptr;} else {glob_script_mem.web_pages[1] = 0;}
|
||||||
|
if (Run_Scripter(">w1 ", -4, 0) == 99) {glob_script_mem.web_pages[2] = glob_script_mem.section_ptr;} else {glob_script_mem.web_pages[2] = 0;}
|
||||||
|
if (Run_Scripter(">w2 ", -4, 0) == 99) {glob_script_mem.web_pages[3] = glob_script_mem.section_ptr;} else {glob_script_mem.web_pages[3] = 0;}
|
||||||
|
if (Run_Scripter(">w3 ", -4, 0) == 99) {glob_script_mem.web_pages[4] = glob_script_mem.section_ptr;} else {glob_script_mem.web_pages[4] = 0;}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
||||||
|
|
||||||
@ -7100,8 +7208,43 @@ void ScriptGetSDCard(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern uint8_t *buffer;
|
extern uint8_t *buffer;
|
||||||
|
bool script_download_busy;
|
||||||
|
|
||||||
|
//#define USE_DLTASK
|
||||||
|
|
||||||
void SendFile(char *fname) {
|
void SendFile(char *fname) {
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
|
SendFile_sub(fname);
|
||||||
|
#endif // ESP8266
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#ifdef USE_DLTASK
|
||||||
|
if (script_download_busy == true) {
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("UFS: Download is busy"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
script_download_busy = true;
|
||||||
|
char *path = (char*)malloc(128);
|
||||||
|
strcpy(path, fname);
|
||||||
|
xTaskCreatePinnedToCore(script_download_task, "DT", 6000, (void*)path, 3, NULL, 1);
|
||||||
|
#else
|
||||||
|
SendFile_sub(fname);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ESP32
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DLTASK
|
||||||
|
void script_download_task(void *path) {
|
||||||
|
SendFile_sub((char*) path);
|
||||||
|
free(path);
|
||||||
|
script_download_busy = false;
|
||||||
|
vTaskDelete( NULL );
|
||||||
|
}
|
||||||
|
#endif // USE_DLTASK
|
||||||
|
|
||||||
|
void SendFile_sub(char *fname) {
|
||||||
char buff[512];
|
char buff[512];
|
||||||
const char *mime = 0;
|
const char *mime = 0;
|
||||||
uint8_t sflg = 0;
|
uint8_t sflg = 0;
|
||||||
@ -7133,7 +7276,6 @@ char buff[512];
|
|||||||
|
|
||||||
if (!mime) return;
|
if (!mime) return;
|
||||||
|
|
||||||
|
|
||||||
WSContentSend_P(HTTP_SCRIPT_MIMES, fname, mime);
|
WSContentSend_P(HTTP_SCRIPT_MIMES, fname, mime);
|
||||||
|
|
||||||
if (sflg) {
|
if (sflg) {
|
||||||
@ -7234,24 +7376,25 @@ char buff[512];
|
|||||||
}
|
}
|
||||||
#endif // USE_DISPLAY_DUMP
|
#endif // USE_DISPLAY_DUMP
|
||||||
} else {
|
} else {
|
||||||
File file = ufsp->open(fname,FS_FILE_READ);
|
File file = ufsp->open(fname, FS_FILE_READ);
|
||||||
uint32_t siz = file.size();
|
uint32_t siz = file.size();
|
||||||
uint32_t len = sizeof(buff);
|
uint32_t len = sizeof(buff);
|
||||||
while (siz > 0) {
|
while (siz > 0) {
|
||||||
if (len>siz) len = siz;
|
if (len > siz) len = siz;
|
||||||
file.read((uint8_t *)buff, len);
|
file.read((uint8_t *)buff, len);
|
||||||
Webserver->client().write((const char*)buff, len);
|
Webserver->client().write((const char*)buff, len);
|
||||||
siz -= len;
|
siz -= len;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
|
Webserver->client().stop();
|
||||||
}
|
}
|
||||||
Webserver->client().stop();
|
|
||||||
}
|
}
|
||||||
#endif // USE_UFILESYS
|
#endif // USE_UFILESYS
|
||||||
|
|
||||||
|
|
||||||
#ifdef SCRIPT_FULL_WEBPAGE
|
#ifdef SCRIPT_FULL_WEBPAGE
|
||||||
const char HTTP_WEB_FULL_DISPLAY[] PROGMEM =
|
const char HTTP_WEB_FULL_DISPLAY[] PROGMEM =
|
||||||
"<p><form action='" "sfd" "' method='get'><button>" "%s" "</button></form></p>";
|
"<p><form action='" "sfd%1d" "' method='get'><button>" "%s" "</button></form></p>";
|
||||||
|
|
||||||
const char HTTP_SCRIPT_FULLPAGE1[] PROGMEM =
|
const char HTTP_SCRIPT_FULLPAGE1[] PROGMEM =
|
||||||
"<!DOCTYPE html><html lang=\"" D_HTML_LANGUAGE "\" class=\"\">"
|
"<!DOCTYPE html><html lang=\"" D_HTML_LANGUAGE "\" class=\"\">"
|
||||||
@ -7287,7 +7430,7 @@ const char HTTP_SCRIPT_FULLPAGE1[] PROGMEM =
|
|||||||
"}"
|
"}"
|
||||||
"};"
|
"};"
|
||||||
"if (rfsh) {"
|
"if (rfsh) {"
|
||||||
"x.open('GET','./sfd?m=1'+a,true);" // ?m related to Webserver->hasArg("m")
|
"x.open('GET','./sfd%1d?m=1'+a,true);" // ?m related to Webserver->hasArg("m")
|
||||||
"x.send();"
|
"x.send();"
|
||||||
"lt=setTimeout(la,%d);" // Settings->web_refresh
|
"lt=setTimeout(la,%d);" // Settings->web_refresh
|
||||||
"}"
|
"}"
|
||||||
@ -7313,9 +7456,21 @@ const char HTTP_SCRIPT_FULLPAGE2[] PROGMEM =
|
|||||||
"}"
|
"}"
|
||||||
"</script>";
|
"</script>";
|
||||||
|
|
||||||
|
void ScriptFullWebpage1(void) {
|
||||||
|
ScriptFullWebpage(1);
|
||||||
|
}
|
||||||
|
void ScriptFullWebpage2(void) {
|
||||||
|
ScriptFullWebpage(2);
|
||||||
|
}
|
||||||
|
void ScriptFullWebpage3(void) {
|
||||||
|
ScriptFullWebpage(3);
|
||||||
|
}
|
||||||
|
void ScriptFullWebpage4(void) {
|
||||||
|
ScriptFullWebpage(4);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptFullWebpage(void) {
|
void ScriptFullWebpage(uint8_t page) {
|
||||||
uint32_t fullpage_refresh=10000;
|
uint32_t fullpage_refresh = 10000;
|
||||||
if (!HttpCheckPriviledgedAccess()) { return; }
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
|
|
||||||
String stmp = Webserver->uri();
|
String stmp = Webserver->uri();
|
||||||
@ -7325,7 +7480,7 @@ void ScriptFullWebpage(void) {
|
|||||||
Script_Check_HTML_Setvars();
|
Script_Check_HTML_Setvars();
|
||||||
}
|
}
|
||||||
WSContentBegin(200, CT_HTML);
|
WSContentBegin(200, CT_HTML);
|
||||||
ScriptWebShow('w');
|
ScriptWebShow('w', page);
|
||||||
WSContentEnd();
|
WSContentEnd();
|
||||||
//Serial.printf("fwp update sv %s\n",stmp.c_str() );
|
//Serial.printf("fwp update sv %s\n",stmp.c_str() );
|
||||||
return; //goto redraw;
|
return; //goto redraw;
|
||||||
@ -7340,7 +7495,7 @@ void ScriptFullWebpage(void) {
|
|||||||
|
|
||||||
WSContentBegin(200, CT_HTML);
|
WSContentBegin(200, CT_HTML);
|
||||||
const char *title = "Full Screen";
|
const char *title = "Full Screen";
|
||||||
WSContentSend_P(HTTP_SCRIPT_FULLPAGE1, SettingsText(SET_DEVICENAME), title, fullpage_refresh);
|
WSContentSend_P(HTTP_SCRIPT_FULLPAGE1, SettingsText(SET_DEVICENAME), title, page , fullpage_refresh);
|
||||||
WSContentSend_P(HTTP_SCRIPT_FULLPAGE2, fullpage_refresh);
|
WSContentSend_P(HTTP_SCRIPT_FULLPAGE2, fullpage_refresh);
|
||||||
//WSContentSend_P(PSTR("<div id='l1' name='l1'></div>"));
|
//WSContentSend_P(PSTR("<div id='l1' name='l1'></div>"));
|
||||||
|
|
||||||
@ -7348,10 +7503,10 @@ void ScriptFullWebpage(void) {
|
|||||||
|
|
||||||
|
|
||||||
WSContentSend_P(PSTR("<div id='l1' name='l1'>"));
|
WSContentSend_P(PSTR("<div id='l1' name='l1'>"));
|
||||||
ScriptWebShow('w');
|
ScriptWebShow('w', page);
|
||||||
WSContentSend_P(PSTR("</div>"));
|
WSContentSend_P(PSTR("</div>"));
|
||||||
|
|
||||||
ScriptWebShow('x');
|
ScriptWebShow('x', page);
|
||||||
|
|
||||||
WSContentStop();
|
WSContentStop();
|
||||||
}
|
}
|
||||||
@ -7518,15 +7673,15 @@ uint16 entries = 0;
|
|||||||
uint16_t cipos = 0;
|
uint16_t cipos = 0;
|
||||||
|
|
||||||
uint8_t anum = 0;
|
uint8_t anum = 0;
|
||||||
while (anum<MAX_GARRAY) {
|
while (anum < MAX_GARRAY) {
|
||||||
if (*lp==')' || *lp==0) break;
|
if (*lp == ')' || *lp == 0) break;
|
||||||
char *lp1 = lp;
|
char *lp1 = lp;
|
||||||
float sysvar;
|
float sysvar;
|
||||||
lp=isvar(lp, &vtype, &ind, &sysvar, 0, 0);
|
lp=isvar(lp, &vtype, &ind, &sysvar, 0, 0);
|
||||||
if (vtype!=VAR_NV) {
|
if (vtype != VAR_NV) {
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
uint8_t index = glob_script_mem.type[ind.index].index;
|
uint8_t index = glob_script_mem.type[ind.index].index;
|
||||||
if ((vtype&STYPE)==0) {
|
if ((vtype&STYPE) == 0) {
|
||||||
// numeric result
|
// numeric result
|
||||||
//Serial.printf("numeric %d - %d \n",ind.index,index);
|
//Serial.printf("numeric %d - %d \n",ind.index,index);
|
||||||
if (glob_script_mem.type[ind.index].bits.is_filter) {
|
if (glob_script_mem.type[ind.index].bits.is_filter) {
|
||||||
@ -7534,7 +7689,7 @@ uint16_t cipos = 0;
|
|||||||
uint16_t len = 0;
|
uint16_t len = 0;
|
||||||
float *fa = Get_MFAddr(index, &len, &cipos);
|
float *fa = Get_MFAddr(index, &len, &cipos);
|
||||||
//Serial.printf(">> 2 %d\n",len);
|
//Serial.printf(">> 2 %d\n",len);
|
||||||
if (fa && len>=entries) {
|
if (fa && len >= entries) {
|
||||||
if (!entries) {
|
if (!entries) {
|
||||||
entries = len;
|
entries = len;
|
||||||
}
|
}
|
||||||
@ -7588,19 +7743,22 @@ uint32_t cnt;
|
|||||||
nbuf[cnt] = 0;
|
nbuf[cnt] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptWebShow(char mc) {
|
void ScriptWebShow(char mc, uint8_t page) {
|
||||||
uint8_t web_script;
|
uint8_t web_script;
|
||||||
glob_script_mem.web_mode = mc;
|
glob_script_mem.web_mode = mc;
|
||||||
if (mc=='w' || mc=='x') {
|
if (mc=='w' || mc=='x') {
|
||||||
if (mc=='x') {
|
if (mc=='x') {
|
||||||
mc='$';
|
mc='$';
|
||||||
}
|
}
|
||||||
web_script = Run_Scripter(">w", -2, 0);
|
//web_script = Run_Scripter(">w", -2, 0);
|
||||||
|
glob_script_mem.section_ptr = glob_script_mem.web_pages[page];
|
||||||
} else {
|
} else {
|
||||||
web_script = Run_Scripter(">W", -2, 0);
|
//web_script = Run_Scripter(">W", -2, 0);
|
||||||
|
glob_script_mem.section_ptr = glob_script_mem.web_pages[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (web_script==99) {
|
//if (web_script==99) {
|
||||||
|
if (glob_script_mem.section_ptr) {
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
uint8_t optflg = 0;
|
uint8_t optflg = 0;
|
||||||
uint8_t chartindex = 1;
|
uint8_t chartindex = 1;
|
||||||
@ -8102,6 +8260,12 @@ exgc:
|
|||||||
lp = GetStringArgument(lp, OPER_EQU, label, 0);
|
lp = GetStringArgument(lp, OPER_EQU, label, 0);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
|
|
||||||
|
uint8_t asflg = 1;
|
||||||
|
if (label[0] == '&') {
|
||||||
|
strcpy(label, &label[1]);
|
||||||
|
asflg = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int16_t divflg = 1;
|
int16_t divflg = 1;
|
||||||
int16_t todflg = -1;
|
int16_t todflg = -1;
|
||||||
if (!strncmp(label, "cnt", 3)) {
|
if (!strncmp(label, "cnt", 3)) {
|
||||||
@ -8123,7 +8287,7 @@ exgc:
|
|||||||
}
|
}
|
||||||
uint16 segments = 1;
|
uint16 segments = 1;
|
||||||
for (uint32_t cnt = 0; cnt < strlen(lp); cnt++) {
|
for (uint32_t cnt = 0; cnt < strlen(lp); cnt++) {
|
||||||
if (lp[cnt]=='|') {
|
if (lp[cnt] == '|') {
|
||||||
segments++;
|
segments++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8131,18 +8295,18 @@ exgc:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t aind = ipos;
|
uint32_t aind = ipos;
|
||||||
if (aind>=entries) aind = entries - 1;
|
if (aind >= entries) aind = entries - 1;
|
||||||
for (uint32_t cnt = 0; cnt < entries; cnt++) {
|
for (uint32_t cnt = 0; cnt < entries; cnt++) {
|
||||||
WSContentSend_PD("['");
|
WSContentSend_PD("['");
|
||||||
char lbl[16];
|
char lbl[16];
|
||||||
if (todflg>=0) {
|
if (todflg >= 0) {
|
||||||
sprintf(lbl, "%d:%02d", todflg / divflg, (todflg % divflg) * (60 / divflg) );
|
sprintf(lbl, "%d:%02d", todflg / divflg, (todflg % divflg) * (60 / divflg) );
|
||||||
todflg++;
|
todflg++;
|
||||||
if (todflg >= entries) {
|
if (todflg >= entries) {
|
||||||
todflg = 0;
|
todflg = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (todflg==-1) {
|
if (todflg == -1) {
|
||||||
GetTextIndexed(lbl, sizeof(lbl), aind / divflg, label);
|
GetTextIndexed(lbl, sizeof(lbl), aind / divflg, label);
|
||||||
} else {
|
} else {
|
||||||
// day,hours,mins
|
// day,hours,mins
|
||||||
@ -8155,14 +8319,20 @@ exgc:
|
|||||||
for (uint32_t ind = 0; ind < anum; ind++) {
|
for (uint32_t ind = 0; ind < anum; ind++) {
|
||||||
char acbuff[32];
|
char acbuff[32];
|
||||||
float *fp = arrays[ind];
|
float *fp = arrays[ind];
|
||||||
f2char(fp[aind], glob_script_mem.script_dprec, glob_script_mem.script_lzero, acbuff);
|
float fval;
|
||||||
|
if (asflg) {
|
||||||
|
fval = fp[aind];
|
||||||
|
} else {
|
||||||
|
fval = fp[cnt];
|
||||||
|
}
|
||||||
|
f2char(fval, glob_script_mem.script_dprec, glob_script_mem.script_lzero, acbuff);
|
||||||
WSContentSend_PD("%s", acbuff);
|
WSContentSend_PD("%s", acbuff);
|
||||||
if (ind<anum - 1) { WSContentSend_PD(","); }
|
if (ind < anum - 1) { WSContentSend_PD(","); }
|
||||||
}
|
}
|
||||||
WSContentSend_PD("]");
|
WSContentSend_PD("]");
|
||||||
if (cnt<entries - 1) { WSContentSend_PD(","); }
|
if (cnt < entries - 1) { WSContentSend_PD(","); }
|
||||||
aind++;
|
aind++;
|
||||||
if (aind>=entries) {
|
if (aind >= entries) {
|
||||||
aind = 0;
|
aind = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8338,11 +8508,10 @@ bool RulesProcessEvent(const char *json_event) {
|
|||||||
#define STASK_STACK 8192-2048
|
#define STASK_STACK 8192-2048
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
|
||||||
struct ESP32_Task {
|
struct ESP32_Task {
|
||||||
uint16_t task_timer;
|
uint16_t task_timer;
|
||||||
TaskHandle_t task_t;
|
TaskHandle_t task_t;
|
||||||
|
char *tstart;
|
||||||
} esp32_tasks[2];
|
} esp32_tasks[2];
|
||||||
|
|
||||||
|
|
||||||
@ -8355,25 +8524,28 @@ void script_task1(void *arg) {
|
|||||||
//time=esp32_tasks[0].task_timer-time;
|
//time=esp32_tasks[0].task_timer-time;
|
||||||
//if (time<esp32_tasks[1].task_timer) {delay(time); }
|
//if (time<esp32_tasks[1].task_timer) {delay(time); }
|
||||||
//if (time<=esp32_tasks[0].task_timer) {vTaskDelay( pdMS_TO_TICKS( time ) ); }
|
//if (time<=esp32_tasks[0].task_timer) {vTaskDelay( pdMS_TO_TICKS( time ) ); }
|
||||||
delay(esp32_tasks[0].task_timer);
|
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
Run_Scripter(">t1", 3, 0);
|
if (esp32_tasks[0].tstart) Run_Scripter(esp32_tasks[0].tstart, 0, 0);
|
||||||
|
}
|
||||||
|
if (esp32_tasks[0].task_timer) {
|
||||||
|
delay(esp32_tasks[0].task_timer);
|
||||||
|
} else {
|
||||||
|
esp32_tasks[0].task_t = 0;
|
||||||
|
vTaskDelete( NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void script_task2(void *arg) {
|
void script_task2(void *arg) {
|
||||||
//uint32_t lastms=millis();
|
|
||||||
//uint32_t time;
|
|
||||||
while (1) {
|
while (1) {
|
||||||
//time=millis()-lastms;
|
|
||||||
//lastms=millis();
|
|
||||||
//time=esp32_tasks[1].task_timer-time;
|
|
||||||
//if (time<esp32_tasks[1].task_timer) {delay(time); }
|
|
||||||
//if (time<=esp32_tasks[1].task_timer) {vTaskDelay( pdMS_TO_TICKS( time ) ); }
|
|
||||||
delay(esp32_tasks[1].task_timer);
|
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
Run_Scripter(">t2", 3, 0);
|
if (esp32_tasks[1].tstart) Run_Scripter(esp32_tasks[1].tstart, 0, 0);
|
||||||
|
}
|
||||||
|
if (esp32_tasks[1].task_timer) {
|
||||||
|
delay(esp32_tasks[1].task_timer);
|
||||||
|
} else {
|
||||||
|
esp32_tasks[1].task_t = 0;
|
||||||
|
vTaskDelete( NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8389,49 +8561,23 @@ uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core, int32_
|
|||||||
esp32_tasks[num].task_t = 0;
|
esp32_tasks[num].task_t = 0;
|
||||||
}
|
}
|
||||||
if (prio >= 0) {
|
if (prio >= 0) {
|
||||||
res = xTaskCreatePinnedToCore(script_task1, num==0?"T1":"T2", STASK_STACK, NULL, prio, &esp32_tasks[num].task_t, core);
|
char *sp = 0;
|
||||||
esp32_tasks[num].task_timer = time;
|
esp32_tasks[num].task_timer = time;
|
||||||
|
if (!num) {
|
||||||
|
if (Run_Scripter(">t1", -3, 0) == 99) {
|
||||||
|
sp = glob_script_mem.section_ptr + 2;
|
||||||
|
res = xTaskCreatePinnedToCore(script_task1, "T1", STASK_STACK, NULL, prio, &esp32_tasks[num].task_t, core);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (Run_Scripter(">t2", -3, 0) == 99) {
|
||||||
|
sp = glob_script_mem.section_ptr + 2;
|
||||||
|
res = xTaskCreatePinnedToCore(script_task2, "T2", STASK_STACK, NULL, prio, &esp32_tasks[num].task_t, core);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
esp32_tasks[num].tstart = sp;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
|
||||||
uint16_t task_timer1;
|
|
||||||
uint16_t task_timer2;
|
|
||||||
TaskHandle_t task_t1;
|
|
||||||
TaskHandle_t task_t2;
|
|
||||||
|
|
||||||
void script_task1(void *arg) {
|
|
||||||
while (1) {
|
|
||||||
delay(task_timer1);
|
|
||||||
Run_Scripter(">t1", 3, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void script_task2(void *arg) {
|
|
||||||
while (1) {
|
|
||||||
delay(task_timer2);
|
|
||||||
Run_Scripter(">t2", 3, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core, int32_t prio) {
|
|
||||||
//return 0;
|
|
||||||
BaseType_t res = 0;
|
|
||||||
if (core > 1) { core = 1; }
|
|
||||||
if (num == 1) {
|
|
||||||
if (task_t1) { vTaskDelete(task_t1); }
|
|
||||||
res = xTaskCreatePinnedToCore(script_task1, "T1", STASK_STACK, NULL, prio, &task_t1, core);
|
|
||||||
task_timer1 = time;
|
|
||||||
} else {
|
|
||||||
if (task_t2) { vTaskDelete(task_t2); }
|
|
||||||
res = xTaskCreatePinnedToCore(script_task2, "T2", STASK_STACK, NULL, prio, &task_t2, core);
|
|
||||||
task_timer2 = time;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // USE_SCRIPT_TASK
|
#endif // USE_SCRIPT_TASK
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
|
|
||||||
@ -8443,13 +8589,14 @@ int32_t url2file(uint8_t fref, char *url) {
|
|||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
int32_t httpCode = 0;
|
int32_t httpCode = 0;
|
||||||
String weburl = "http://"+UrlEncode(url);
|
String weburl = "http://"+UrlEncode(url);
|
||||||
for (uint32_t retry = 0; retry < 15; retry++) {
|
//for (uint32_t retry = 0; retry < 15; retry++) {
|
||||||
http.begin(http_client, weburl);
|
http.begin(http_client, weburl);
|
||||||
|
delay(100);
|
||||||
httpCode = http.GET();
|
httpCode = http.GET();
|
||||||
if (httpCode > 0) {
|
//if (httpCode > 0) {
|
||||||
break;
|
// break;
|
||||||
}
|
//}
|
||||||
}
|
//}
|
||||||
if (httpCode < 0) {
|
if (httpCode < 0) {
|
||||||
AddLog(LOG_LEVEL_INFO,PSTR("HTTP error %d = %s"), httpCode, http.errorToString(httpCode).c_str());
|
AddLog(LOG_LEVEL_INFO,PSTR("HTTP error %d = %s"), httpCode, http.errorToString(httpCode).c_str());
|
||||||
}
|
}
|
||||||
@ -9103,6 +9250,37 @@ int32_t retval = 0;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SCRIPT_FULL_WEBPAGE
|
||||||
|
void script_add_subpage(uint8_t num) {
|
||||||
|
//uint8_t web_script = Run_Scripter(code, -strlen(code), 0);
|
||||||
|
if (glob_script_mem.web_pages[num]) {
|
||||||
|
char bname[48];
|
||||||
|
cpy2lf(bname, sizeof(bname), glob_script_mem.web_pages[num] + 3);
|
||||||
|
|
||||||
|
void (*wptr)(void);
|
||||||
|
|
||||||
|
char id[8];
|
||||||
|
switch (num) {
|
||||||
|
case 1:
|
||||||
|
wptr = ScriptFullWebpage1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
wptr = ScriptFullWebpage2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
wptr = ScriptFullWebpage3;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
wptr = ScriptFullWebpage4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sprintf_P(id, PSTR("/sfd%1d"), num);
|
||||||
|
Webserver->on(id, wptr);
|
||||||
|
WSContentSend_PD(HTTP_WEB_FULL_DISPLAY, num, bname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // SCRIPT_FULL_WEBPAGE
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Interface
|
* Interface
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
@ -9265,7 +9443,8 @@ bool Xdrv10(uint8_t function)
|
|||||||
//case FUNC_INIT:
|
//case FUNC_INIT:
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
Run_Scripter(">B\n", 3, 0);
|
Run_Scripter(">B\n", 3, 0);
|
||||||
glob_script_mem.fast_script = Run_Scripter(">F", -2, 0);
|
if (Run_Scripter(">F", -2, 0) == 99) {glob_script_mem.fast_script = glob_script_mem.section_ptr + 2;} else {glob_script_mem.fast_script = 0;}
|
||||||
|
script_set_web_pages();
|
||||||
#if defined(USE_SCRIPT_HUE) && defined(USE_WEBSERVER) && defined(USE_EMULATION) && defined(USE_EMULATION_HUE) && defined(USE_LIGHT)
|
#if defined(USE_SCRIPT_HUE) && defined(USE_WEBSERVER) && defined(USE_EMULATION) && defined(USE_EMULATION_HUE) && defined(USE_LIGHT)
|
||||||
Script_Check_Hue(0);
|
Script_Check_Hue(0);
|
||||||
#endif //USE_SCRIPT_HUE
|
#endif //USE_SCRIPT_HUE
|
||||||
@ -9324,15 +9503,12 @@ bool Xdrv10(uint8_t function)
|
|||||||
#ifdef USE_SCRIPT_WEB_DISPLAY
|
#ifdef USE_SCRIPT_WEB_DISPLAY
|
||||||
case FUNC_WEB_ADD_MAIN_BUTTON:
|
case FUNC_WEB_ADD_MAIN_BUTTON:
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
ScriptWebShow('$');
|
ScriptWebShow('$', 0);
|
||||||
#ifdef SCRIPT_FULL_WEBPAGE
|
#ifdef SCRIPT_FULL_WEBPAGE
|
||||||
uint8_t web_script = Run_Scripter(">w", -2, 0);
|
script_add_subpage(1);
|
||||||
if (web_script==99) {
|
script_add_subpage(2);
|
||||||
char bname[48];
|
script_add_subpage(3);
|
||||||
cpy2lf(bname, sizeof(bname), glob_script_mem.section_ptr + 3);
|
script_add_subpage(4);
|
||||||
WSContentSend_PD(HTTP_WEB_FULL_DISPLAY, bname);
|
|
||||||
Webserver->on("/sfd", ScriptFullWebpage);
|
|
||||||
}
|
|
||||||
#endif // SCRIPT_FULL_WEBPAGE
|
#endif // SCRIPT_FULL_WEBPAGE
|
||||||
|
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
@ -9368,7 +9544,7 @@ bool Xdrv10(uint8_t function)
|
|||||||
#ifdef USE_SCRIPT_WEB_DISPLAY
|
#ifdef USE_SCRIPT_WEB_DISPLAY
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
if (bitRead(Settings->rule_enabled, 0)) {
|
if (bitRead(Settings->rule_enabled, 0)) {
|
||||||
ScriptWebShow(0);
|
ScriptWebShow(0, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif //USE_SCRIPT_WEB_DISPLAY
|
#endif //USE_SCRIPT_WEB_DISPLAY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user