From 8034b19b2ea2250e94c31aeecffda10c9edfaf0c Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Fri, 9 Sep 2022 08:14:42 +0200 Subject: [PATCH] WSContentSend_P fix --- .../tasmota_xdrv_driver/xdrv_10_scripter.ino | 242 ++++++++++++------ 1 file changed, 159 insertions(+), 83 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino index 3c05b0afd..7ccba2c07 100755 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino @@ -137,6 +137,10 @@ int32_t web_send_file(char mc, char *file); #define STASK_PRIO 1 #endif +#ifdef ESP32 +#include +#endif + #ifdef USE_SCRIPT_TIMER #include Ticker Script_ticker1; @@ -1042,10 +1046,14 @@ char *script; int32_t udp_call(char *url, uint32_t port, char *sbuf) { WiFiUDP udp; - IPAddress adr = adr.fromString(url); + IPAddress adr; + adr.fromString(url); + udp.begin(port); udp.beginPacket(adr, port); udp.write((const uint8_t*)sbuf, strlen(sbuf)); udp.endPacket(); + udp.flush(); + udp.stop(); return 0; } @@ -1225,16 +1233,16 @@ float median_array(float *array, uint16_t len) { uint8_t flg; float min = FLT_MAX; - for (uint8_t hcnt = 0; hcntnumvals & AND_FILT_MASK; if (ipos) *ipos = mflp->index; return mflp->rbuff; @@ -1270,10 +1278,9 @@ char *get_array_by_name(char *lp, float **fp, uint16_t *alen, uint16_t *ipos) { uint8_t vtype; while (*lp == ' ') lp++; lp = isvar(lp, &vtype, &ind, 0, 0, 0); - if (vtype==VAR_NV) return 0; - if (vtype&STYPE) return 0; + if (vtype == VAR_NV) return 0; + if (vtype & STYPE) return 0; uint16_t index = glob_script_mem.type[ind.index].index; - if (glob_script_mem.type[ind.index].bits.is_filter) { float *fa = Get_MFAddr(index, alen, ipos); *fp = fa; @@ -1287,8 +1294,8 @@ float *get_array_by_name(char *name, uint16_t *alen) { struct T_INDEX ind; uint8_t vtype; isvar(name, &vtype, &ind, 0, 0, 0); - if (vtype==VAR_NV) return 0; - if (vtype&STYPE) return 0; + if (vtype == VAR_NV) return 0; + if (vtype & STYPE) return 0; uint16_t index = glob_script_mem.type[ind.index].index; if (glob_script_mem.type[ind.index].bits.is_filter) { @@ -1763,7 +1770,16 @@ uint32_t res = 0; } - +uint8_t script_hexnibble(char chr) { + uint8_t rVal = 0; + if (isdigit(chr)) { + rVal = chr - '0'; + } else { + if (chr >= 'A' && chr <= 'F') rVal = chr + 10 - 'A'; + if (chr >= 'a' && chr <= 'f') rVal = chr + 10 - 'a'; + } + return rVal; +} #ifdef USE_LIGHT uint32_t HSVToRGB(uint16_t hue, uint8_t saturation, uint8_t value) { @@ -2527,6 +2543,18 @@ chknext: tind->index = SCRIPT_CBSIZE; goto exit_settable; } +#ifdef USE_W8960 +extern void W8960_SetGain(uint8_t sel, uint16_t value); + + if (!strncmp(lp, "codec(", 6)) { + float sel; + lp = GetNumericArgument(lp + 6, OPER_EQU, &sel, gv); + lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); + W8960_SetGain(sel, fvar); + fvar = 0; + goto nfuncexit; + } +#endif break; case 'd': if (!strncmp(vname, "day", 3)) { @@ -3380,7 +3408,23 @@ chknext: goto nfuncexit; } #endif + if (!strncmp(lp, "hstr(", 5)) { + char hstr[SCRIPT_MAXSSIZE]; + lp = GetStringArgument(lp + 5, OPER_EQU, hstr, 0); + uint16_t cnt; + uint16_t slen = strlen(hstr); + slen &= 0xfffe; + for (cnt = 0; cnt < slen; cnt += 2) { + hstr[cnt / 2] = (script_hexnibble(hstr[cnt]) << 4) | script_hexnibble(hstr[cnt + 1] ); + } + hstr[cnt / 2 + 1] = 0; + if (sp) strlcpy(sp, hstr, strlen(hstr)); + len = 0; + lp++; + goto strexit; + } break; + case 'i': if (!strncmp(lp, "ins(", 4)) { char s1[SCRIPT_MAXSSIZE]; @@ -3478,6 +3522,34 @@ chknext: goto nfuncexit; } #endif // USE_SCRIPT_I2C + +#ifdef ESP32 +#ifdef USE_I2S_AUDIO + if (!strncmp(lp, "i2sw(", 5)) { + float port; + lp = GetNumericArgument(lp + 5, OPER_EQU, &port, gv); + uint16_t alen = 0; + float *fa = 0; + lp = get_array_by_name(lp, &fa, &alen, 0); + if (!fa) { + fvar = -1; + goto nfuncexit; + } + lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv); + uint32_t bytes_written; + int16_t *wp = (int16_t*)special_malloc(alen * 2); + if (wp) { + for (uint16_t cnt = 0; cnt < alen; cnt++) { + wp[cnt] = fa[cnt]; + } + i2s_write((i2s_port_t)port, (const uint8_t*)wp, fvar, &bytes_written, 0); + free(wp); + fvar = bytes_written; + } + goto nfuncexit; + } +#endif // USE_I2S_AUDIO +#endif // ESP32 break; #ifdef USE_KNX @@ -3834,7 +3906,6 @@ chknext: #endif */ -#ifdef ESP32 if (!strncmp(lp, "rr(", 3)) { lp+=4; len = 0; @@ -3848,7 +3919,6 @@ chknext: } goto strexit; } -#endif break; case 's': @@ -4625,6 +4695,7 @@ extern char *SML_GetSVal(uint32_t index); script_sspi_trans(index, fpd, len, fvar); break; } + lp++; len = 0; goto exit; } @@ -8284,6 +8355,11 @@ String ScriptUnsubscribe(const char * data, int data_len) #if defined(ESP32) && defined(USE_UFILESYS) && defined(USE_SCRIPT_ALT_DOWNLOAD) + +#ifndef SCRIPT_DLPORT +#define SCRIPT_DLPORT 82 +#endif + ESP8266WebServer *http82_Server; bool download82_busy; @@ -8343,15 +8419,15 @@ void WebServer82Init(void) { if (http82_Server != nullptr) { return; } - http82_Server = new ESP8266WebServer(82); + http82_Server = new ESP8266WebServer(SCRIPT_DLPORT); if (http82_Server != nullptr) { http82_Server->on(UriGlob("/ufs/*"), HTTP_GET, ScriptServeFile82); http82_Server->on("/", HTTP_GET, Handle82Root); http82_Server->onNotFound(Handle82NotFound); http82_Server->begin(); - AddLog(LOG_LEVEL_INFO, PSTR("HTTP Server 82 started")); + AddLog(LOG_LEVEL_INFO, PSTR("HTTP DL Server started on port: %d "), SCRIPT_DLPORT); } else { - AddLog(LOG_LEVEL_INFO, PSTR("HTTP Server 82 failed")); + AddLog(LOG_LEVEL_INFO, PSTR("HTTP DL Server failed")); } } @@ -8954,16 +9030,16 @@ uint16_t cipos = 0; } char *gc_send_labels(char *lp,uint32_t anum) { - WSContentSend_PD("["); + WSContentSend_P("["); for (uint32_t cnt = 0; cnt < anum + 1; cnt++) { char label[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp, OPER_EQU, label, 0); SCRIPT_SKIP_SPACES - WSContentSend_PD(SCRIPT_MSG_GTE1, label); + WSContentSend_P(SCRIPT_MSG_GTE1, label); //Serial.printf("labels %s\n",label); - if (cnt1) proz -= 2; - if (optflg) WSContentSend_PD(SCRIPT_MSG_BUT_START_TBL); - else WSContentSend_PD(SCRIPT_MSG_BUT_START); + if (optflg) WSContentSend_P(SCRIPT_MSG_BUT_START_TBL); + else WSContentSend_P(SCRIPT_MSG_BUT_START); for (uint32_t cnt = 0; cnt < bcnt; cnt++) { float val; char *slp = lp; @@ -9378,17 +9454,17 @@ const char *gc_str; if (!optflg) proz += 2; } if (!optflg) { - WSContentSend_PD(SCRIPT_MSG_BUTTONa, proz, uval, vname, cp); + WSContentSend_P(SCRIPT_MSG_BUTTONa, proz, uval, vname, cp); } else { - WSContentSend_PD(SCRIPT_MSG_BUTTONa_TBL, proz, uval, vname, cp); + WSContentSend_P(SCRIPT_MSG_BUTTONa_TBL, proz, uval, vname, cp); } if (bcnt > 1 && cnt < bcnt - 1) { - if (!optflg) WSContentSend_PD(SCRIPT_MSG_BUTTONb, 2); + if (!optflg) WSContentSend_P(SCRIPT_MSG_BUTTONb, 2); } lp += 4; } - if (optflg) WSContentSend_PD(SCRIPT_MSG_BUT_STOP_TBL); - else WSContentSend_PD(SCRIPT_MSG_BUT_STOP); + if (optflg) WSContentSend_P(SCRIPT_MSG_BUT_STOP_TBL); + else WSContentSend_P(SCRIPT_MSG_BUT_STOP); } else if (!strncmp(lin, "tm(", 3)) { // time only HH:MM @@ -9418,7 +9494,7 @@ const char *gc_str; const char *max = PSTR("23:59"); const char *styp = PSTR("sivat"); WCS_DIV(specopt); - WSContentSend_PD(SCRIPT_MSG_TEXTINP_U, center, label, type, vstr, min, max, tsiz, styp, vname); + WSContentSend_P(SCRIPT_MSG_TEXTINP_U, center, label, type, vstr, min, max, tsiz, styp, vname); WCS_DIV(specopt | WSO_STOP_DIV); } else if (!strncmp(lin, "tx(", 3)) { // text @@ -9459,16 +9535,16 @@ const char *gc_str; SCRIPT_SKIP_SPACES WCS_DIV(specopt); const char *styp = PSTR("siva"); - WSContentSend_PD(SCRIPT_MSG_TEXTINP_U, center, label, type, str, min, max, tsiz, styp, vname); + WSContentSend_P(SCRIPT_MSG_TEXTINP_U, center, label, type, str, min, max, tsiz, styp, vname); WCS_DIV(specopt | WSO_STOP_DIV); } else { WCS_DIV(specopt); - WSContentSend_PD(SCRIPT_MSG_TEXTINP, center, label, str, tsiz, vname); + WSContentSend_P(SCRIPT_MSG_TEXTINP, center, label, str, tsiz, vname); WCS_DIV(specopt | WSO_STOP_DIV); } } else { WCS_DIV(specopt); - WSContentSend_PD(SCRIPT_MSG_TEXTINP, center, label, str, tsiz, vname); + WSContentSend_P(SCRIPT_MSG_TEXTINP, center, label, str, tsiz, vname); WCS_DIV(specopt | WSO_STOP_DIV); } lp++; @@ -9514,18 +9590,18 @@ const char *gc_str; dtostrfd(max, dprec, maxstr); dtostrfd(step, dprec, stepstr); WCS_DIV(specopt); - WSContentSend_PD(SCRIPT_MSG_NUMINP, center, label, minstr, maxstr, stepstr, vstr, tsiz, vname); + WSContentSend_P(SCRIPT_MSG_NUMINP, center, label, minstr, maxstr, stepstr, vstr, tsiz, vname); WCS_DIV(specopt | WSO_STOP_DIV); lp++; } else { if (mc == 'w' || (specopt & WSO_FORCEPLAIN)) { - WSContentSend_PD(PSTR("%s"), lin); + WSContentSend_P(PSTR("%s"), lin); } else { if (optflg) { - WSContentSend_PD(PSTR("
%s
"), lin); + WSContentSend_P(PSTR("
%s
"), lin); } else { - WSContentSend_PD(PSTR("{s}%s{e}"), lin); + WSContentSend_P(PSTR("{s}%s{e}"), lin); } } } @@ -9551,7 +9627,7 @@ exgc: uint16_t len = (uint32_t)cp - (uint32_t)lin; strncpy(valstr, lin, len); valstr[len] = 0; - WSContentSend_PD(PSTR("%s"), valstr); + WSContentSend_P(PSTR("%s"), valstr); float *fpd = 0; uint16_t alend; uint16_t ipos; @@ -9576,14 +9652,14 @@ exgc: ipos = 0; } if (cnt == 0) { - WSContentSend_PD(PSTR("%s"), valstr); + WSContentSend_P(PSTR("%s"), valstr); } else { - WSContentSend_PD(PSTR(",%s"), valstr); + WSContentSend_P(PSTR(",%s"), valstr); } } } lp++; - WSContentSend_PD(PSTR("%s"), lp); + WSContentSend_P(PSTR("%s"), lp); return lp; } @@ -9594,11 +9670,11 @@ exgc: uint16_t len = (uint32_t)cp - (uint32_t)lin; strncpy(valstr, lin, len); valstr[len] = 0; - WSContentSend_PD(PSTR("%s"), valstr); + WSContentSend_P(PSTR("%s"), valstr); scripter_sub(cp , 0); cp = strchr(cp, ')'); if (cp) { - WSContentSend_PD(PSTR("%s"), cp + 1); + WSContentSend_P(PSTR("%s"), cp + 1); } return lp; } @@ -9620,7 +9696,7 @@ exgc: lp++; if (!(google_libs & GLIBS_MAIN)) { google_libs |= GLIBS_MAIN; - WSContentSend_PD(SCRIPT_MSG_GTABLE); + WSContentSend_P(SCRIPT_MSG_GTABLE); } gc_str = GC_type(gs_ctype); @@ -9629,24 +9705,24 @@ exgc: case 'g': if (!(google_libs & GLIBS_GAUGE)) { google_libs |= GLIBS_GAUGE; - WSContentSend_PD(SCRIPT_MSG_GAUGE); + WSContentSend_P(SCRIPT_MSG_GAUGE); } break; case 't': if (!(google_libs & GLIBS_TABLE)) { google_libs |= GLIBS_TABLE; - WSContentSend_PD(SCRIPT_MSG_TABLE); + WSContentSend_P(SCRIPT_MSG_TABLE); } break; case 'T': if (!(google_libs & GLIBS_TIMELINE)) { google_libs |= GLIBS_TIMELINE; - WSContentSend_PD(SCRIPT_MSG_TIMELINE); + WSContentSend_P(SCRIPT_MSG_TIMELINE); } break; } if (type == 'e') { - WSContentSend_PD(SCRIPT_MSG_GTABLEbx, gc_str, chartindex); + WSContentSend_P(SCRIPT_MSG_GTABLEbx, gc_str, chartindex); chartindex++; return lp1; } @@ -9716,7 +9792,7 @@ exgc: //Serial.printf("entries %d\n",entries); if (gs_ctype=='T') { if (anum && !(entries & 1)) { - WSContentSend_PD(SCRIPT_MSG_GTABLEa); + WSContentSend_P(SCRIPT_MSG_GTABLEa); char label[SCRIPT_MAXSSIZE]; lp = GetStringArgument(lp, OPER_EQU, label, 0); SCRIPT_SKIP_SPACES @@ -9724,9 +9800,9 @@ exgc: lab2[0] = 0; if (*lp!=')') { lp = GetStringArgument(lp, OPER_EQU, lab2, 0); - WSContentSend_PD(SCRIPT_MSG_GTABLEe); + WSContentSend_P(SCRIPT_MSG_GTABLEe); } else { - WSContentSend_PD(SCRIPT_MSG_GTABLEd); + WSContentSend_P(SCRIPT_MSG_GTABLEd); } for (uint32_t ind = 0; ind < anum; ind++) { @@ -9747,34 +9823,34 @@ exgc: } for (uint32_t cnt = 0; cnt < ventries; cnt += 2) { - WSContentSend_PD("['%s',",lbl); + WSContentSend_P("['%s',",lbl); if (lab2[0]) { - WSContentSend_PD("'%s',",lbl2); + WSContentSend_P("'%s',",lbl2); } uint32_t time = fp[cnt]; - WSContentSend_PD(SCRIPT_MSG_GOPT5, time / 60, time % 60); - WSContentSend_PD(","); + WSContentSend_P(SCRIPT_MSG_GOPT5, time / 60, time % 60); + WSContentSend_P(","); time = fp[cnt + 1]; - WSContentSend_PD(SCRIPT_MSG_GOPT5, time / 60, time % 60); - WSContentSend_PD("]"); - if (cnt < ventries - 2) { WSContentSend_PD(","); } + WSContentSend_P(SCRIPT_MSG_GOPT5, time / 60, time % 60); + WSContentSend_P("]"); + if (cnt < ventries - 2) { WSContentSend_P(","); } } if (ind < anum - 1) { if (ventries) { - WSContentSend_PD(","); + WSContentSend_P(","); } } } snprintf_P(options,sizeof(options), SCRIPT_MSG_GOPT4); } if (tonly) { - WSContentSend_PD("]);"); + WSContentSend_P("]);"); return lp1; //goto nextwebline; } } else { // we need to fetch the labels now - WSContentSend_PD(SCRIPT_MSG_GTABLEa); + WSContentSend_P(SCRIPT_MSG_GTABLEa); lp = gc_send_labels(lp, anum); // now we have to export the values @@ -9828,7 +9904,7 @@ exgc: uint32_t aind = ipos; if (aind >= entries) aind = entries - 1; for (uint32_t cnt = 0; cnt < entries; cnt++) { - WSContentSend_PD("['"); + WSContentSend_P("['"); char lbl[16]; if (todflg >= 0) { uint16_t mins = (float)(todflg % divflg) * (float)((float)60 / (float)divflg); @@ -9856,8 +9932,8 @@ exgc: sprintf(lbl, "%s-%02d", lbl, aind % divflg); } } - WSContentSend_PD(lbl); - WSContentSend_PD("',"); + WSContentSend_P(lbl); + WSContentSend_P("',"); for (uint32_t ind = 0; ind < anum; ind++) { char acbuff[32]; float *fp = arrays[ind]; @@ -9868,11 +9944,11 @@ exgc: fval = fp[cnt]; } f2char(fval, glob_script_mem.script_dprec, glob_script_mem.script_lzero, acbuff); - WSContentSend_PD("%s", acbuff); - if (ind < anum - 1) { WSContentSend_PD(","); } + WSContentSend_P("%s", acbuff); + if (ind < anum - 1) { WSContentSend_P(","); } } - WSContentSend_PD("]"); - if (cnt < entries - 1) { WSContentSend_PD(","); } + WSContentSend_P("]"); + if (cnt < entries - 1) { WSContentSend_P(","); } aind++; if (aind >= entries) { aind = 0; @@ -9880,7 +9956,7 @@ exgc: } // table complete if (tonly) { - WSContentSend_PD("]);"); + WSContentSend_P("]);"); return lp1; //goto nextwebline; } @@ -9949,19 +10025,19 @@ exgc: (uint32_t)yellowFrom, (uint32_t)yellowTo); } } - WSContentSend_PD(SCRIPT_MSG_GTABLEb, options); - WSContentSend_PD(SCRIPT_MSG_GTABLEbx, gc_str, chartindex); + WSContentSend_P(SCRIPT_MSG_GTABLEb, options); + WSContentSend_P(SCRIPT_MSG_GTABLEbx, gc_str, chartindex); chartindex++; } else { - WSContentSend_PD(PSTR("%s"), lin); + WSContentSend_P(PSTR("%s"), lin); } #else if (!(specopt&WSO_FORCEMAIN)) { lin++; } - WSContentSend_PD(PSTR("%s"), lin); + WSContentSend_P(PSTR("%s"), lin); } else { - // WSContentSend_PD(PSTR("%s"),lin); + // WSContentSend_P(PSTR("%s"),lin); #endif //USE_GOOGLE_CHARTS } } @@ -10954,7 +11030,7 @@ void script_add_subpage(uint8_t num) { } sprintf_P(id, PSTR("/sfd%1d"), num); Webserver->on(id, wptr); - WSContentSend_PD(HTTP_WEB_FULL_DISPLAY, num, bname); + WSContentSend_P(HTTP_WEB_FULL_DISPLAY, num, bname); } } #endif // SCRIPT_FULL_WEBPAGE