From 9b0aa51515176d9dc1b82731eaf9afa3cb56f134 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 10 May 2020 17:51:22 +0200 Subject: [PATCH 1/2] scripter fix create task --- tasmota/xdrv_10_scripter.ino | 53 ++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 38c8f158f..0b9bfa200 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -891,6 +891,16 @@ if (hsv.S == 0) { #endif //#endif + +#ifdef ESP32 +#include "esp_pm.h" +#include "esp_clk.h" +uint32_t switch_freq(uint32_t mhz) { + setCpuFrequencyMhz(mhz); //Set CPU clock to 80MHz fo example + return getCpuFrequencyMhz(); //Get CPU clock +} +#endif // ESP32 + // vtype => ff=nothing found, fe=constant number,fd = constant string else bit 7 => 80 = string, 0 = number // no flash strings here for performance reasons!!! char *isvar(char *lp, uint8_t *vtype,struct T_INDEX *tind,float *fp,char *sp,JsonObject *jo) { @@ -1879,6 +1889,19 @@ chknext: len=0; goto strexit; } +#ifdef ESP32 + if (!strncmp(vname,"sf(",3)) { + lp+=2; + lp=GetNumericResult(lp,OPER_EQU,&fvar,0); + if (fvar<80) fvar=80; + if (fvar>240) fvar=240; + setCpuFrequencyMhz(fvar); + fvar=getCpuFrequencyMhz(); + lp++; + len=0; + goto exit; + } +#endif #if defined(USE_TIMERS) && defined(USE_SUNRISE) if (!strncmp(vname,"sunrise",7)) { fvar=SunMinutes(0); @@ -2093,7 +2116,7 @@ chknext: len=0; goto exit; } -#endif +#endif //ESP32, USE_WEBCAM if (!strncmp(vname,"wday",4)) { fvar=RtcTime.day_of_week; goto exit; @@ -2692,11 +2715,13 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) { return -99; } - DynamicJsonBuffer jsonBuffer; // on heap - JsonObject &jobj=jsonBuffer.parseObject(js); - JsonObject *jo; - if (js) jo=&jobj; - else jo=0; + JsonObject *jo=0; + + if (js) { + DynamicJsonBuffer jsonBuffer; // on heap + JsonObject &jobj=jsonBuffer.parseObject(js); + jo=&jobj; + } char *lp=glob_script_mem.scriptptr; @@ -5119,6 +5144,8 @@ bool RulesProcessEvent(char *json_event) { #ifdef USE_SCRIPT_TASK uint16_t task_timer1; uint16_t task_timer2; +TaskHandle_t task_t1; +TaskHandle_t task_t2; void script_task1(void *arg) { while (1) { @@ -5143,14 +5170,16 @@ void script_task2(void *arg) { uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core) { //return 0; - BaseType_t res=0; - if (core>1) {core = 1;} + BaseType_t res = 0; + if (core > 1) { core = 1; } if (num == 1) { - res = xTaskCreatePinnedToCore(script_task1, "T 1", STASK_STACK, NULL, STASK_PRIO, NULL, core); - task_timer1=time; + if (task_t1) { vTaskDelete(task_t1); } + res = xTaskCreatePinnedToCore(script_task1, "T1", STASK_STACK, NULL, STASK_PRIO, &task_t1, core); + task_timer1 = time; } else { - res = xTaskCreatePinnedToCore(script_task2, "T 2", STASK_STACK, NULL, STASK_PRIO, NULL, core); - task_timer2=time; + if (task_t2) { vTaskDelete(task_t2); } + res = xTaskCreatePinnedToCore(script_task2, "T2", STASK_STACK, NULL, STASK_PRIO, &task_t2, core); + task_timer2 = time; } return res; } From 39a92c276780940c0d09599d2967cccd7dce3bb5 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Sun, 10 May 2020 18:00:37 +0200 Subject: [PATCH 2/2] Update xdrv_10_scripter.ino --- tasmota/xdrv_10_scripter.ino | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 0b9bfa200..d16c0bd31 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -891,16 +891,6 @@ if (hsv.S == 0) { #endif //#endif - -#ifdef ESP32 -#include "esp_pm.h" -#include "esp_clk.h" -uint32_t switch_freq(uint32_t mhz) { - setCpuFrequencyMhz(mhz); //Set CPU clock to 80MHz fo example - return getCpuFrequencyMhz(); //Get CPU clock -} -#endif // ESP32 - // vtype => ff=nothing found, fe=constant number,fd = constant string else bit 7 => 80 = string, 0 = number // no flash strings here for performance reasons!!! char *isvar(char *lp, uint8_t *vtype,struct T_INDEX *tind,float *fp,char *sp,JsonObject *jo) {