diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 0071e38d1..4b394dc79 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,5 +1,6 @@ /* 6.5.0.11 20190517 * Add command SetOption64 0/1 to switch between "-" or "_" as sensor index separator impacting DS18X20, DHT, BMP and SHT3X sensor names (#5689) + * Add initial support for Scripts as replacement for Rules. Default disabled but can be enabled in my_user_config.h (#5689) * * 6.5.0.10 20190513 * Enable ADC0 by default in my_user_config.h (#5671) diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 3250573a4..8da668960 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -288,10 +288,10 @@ #define USE_SUNRISE // Add support for Sunrise and sunset tools (+16k) #define SUNRISE_DAWN_ANGLE DAWN_NORMAL // Select desired Dawn Angle from (DAWN_NORMAL, DAWN_CIVIL, DAWN_NAUTIC, DAWN_ASTRONOMIC) -// -- Rules or Scripts ---------------------------- +// -- Rules or Script ---------------------------- // Select none or only one of the below defines -#define USE_RULES // Add support for rules (+4k4 code) -//#define USE_SCRIPT // Add support for script +#define USE_RULES // Add support for rules (+8k code) +//#define USE_SCRIPT // Add support for script (+15k code) // #define USE_EXPRESSION // Add support for expression evaluation in rules (+3k2 code, +64 bytes mem) // #define SUPPORT_MQTT_EVENT // Support trigger event with MQTT subscriptions (+3k5 code) diff --git a/sonoff/support_features.ino b/sonoff/support_features.ino index 1802f93b4..fef9766ea 100644 --- a/sonoff/support_features.ino +++ b/sonoff/support_features.ino @@ -103,7 +103,7 @@ void GetFeatures(void) #ifdef USE_TIMERS_WEB feature_drv1 |= 0x04000000; // xdrv_09_timers.ino #endif -#if defined(USE_RULES) || defined(USE_SCRIPT) +#ifdef USE_RULES feature_drv1 |= 0x08000000; // xdrv_10_rules.ino #endif #ifdef USE_KNX @@ -180,8 +180,10 @@ void GetFeatures(void) #ifdef USE_SM16716 feature_drv2 |= 0x00040000; // xdrv_04_light.ino #endif +#ifdef USE_SCRIPT + feature_drv2 |= 0x00080000; // xdrv_10_scripter.ino +#endif -// feature_drv2 |= 0x00080000; // feature_drv2 |= 0x00100000; // feature_drv2 |= 0x00200000; // feature_drv2 |= 0x00400000; diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 3c0d05d4a..142f3f234 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -18,6 +18,7 @@ */ #ifdef USE_RULES +#ifndef USE_SCRIPT /*********************************************************************************************\ * Rules based heavily on ESP Easy implementation * @@ -1287,4 +1288,5 @@ bool Xdrv10(uint8_t function) return result; } +#endif // Do not USE_SCRIPT #endif // USE_RULES \ No newline at end of file diff --git a/sonoff/xdrv_10_scripter.ino b/sonoff/xdrv_10_scripter.ino index 72e6b6190..9edd27a9f 100644 --- a/sonoff/xdrv_10_scripter.ino +++ b/sonoff/xdrv_10_scripter.ino @@ -17,25 +17,28 @@ along with this program. If not, see . */ -// for doku see up to date doku in file scripter.md +#ifdef USE_SCRIPT +#ifndef USE_RULES +/*********************************************************************************************\ -// uses about 14,2 k of flash -// more stack could be needed for sendmail => -D CONT_STACKSIZE=4800 = +0.8k stack -0.8k heap -// +for documentation see up to date docs in file SCRIPTER.md -/* to doo +uses about 14,2 k of flash +more stack could be needed for sendmail => -D CONT_STACKSIZE=4800 = +0.8k stack -0.8k heap + + +to do optimize code for space -// remarks +remarks goal is fast execution time, minimal use of ram and intuitive syntax therefore => case sensitive cmds and vars (lowercase uses time and code) no math hierarchy (costs ram and execution time, better group with brackets, anyhow better readable for beginners) (will probably make math hierarchy an ifdefed option) keywords if then else endif, or, and are better readable for beginners (others may use {}) -*/ -#ifdef USE_SCRIPT -#ifndef USE_RULES + +\*********************************************************************************************/ #define XDRV_10 10 @@ -896,8 +899,8 @@ chknext: float fvar2; lp=GetNumericResult(lp,OPER_EQU,&fvar2,0); lp++; - fvar=pow(fvar1,fvar2); - //fvar=FastPrecisePow(fvar1,fvar2); + //fvar=pow(fvar1,fvar2); + fvar=FastPrecisePow(fvar1,fvar2); len=0; goto exit; } @@ -2231,5 +2234,5 @@ bool Xdrv10(byte function) return result; } -#endif // not use RULES +#endif // Do not USE_RULES #endif // USE_SCRIPT