mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 18:56:38 +00:00
bug fixes and enhancements
This commit is contained in:
parent
eaed13abb5
commit
e452f85e39
@ -79,6 +79,7 @@ uint32_t DecodeLightId(uint32_t hue_id);
|
|||||||
#undef LITTLEFS_SCRIPT_SIZE
|
#undef LITTLEFS_SCRIPT_SIZE
|
||||||
#undef EEP_SCRIPT_SIZE
|
#undef EEP_SCRIPT_SIZE
|
||||||
#undef USE_SCRIPT_COMPRESSION
|
#undef USE_SCRIPT_COMPRESSION
|
||||||
|
|
||||||
#if USE_SCRIPT_FATFS==-1
|
#if USE_SCRIPT_FATFS==-1
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
@ -250,9 +251,9 @@ SDClass *fsp;
|
|||||||
#define FAT_SCRIPT_NAME "script.txt"
|
#define FAT_SCRIPT_NAME "script.txt"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_STANDARD_SPI_LIBRARY==0
|
//#if USE_STANDARD_SPI_LIBRARY==0
|
||||||
#warning ("FATFS standard spi should be used");
|
//#warning ("FATFS standard spi should be used");
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#endif // USE_SCRIPT_FATFS
|
#endif // USE_SCRIPT_FATFS
|
||||||
|
|
||||||
@ -377,7 +378,11 @@ struct SCRIPT_MEM {
|
|||||||
struct T_INDEX *type; // type and index pointer
|
struct T_INDEX *type; // type and index pointer
|
||||||
struct M_FILT *mfilt;
|
struct M_FILT *mfilt;
|
||||||
char *glob_vnp; // var name pointer
|
char *glob_vnp; // var name pointer
|
||||||
|
#ifdef SCRIPT_LARGE_VNBUFF
|
||||||
|
uint16_t *vnp_offset;
|
||||||
|
#else
|
||||||
uint8_t *vnp_offset;
|
uint8_t *vnp_offset;
|
||||||
|
#endif
|
||||||
char *glob_snp; // string vars pointer
|
char *glob_snp; // string vars pointer
|
||||||
char *scriptptr;
|
char *scriptptr;
|
||||||
char *section_ptr;
|
char *section_ptr;
|
||||||
@ -511,7 +516,7 @@ char *script;
|
|||||||
char **snp_p = snp;
|
char **snp_p = snp;
|
||||||
uint8_t numperm = 0;
|
uint8_t numperm = 0;
|
||||||
uint8_t numflt = 0;
|
uint8_t numflt = 0;
|
||||||
uint8_t count;
|
uint16_t count;
|
||||||
|
|
||||||
glob_script_mem.max_ssize = SCRIPT_SVARSIZE;
|
glob_script_mem.max_ssize = SCRIPT_SVARSIZE;
|
||||||
glob_script_mem.scriptptr = 0;
|
glob_script_mem.scriptptr = 0;
|
||||||
@ -592,7 +597,7 @@ char *script;
|
|||||||
} else {
|
} else {
|
||||||
vtypes[vars].bits.is_filter = 0;
|
vtypes[vars].bits.is_filter = 0;
|
||||||
}
|
}
|
||||||
*vnp_p ++= vnames_p;
|
*vnp_p++ = vnames_p;
|
||||||
while (lp<op) {
|
while (lp<op) {
|
||||||
*vnames_p++ = *lp++;
|
*vnames_p++ = *lp++;
|
||||||
}
|
}
|
||||||
@ -684,7 +689,11 @@ char *script;
|
|||||||
// var names
|
// var names
|
||||||
(vnames_p-vnames) +
|
(vnames_p-vnames) +
|
||||||
// vars offsets
|
// vars offsets
|
||||||
|
#ifdef SCRIPT_LARGE_VNBUFF
|
||||||
|
(sizeof(uint16_t)*vars) +
|
||||||
|
#else
|
||||||
(sizeof(uint8_t)*vars) +
|
(sizeof(uint8_t)*vars) +
|
||||||
|
#endif
|
||||||
// strings
|
// strings
|
||||||
(glob_script_mem.max_ssize*svars) +
|
(glob_script_mem.max_ssize*svars) +
|
||||||
// type array
|
// type array
|
||||||
@ -727,8 +736,14 @@ char *script;
|
|||||||
memcpy(script_mem, vnames, size);
|
memcpy(script_mem, vnames, size);
|
||||||
script_mem += size;
|
script_mem += size;
|
||||||
|
|
||||||
|
#ifdef SCRIPT_LARGE_VNBUFF
|
||||||
|
glob_script_mem.vnp_offset = (uint16_t*)script_mem;
|
||||||
|
size = vars*sizeof(uint16_t);
|
||||||
|
#else
|
||||||
glob_script_mem.vnp_offset = (uint8_t*)script_mem;
|
glob_script_mem.vnp_offset = (uint8_t*)script_mem;
|
||||||
size = vars*sizeof(uint8_t);
|
size = vars*sizeof(uint8_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
script_mem += size;
|
script_mem += size;
|
||||||
|
|
||||||
// strings
|
// strings
|
||||||
@ -738,10 +753,20 @@ char *script;
|
|||||||
//memcpy(script_mem,strings,size);
|
//memcpy(script_mem,strings,size);
|
||||||
script_mem += size;
|
script_mem += size;
|
||||||
|
|
||||||
|
|
||||||
// now must recalc memory offsets
|
// now must recalc memory offsets
|
||||||
uint16_t index = 0;
|
uint16_t index = 0;
|
||||||
|
#ifdef SCRIPT_LARGE_VNBUFF
|
||||||
|
#ifndef MAXVNSIZ
|
||||||
|
#define MAXVNSIZ 4096
|
||||||
|
#endif
|
||||||
|
uint16_t *cp = glob_script_mem.vnp_offset;
|
||||||
|
#else
|
||||||
|
#undef MAXVNSIZ
|
||||||
|
#define MAXVNSIZ 255
|
||||||
uint8_t *cp = glob_script_mem.vnp_offset;
|
uint8_t *cp = glob_script_mem.vnp_offset;
|
||||||
for (count=0;count<vars;count++) {
|
#endif
|
||||||
|
for (count = 0; count<vars; count++) {
|
||||||
*cp++ = index;
|
*cp++ = index;
|
||||||
while (*namep) {
|
while (*namep) {
|
||||||
index++;
|
index++;
|
||||||
@ -749,7 +774,7 @@ char *script;
|
|||||||
}
|
}
|
||||||
namep++;
|
namep++;
|
||||||
index++;
|
index++;
|
||||||
if (index>255) {
|
if (index > MAXVNSIZ) {
|
||||||
free(glob_script_mem.script_mem);
|
free(glob_script_mem.script_mem);
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
@ -760,7 +785,7 @@ 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;
|
||||||
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;
|
||||||
cp1 += glob_script_mem.max_ssize;
|
cp1 += glob_script_mem.max_ssize;
|
||||||
@ -875,19 +900,81 @@ char *script;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_SCRIPT_FATFS
|
||||||
|
uint32_t get_fsinfo(uint32_t sel) {
|
||||||
|
uint32_t result = 0;
|
||||||
|
#ifdef ESP32
|
||||||
|
#if USE_SCRIPT_FATFS >=0
|
||||||
|
if (sel == 0) {
|
||||||
|
result = SD.totalBytes()/1000;
|
||||||
|
} else if (sel == 1) {
|
||||||
|
result = (SD.totalBytes() - SD.usedBytes())/1000;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (sel == 0) {
|
||||||
|
result = FFat.totalBytes()/1000;
|
||||||
|
} else if (sel == 1) {
|
||||||
|
result = FFat.freeBytes()/1000;
|
||||||
|
}
|
||||||
|
#endif // USE_SCRIPT_FATFS>=0
|
||||||
|
#else
|
||||||
|
// ESP8266
|
||||||
|
FSInfo64 fsinfo;
|
||||||
|
fsp->info64(fsinfo);
|
||||||
|
if (sel == 0) {
|
||||||
|
result = fsinfo.totalBytes/1000;
|
||||||
|
} else if (sel == 1) {
|
||||||
|
result = (fsinfo.totalBytes - fsinfo.usedBytes)/1000;
|
||||||
|
}
|
||||||
|
#endif // ESP32
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// format number with thousand marker
|
||||||
|
void form1000(uint32_t number, char *dp, char sc) {
|
||||||
|
char str[32];
|
||||||
|
sprintf(str, "%d", number);
|
||||||
|
char *sp = str;
|
||||||
|
uint32_t inum = strlen(sp)/3;
|
||||||
|
uint32_t fnum = strlen(sp)%3;
|
||||||
|
if (!fnum) inum--;
|
||||||
|
for (uint32_t count=0; count<=inum; count++) {
|
||||||
|
if (fnum){
|
||||||
|
memcpy(dp,sp,fnum);
|
||||||
|
dp+=fnum;
|
||||||
|
sp+=fnum;
|
||||||
|
fnum=0;
|
||||||
|
} else {
|
||||||
|
memcpy(dp,sp,3);
|
||||||
|
dp+=3;
|
||||||
|
sp+=3;
|
||||||
|
}
|
||||||
|
if (count!=inum) {
|
||||||
|
*dp++=sc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dp=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //USE_SCRIPT_FATFS
|
||||||
|
|
||||||
#ifdef USE_SCRIPT_GLOBVARS
|
#ifdef USE_SCRIPT_GLOBVARS
|
||||||
#define SCRIPT_UDP_BUFFER_SIZE 128
|
#define SCRIPT_UDP_BUFFER_SIZE 128
|
||||||
#define SCRIPT_UDP_PORT 1999
|
#define SCRIPT_UDP_PORT 1999
|
||||||
IPAddress script_udp_remote_ip;
|
IPAddress script_udp_remote_ip;
|
||||||
|
|
||||||
void Script_Stop_UDP(void) {
|
void Script_Stop_UDP(void) {
|
||||||
Script_PortUdp.flush();
|
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||||
Script_PortUdp.stop();
|
if (glob_script_mem.udp_flags.udp_connected) {
|
||||||
glob_script_mem.udp_flags.udp_connected = 0;
|
Script_PortUdp.flush();
|
||||||
|
Script_PortUdp.stop();
|
||||||
|
glob_script_mem.udp_flags.udp_connected = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Script_Init_UDP() {
|
void Script_Init_UDP() {
|
||||||
if (global_state.network_down) return;
|
if (global_state.network_down) return;
|
||||||
|
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||||
if (glob_script_mem.udp_flags.udp_connected) return;
|
if (glob_script_mem.udp_flags.udp_connected) return;
|
||||||
|
|
||||||
if (Script_PortUdp.beginMulticast(WiFi.localIP(), IPAddress(239,255,255,250), SCRIPT_UDP_PORT)) {
|
if (Script_PortUdp.beginMulticast(WiFi.localIP(), IPAddress(239,255,255,250), SCRIPT_UDP_PORT)) {
|
||||||
@ -898,6 +985,7 @@ void Script_Init_UDP() {
|
|||||||
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 (global_state.network_down) return;
|
if (global_state.network_down) return;
|
||||||
if (!glob_script_mem.udp_flags.udp_used) return;
|
if (!glob_script_mem.udp_flags.udp_used) return;
|
||||||
@ -1546,11 +1634,18 @@ chknext:
|
|||||||
case 'a':
|
case 'a':
|
||||||
#ifdef USE_ANGLE_FUNC
|
#ifdef USE_ANGLE_FUNC
|
||||||
if (!strncmp(vname, "acos(", 5)) {
|
if (!strncmp(vname, "acos(", 5)) {
|
||||||
lp=GetNumericArgument(lp + 5, OPER_EQU, &fvar, 0);
|
lp=GetNumericArgument(lp + 5, OPER_EQU, &fvar, 0);
|
||||||
fvar = acosf(fvar);
|
fvar = acosf(fvar);
|
||||||
lp++;
|
lp++;
|
||||||
len = 0;
|
len = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
}
|
||||||
|
if (!strncmp(vname, "abs(", 4)) {
|
||||||
|
lp=GetNumericArgument(lp + 4, OPER_EQU, &fvar, 0);
|
||||||
|
fvar = fabs(fvar);
|
||||||
|
lp++;
|
||||||
|
len = 0;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!strncmp(vname, "asc(", 4)) {
|
if (!strncmp(vname, "asc(", 4)) {
|
||||||
@ -1982,6 +2077,14 @@ chknext:
|
|||||||
len = 0;
|
len = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strncmp(vname, "fsi(", 4)) {
|
||||||
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, 0);
|
||||||
|
fvar = get_fsinfo(fvar);
|
||||||
|
lp++;
|
||||||
|
len = 0;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
#endif // USE_SCRIPT_FATFS_EXT
|
#endif // USE_SCRIPT_FATFS_EXT
|
||||||
if (!strncmp(vname, "fl1(", 4) || !strncmp(vname, "fl2(", 4) ) {
|
if (!strncmp(vname, "fl1(", 4) || !strncmp(vname, "fl2(", 4) ) {
|
||||||
uint8_t lknum = *(lp+2)&3;
|
uint8_t lknum = *(lp+2)&3;
|
||||||
@ -4358,8 +4461,8 @@ const char HTTP_FORM_FILE_UPLOAD[] PROGMEM =
|
|||||||
"<div id='f1' name='f1' style='display:block;'>"
|
"<div id='f1' name='f1' style='display:block;'>"
|
||||||
"<fieldset><legend><b> %s" " </b></legend>";
|
"<fieldset><legend><b> %s" " </b></legend>";
|
||||||
const char HTTP_FORM_FILE_UPG[] PROGMEM =
|
const char HTTP_FORM_FILE_UPG[] PROGMEM =
|
||||||
"<form method='post' action='u3' enctype='multipart/form-data'>"
|
"<form method='post' action='u13' enctype='multipart/form-data'>"
|
||||||
"<br/><input type='file' name='u3'><br/>"
|
"<br/><input type='file' name='u13'><br/>"
|
||||||
"<br/><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>" D_START " %s</button></form>";
|
"<br/><button type='submit' onclick='eb(\"f1\").style.display=\"none\";eb(\"f2\").style.display=\"block\";this.form.submit();'>" D_START " %s</button></form>";
|
||||||
|
|
||||||
const char HTTP_FORM_FILE_UPGb[] PROGMEM =
|
const char HTTP_FORM_FILE_UPGb[] PROGMEM =
|
||||||
@ -4367,6 +4470,9 @@ const char HTTP_FORM_FILE_UPGb[] PROGMEM =
|
|||||||
"</div>"
|
"</div>"
|
||||||
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>" D_UPLOAD_STARTED " ...</b></div>";
|
"<div id='f2' name='f2' style='display:none;text-align:center;'><b>" D_UPLOAD_STARTED " ...</b></div>";
|
||||||
|
|
||||||
|
const char HTTP_FORM_FILE_UPGc[] PROGMEM =
|
||||||
|
"<div style='text-align:left;color:green;'>total size: %s kB - free: %s kB</div>";
|
||||||
|
|
||||||
const char HTTP_FORM_SDC_DIRa[] PROGMEM =
|
const char HTTP_FORM_SDC_DIRa[] PROGMEM =
|
||||||
"<div style='text-align:left'>";
|
"<div style='text-align:left'>";
|
||||||
const char HTTP_FORM_SDC_DIRb[] PROGMEM =
|
const char HTTP_FORM_SDC_DIRb[] PROGMEM =
|
||||||
@ -4573,6 +4679,11 @@ void Script_FileUploadConfiguration(void) {
|
|||||||
WSContentSend_P(HTTP_FORM_FILE_UPLOAD,D_SDCARD_DIR);
|
WSContentSend_P(HTTP_FORM_FILE_UPLOAD,D_SDCARD_DIR);
|
||||||
WSContentSend_P(HTTP_FORM_FILE_UPG, D_SCRIPT_UPLOAD);
|
WSContentSend_P(HTTP_FORM_FILE_UPG, D_SCRIPT_UPLOAD);
|
||||||
#ifdef SDCARD_DIR
|
#ifdef SDCARD_DIR
|
||||||
|
char ts[16];
|
||||||
|
char fs[16];
|
||||||
|
form1000(get_fsinfo(0), ts, '.');
|
||||||
|
form1000(get_fsinfo(1), fs, '.');
|
||||||
|
WSContentSend_P(HTTP_FORM_FILE_UPGc, ts, fs);
|
||||||
WSContentSend_P(HTTP_FORM_SDC_DIRa);
|
WSContentSend_P(HTTP_FORM_SDC_DIRa);
|
||||||
if (glob_script_mem.script_sd_found) {
|
if (glob_script_mem.script_sd_found) {
|
||||||
ListDir(path, depth);
|
ListDir(path, depth);
|
||||||
@ -4837,6 +4948,11 @@ void ScriptSaveSettings(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SaveScriptEnd(void) {
|
void SaveScriptEnd(void) {
|
||||||
|
|
||||||
|
#ifdef USE_SCRIPT_GLOBVARS
|
||||||
|
Script_Stop_UDP();
|
||||||
|
#endif //USE_SCRIPT_GLOBVARS
|
||||||
|
|
||||||
if (glob_script_mem.script_mem) {
|
if (glob_script_mem.script_mem) {
|
||||||
Scripter_save_pvars();
|
Scripter_save_pvars();
|
||||||
free(glob_script_mem.script_mem);
|
free(glob_script_mem.script_mem);
|
||||||
@ -4856,6 +4972,9 @@ void SaveScriptEnd(void) {
|
|||||||
#endif // USE_SCRIPT_COMPRESSION
|
#endif // USE_SCRIPT_COMPRESSION
|
||||||
|
|
||||||
if (bitRead(Settings.rule_enabled, 0)) {
|
if (bitRead(Settings.rule_enabled, 0)) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int16_t res = Init_Scripter();
|
int16_t res = Init_Scripter();
|
||||||
if (res) {
|
if (res) {
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("script init error: %d"), res);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("script init error: %d"), res);
|
||||||
@ -7110,8 +7229,8 @@ bool Xdrv10(uint8_t function)
|
|||||||
Webserver->on("/exs", HTTP_GET, ScriptExecuteUploadSuccess);
|
Webserver->on("/exs", HTTP_GET, ScriptExecuteUploadSuccess);
|
||||||
|
|
||||||
#ifdef USE_SCRIPT_FATFS
|
#ifdef USE_SCRIPT_FATFS
|
||||||
Webserver->on("/u3", HTTP_POST,[]() { Webserver->sendHeader("Location","/u3");Webserver->send(303);}, script_upload);
|
Webserver->on("/u13", HTTP_POST,[]() { Webserver->sendHeader("Location","/u13");Webserver->send(303);}, script_upload);
|
||||||
Webserver->on("/u3", HTTP_GET, ScriptFileUploadSuccess);
|
Webserver->on("/u13", HTTP_GET, ScriptFileUploadSuccess);
|
||||||
Webserver->on("/upl", HTTP_GET, Script_FileUploadConfiguration);
|
Webserver->on("/upl", HTTP_GET, Script_FileUploadConfiguration);
|
||||||
#endif //USE_SCRIPT_FATFS
|
#endif //USE_SCRIPT_FATFS
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user