diff --git a/sonoff/xdrv_10_scripter.ino b/sonoff/xdrv_10_scripter.ino
index a43975abb..ee78cc740 100644
--- a/sonoff/xdrv_10_scripter.ino
+++ b/sonoff/xdrv_10_scripter.ino
@@ -177,6 +177,10 @@ uint8_t fast_script=0;
uint32_t script_lastmillis;
+#ifdef USE_BUTTON_EVENT
+int8_t script_button[MAX_KEYS];
+#endif
+
char *GetNumericResult(char *lp,uint8_t lastop,float *fp,JsonObject *jo);
char *GetStringResult(char *lp,uint8_t lastop,char *cp,JsonObject *jo);
char *ForceStringVar(char *lp,char *dstr);
@@ -1062,6 +1066,18 @@ chknext:
}
goto exit;
}
+#ifdef USE_BUTTON_EVENT
+ if (!strncmp(vname,"bt[",3)) {
+ // tasmota button state
+ GetNumericResult(vname+3,OPER_EQU,&fvar,0);
+ uint32_t index=fvar;
+ if (index<1 || index>MAX_KEYS) index=1;
+ fvar=script_button[index-1];
+ script_button[index-1]|=0x80;
+ len++;
+ goto exit;
+ }
+#endif
break;
case 'c':
if (!strncmp(vname,"chg[",4)) {
@@ -2122,7 +2138,20 @@ void Replace_Cmd_Vars(char *srcbuf,char *dstbuf,uint16_t dstsize) {
}
}
} else {
- dstbuf[count]=*cp;
+ if (*cp=='\\') {
+ cp++;
+ if (*cp=='n') {
+ dstbuf[count]='\n';
+ } else if (*cp=='r') {
+ dstbuf[count]='\r';
+ } else if (*cp=='\\') {
+ dstbuf[count]='\\';
+ } else {
+ dstbuf[count]=*cp;
+ }
+ } else {
+ dstbuf[count]=*cp;
+ }
if (*cp==0) {
break;
}
@@ -2970,22 +2999,80 @@ const char HTTP_FORM_SCRIPT1[] PROGMEM =
"script enable
"
"
"
"";
const char HTTP_SCRIPT_FORM_END[] PROGMEM =
@@ -3291,7 +3378,15 @@ void HandleScriptConfiguration(void) {
WSContentStart_P(S_CONFIGURE_SCRIPT);
WSContentSendStyle();
WSContentSend_P(HTTP_FORM_SCRIPT);
+
+
+#ifdef xSCRIPT_STRIP_COMMENTS
+ uint16_t ssize=glob_script_mem.script_size;
+ if (bitRead(Settings.rule_enabled, 1)) ssize*=2;
+ WSContentSend_P(HTTP_FORM_SCRIPT1,1,1,bitRead(Settings.rule_enabled,0) ? " checked" : "",ssize);
+#else
WSContentSend_P(HTTP_FORM_SCRIPT1,1,1,bitRead(Settings.rule_enabled,0) ? " checked" : "",glob_script_mem.script_size);
+#endif
// script is to larg for WSContentSend_P
if (glob_script_mem.script_ram[0]) {
@@ -3329,6 +3424,38 @@ void ScriptSaveSettings(void) {
str.replace("\r\n","\n");
str.replace("\r","\n");
+#ifdef xSCRIPT_STRIP_COMMENTS
+ if (bitRead(Settings.rule_enabled, 1)) {
+ char *sp=(char*)str.c_str();
+ char *sp1=sp;
+ char *dp=sp;
+ uint8_t flg=0;
+ while (*sp) {
+ while (*sp==' ') sp++;
+ sp1=sp;
+ sp=strchr(sp,'\n');
+ if (!sp) {
+ flg=1;
+ } else {
+ *sp=0;
+ }
+ if (*sp1!=';') {
+ uint8_t slen=strlen(sp1);
+ if (slen) {
+ strcpy(dp,sp1);
+ dp+=slen;
+ *dp++='\n';
+ }
+ }
+ if (flg) {
+ *dp=0;
+ break;
+ }
+ sp++;
+ }
+ }
+#endif
+
strlcpy(glob_script_mem.script_ram,str.c_str(), glob_script_mem.script_size);
#ifdef USE_24C256
@@ -3923,11 +4050,20 @@ bool ScriptCommand(void) {
}
else if ((CMND_SCRIPT == command_code) && (index > 0)) {
- if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 2)) {
+ if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 4)) {
switch (XdrvMailbox.payload) {
case 0: // Off
case 1: // On
- bitWrite(Settings.rule_enabled, index -1, XdrvMailbox.payload);
+ bitWrite(Settings.rule_enabled, index -1, XdrvMailbox.payload);
+ break;
+#ifdef xSCRIPT_STRIP_COMMENTS
+ case 2:
+ bitWrite(Settings.rule_enabled, 1,0);
+ break;
+ case 3:
+ bitWrite(Settings.rule_enabled, 1,1);
+ break;
+#endif
}
} else {
if ('>' == XdrvMailbox.data[0]) {
@@ -4519,6 +4655,12 @@ bool Xdrv10(uint8_t function)
glob_script_mem.script_pram=(uint8_t*)Settings.mems[0];
glob_script_mem.script_pram_size=MAX_RULE_MEMS*10;
+#ifdef USE_BUTTON_EVENT
+ for (uint32_t cnt=0;cntb",2,0);
+ }
+ }
+ break;
+#endif
}
return result;
}
+
+
#endif // Do not USE_RULES
#endif // USE_SCRIPT