fix scripter unishox error, add 2 y axes line graph to google charts

This commit is contained in:
gemu2015 2020-05-21 06:06:42 +02:00
parent 7f40acb0a5
commit edaf6c493e
1 changed files with 44 additions and 10 deletions

View File

@ -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.h>
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