From edaf6c493e303f64670357ddfcd7e6e78f0b40d5 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Thu, 21 May 2020 06:06:42 +0200 Subject: [PATCH 1/2] fix scripter unishox error, add 2 y axes line graph to google charts --- tasmota/xdrv_10_scripter.ino | 54 +++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 8c2dcbc4f..895049a21 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -52,7 +52,9 @@ keywords if then else endif, or, and are better readable for beginners (others m #endif #define MAXNVARS MAXVARS-MAXSVARS +#ifndef MAXFILT #define MAXFILT 5 +#endif #define SCRIPT_SVARSIZE 20 #define SCRIPT_MAXSSIZE 48 #define SCRIPT_EOL '\n' @@ -66,8 +68,17 @@ keywords if then else endif, or, and are better readable for beginners (others m uint32_t EncodeLightId(uint8_t relay_id); uint32_t DecodeLightId(uint32_t hue_id); +#ifdef USE_RULES_COMPRESSION #include +Unishox compressor; // singleton +#define SCRIPT_COMPRESS compressor.unishox_compress +#define SCRIPT_DECOMPRESS compressor.unishox_decompress +#ifndef UNISHOXRSIZE +#define UNISHOXRSIZE 2560 +#endif +#endif + #if defined(ESP32) && defined(ESP32_SCRIPT_SIZE) && !defined(USE_24C256) && !defined(USE_SCRIPT_FATFS) #include "FS.h" #include "SPIFFS.h" @@ -3966,20 +3977,20 @@ void ScriptSaveSettings(void) { glob_script_mem.script_mem_size=0; } - -#ifndef UNISHOXRSIZE -#define UNISHOXRSIZE 2560 -#endif #ifdef USE_RULES_COMPRESSION #ifndef USE_24C256 #ifndef USE_SCRIPT_FATFS #ifndef ESP32_SCRIPT_SIZE - uint32_t len_compressed = unishox_compress(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram), Settings.rules[0], UNISHOXRSIZE); + + //AddLog_P2(LOG_LEVEL_INFO,PSTR("in string: %s len = %d"),glob_script_mem.script_ram,strlen(glob_script_mem.script_ram)); + uint32_t len_compressed = SCRIPT_COMPRESS(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram)+1, Settings.rules[0], MAX_SCRIPT_SIZE-1); + Settings.rules[0][len_compressed] = 0; if (len_compressed > 0) { - AddLog_P2(LOG_LEVEL_INFO,PSTR("compressed to %d"),len_compressed * 100 / strlen(glob_script_mem.script_ram)); + AddLog_P2(LOG_LEVEL_INFO,PSTR("script compressed to %d %%"),len_compressed * 100 / strlen(glob_script_mem.script_ram)); } else { AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed); } + #endif #endif #endif @@ -4912,6 +4923,10 @@ const char SCRIPT_MSG_GTABLEb[] PROGMEM = const char SCRIPT_MSG_GOPT1[] PROGMEM = "title:'%s',isStacked:false"; +const char SCRIPT_MSG_GOPT3[] PROGMEM = +"title:'%s',vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}"; + + const char SCRIPT_MSG_GOPT2[] PROGMEM = "showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc"; @@ -5223,14 +5238,27 @@ void ScriptWebShow(char mc) { lp=GetStringResult(lp,OPER_EQU,header,0); SCRIPT_SKIP_SPACES - char options[128]; + char options[256]; snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT1,header); + //uint32_t slen=sizeof(SCRIPT_MSG_GOPT1)+strlen(header); const char *type; if (*lp!=')') { switch (*lp) { case 'l': type=PSTR("LineChart"); + if (*(lp+1)=='2') { + // 2 y axes variant + lp+=2; + SCRIPT_SKIP_SPACES + float max1; + lp=GetNumericResult(lp,OPER_EQU,&max1,0); + SCRIPT_SKIP_SPACES + float max2; + lp=GetNumericResult(lp,OPER_EQU,&max2,0); + SCRIPT_SKIP_SPACES + snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT3,header,(uint32_t)max1,(uint32_t)max2); + } break; case 'b': type=PSTR("BarChart"); @@ -5255,6 +5283,7 @@ void ScriptWebShow(char mc) { } else { type=PSTR("ColumnChart"); } + lp++; WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex); chartindex++; @@ -5423,6 +5452,7 @@ uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core) { bool Xdrv10(uint8_t function) { bool result = false; + char *sprt; switch (function) { case FUNC_PRE_INIT: @@ -5438,10 +5468,14 @@ bool Xdrv10(uint8_t function) #ifndef USE_24C256 #ifndef USE_SCRIPT_FATFS #ifndef ESP32_SCRIPT_SIZE - glob_script_mem.script_ram=(char*)calloc(UNISHOXRSIZE+8,1); - if (!glob_script_mem.script_ram) { break; } - unishox_decompress(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, UNISHOXRSIZE); + int32_t len_decompressed; + sprt=(char*)calloc(UNISHOXRSIZE+8,1); + if (!sprt) { break; } + glob_script_mem.script_ram=sprt; glob_script_mem.script_size=UNISHOXRSIZE; + len_decompressed = SCRIPT_DECOMPRESS(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, glob_script_mem.script_size); + glob_script_mem.script_ram[len_decompressed]=0; + //AddLog_P2(LOG_LEVEL_INFO, PSTR("decompressed script len %d"),len_decompressed); #endif #endif #endif From fca5dc9471c25fdc29512be8150c52ba7eb9d683 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Thu, 21 May 2020 08:13:26 +0200 Subject: [PATCH 2/2] Update xdrv_10_scripter.ino --- tasmota/xdrv_10_scripter.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 895049a21..eb0d00f29 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -68,7 +68,7 @@ keywords if then else endif, or, and are better readable for beginners (others m uint32_t EncodeLightId(uint8_t relay_id); uint32_t DecodeLightId(uint32_t hue_id); -#ifdef USE_RULES_COMPRESSION +#ifdef USE_SCRIPT_COMPRESSION #include Unishox compressor; // singleton @@ -77,7 +77,7 @@ Unishox compressor; // singleton #ifndef UNISHOXRSIZE #define UNISHOXRSIZE 2560 #endif -#endif +#endif // USE_SCRIPT_COMPRESSION #if defined(ESP32) && defined(ESP32_SCRIPT_SIZE) && !defined(USE_24C256) && !defined(USE_SCRIPT_FATFS) #include "FS.h" @@ -1768,7 +1768,7 @@ chknext: lp=GetNumericResult(lp,OPER_EQU,&fvar2,0); lp++; //fvar=pow(fvar1,fvar2); - fvar=FastPrecisePow(fvar1,fvar2); + fvar=FastPrecisePowf(fvar1,fvar2); len=0; goto exit; } @@ -3977,7 +3977,7 @@ void ScriptSaveSettings(void) { glob_script_mem.script_mem_size=0; } -#ifdef USE_RULES_COMPRESSION +#ifdef USE_SCRIPT_COMPRESSION #ifndef USE_24C256 #ifndef USE_SCRIPT_FATFS #ifndef ESP32_SCRIPT_SIZE @@ -3994,7 +3994,7 @@ void ScriptSaveSettings(void) { #endif #endif #endif -#endif // USE_RULES_COMPRESSION +#endif // USE_SCRIPT_COMPRESSION if (bitRead(Settings.rule_enabled, 0)) { int16_t res=Init_Scripter(); @@ -5464,7 +5464,7 @@ bool Xdrv10(uint8_t function) glob_script_mem.script_pram=(uint8_t*)Settings.script_pram[0]; glob_script_mem.script_pram_size=PMEM_SIZE; -#ifdef USE_RULES_COMPRESSION +#ifdef USE_SCRIPT_COMPRESSION #ifndef USE_24C256 #ifndef USE_SCRIPT_FATFS #ifndef ESP32_SCRIPT_SIZE @@ -5479,7 +5479,7 @@ bool Xdrv10(uint8_t function) #endif #endif #endif -#endif // USE_RULES_COMPRESSION +#endif // USE_SCRIPT_COMPRESSION #ifdef USE_BUTTON_EVENT for (uint32_t cnt=0;cnt