Skip to content

Commit

Permalink
v1.2.12
Browse files Browse the repository at this point in the history
- Implemented scheduling of IR/RF transceiver commands
- Optimized memory usage of JavaScript engine
- Fixed `$$.boundModules.command(..)` API
- Automation now using FreeRTOS task by default
  • Loading branch information
genemars committed May 3, 2024
1 parent 52ba6d2 commit d48c88e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/color-light/color-light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setup() {

auto colorLight = new ColorLight(IO::IOEventDomains::HomeAutomation_HomeGenie, "C1", "Demo Light");
colorLight->onSetColor([](float r, float g, float b) {
statusLED.setPixelColor(0, g, r, b);
statusLED.setPixelColor(0, r, g, b);
#ifdef LED_ARRAY_COUNT
for (int i = 0; i < num; i++) {
pixels.setPixelColor(i, r, g, b);
Expand Down
21 changes: 12 additions & 9 deletions examples/ir-transceiver/api/IRTransceiverHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ namespace Service { namespace API {

auto domain = IO::IOEventDomains::HomeAutomation_RemoteControl;
// HomeGenie Mini module
auto rfModule = new Module();
rfModule->domain = domain;
rfModule->address = CONFIG_IR_MODULE_ADDRESS;
rfModule->type = "Sensor";
rfModule->name = CONFIG_IR_MODULE_ADDRESS; //TODO: CONFIG_IR_MODULE_NAME;
auto irModule = new Module();
irModule->domain = domain;
irModule->address = CONFIG_IR_MODULE_ADDRESS;
irModule->type = "Sensor";
irModule->name = CONFIG_IR_MODULE_ADDRESS; //TODO: CONFIG_IR_MODULE_NAME;
// explicitly enable "scheduling" features for this module
irModule->properties.add(new ModuleParameter("Widget.Implements.Scheduling", "1"));
// add properties
auto propRawData = new ModuleParameter(IOEventPaths::Receiver_RawData);
rfModule->properties.add(propRawData);
irModule->properties.add(propRawData);

moduleList.add(rfModule);
moduleList.add(irModule);

receiver->setModule(rfModule);
receiver->setModule(irModule);
}

void IRTransceiverHandler::init() {
Expand All @@ -61,8 +63,9 @@ namespace Service { namespace API {

auto commandString = command->getOption(0);
auto sendRepeat = command->getOption(1).toInt();
if (sendRepeat <= 0) sendRepeat = 1; // send at least once
if (sendRepeat <= 0 || sendRepeat > 100) sendRepeat = 1; // default send repeat = 1
auto sendDelay = command->getOption(2).toInt();
if (sendDelay <= 0 || sendDelay > 10000) sendDelay = 1; // default delay = 1ms

transmitter->sendCommand(commandString, sendRepeat, sendDelay);

Expand Down
77 changes: 54 additions & 23 deletions lib/duktape-2.7.0/src/duk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,8 @@ typedef struct duk_hthread duk_context;
//#define DUK_USE_ARRAY_PROP_FASTPATH
#undef DUK_USE_ASSERTIONS
//#define DUK_USE_AUGMENT_ERROR_CREATE
#define DUK_USE_AUGMENT_ERROR_THROW
//#define DUK_USE_AUGMENT_ERROR_THROW
#undef DUK_USE_AUGMENT_ERROR_THROW
#define DUK_USE_AVOID_PLATFORM_FUNCPTRS
//#define DUK_USE_BASE64_FASTPATH
//#define DUK_USE_BASE64_SUPPORT
Expand Down Expand Up @@ -2937,14 +2938,17 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_DEBUGGER_SUPPORT
//#define DUK_USE_DEBUGGER_THROW_NOTIFY
#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
#define DUK_USE_DEBUG_BUFSIZE 65536L
//#define DUK_USE_DEBUG_BUFSIZE 65536L
#define DUK_USE_DEBUG_BUFSIZE 2048
#define DUK_USE_DEBUG_LEVEL 0
#undef DUK_USE_DEBUG_WRITE
//#define DUK_USE_DOUBLE_LINKED_HEAP
#define DUK_USE_DUKTAPE_BUILTIN
#define DUK_USE_ENCODING_BUILTINS
#define DUK_USE_ERRCREATE
#define DUK_USE_ERRTHROW
//#define DUK_USE_ERRCREATE
#undef DUK_USE_ERRCREATE
//#define DUK_USE_ERRTHROW
#undef DUK_USE_ERRTHROW
#define DUK_USE_ES6
#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
Expand All @@ -2960,7 +2964,7 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
#undef DUK_USE_EXEC_FUN_LOCAL
#undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
#undef DUK_USE_EXEC_PREFER_SIZE
#define DUK_USE_EXEC_PREFER_SIZE
#define DUK_USE_EXEC_REGCONST_OPTIMIZE
#undef DUK_USE_EXEC_TIMEOUT_CHECK
#undef DUK_USE_EXPLICIT_NULL_INIT
Expand All @@ -2969,15 +2973,15 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_FASTINT
//#define DUK_USE_FAST_REFCOUNT_DEFAULT
#undef DUK_USE_FATAL_HANDLER
#define DUK_USE_FATAL_MAXLEN 128
#define DUK_USE_FATAL_MAXLEN 64
#define DUK_USE_FINALIZER_SUPPORT
#undef DUK_USE_FINALIZER_TORTURE
#undef DUK_USE_FUNCPTR16
#undef DUK_USE_FUNCPTR_DEC16
#undef DUK_USE_FUNCPTR_ENC16
#define DUK_USE_FUNCTION_BUILTIN
#define DUK_USE_FUNC_FILENAME_PROPERTY
//#define DUK_USE_FUNC_NAME_PROPERTY
//#define DUK_USE_FUNC_FILENAME_PROPERTY
#define DUK_USE_FUNC_NAME_PROPERTY
#undef DUK_USE_GC_TORTURE
#undef DUK_USE_GET_MONOTONIC_TIME
#undef DUK_USE_GET_RANDOM_DOUBLE
Expand All @@ -2989,17 +2993,15 @@ typedef struct duk_hthread duk_context;
//#define DUK_USE_HEX_FASTPATH
//#define DUK_USE_HEX_SUPPORT
#define DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT 2
#define DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE 257
#define DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE 32
#define DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT 9
#define DUK_USE_HOBJECT_ARRAY_MINGROW_ADD 16
#define DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR 8
#define DUK_USE_HOBJECT_ENTRY_MINGROW_ADD 16
#define DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR 8
/*
#define DUK_USE_HOBJECT_HASH_PART
#define DUK_USE_HOBJECT_HASH_PROP_LIMIT 8
#define DUK_USE_HSTRING_ARRIDX
*/
//#define DUK_USE_HOBJECT_HASH_PART
#define DUK_USE_HOBJECT_HASH_PROP_LIMIT 64
//#define DUK_USE_HSTRING_ARRIDX
#define DUK_USE_HSTRING_CLEN
#undef DUK_USE_HSTRING_EXTDATA
//#define DUK_USE_HSTRING_LAZY_CLEN
Expand All @@ -3020,7 +3022,8 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_JSON_SUPPORT
//#define DUK_USE_JX
//#define DUK_USE_LEXER_SLIDING_WINDOW
#undef DUK_USE_LIGHTFUNC_BUILTINS
//#undef DUK_USE_LIGHTFUNC_BUILTINS
#define DUK_USE_LIGHTFUNC_BUILTINS
//#define DUK_USE_LITCACHE_SIZE 256
#define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
#define DUK_USE_MATH_BUILTIN
Expand All @@ -3037,10 +3040,11 @@ typedef struct duk_hthread duk_context;
#define DUK_USE_NUMBER_BUILTIN
#define DUK_USE_OBJECT_BUILTIN
#undef DUK_USE_OBJSIZES16
#undef DUK_USE_PARANOID_ERRORS
#define DUK_USE_PC2LINE
#define DUK_USE_PARANOID_ERRORS
//#define DUK_USE_PC2LINE
#undef DUK_USE_PC2LINE
#define DUK_USE_PERFORMANCE_BUILTIN
#undef DUK_USE_PREFER_SIZE
#define DUK_USE_PREFER_SIZE
#undef DUK_USE_PROMISE_BUILTIN
#define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
#undef DUK_USE_REFCOUNT16
Expand Down Expand Up @@ -3069,12 +3073,12 @@ typedef struct duk_hthread duk_context;
#undef DUK_USE_STRICT_UTF8_SOURCE
#define DUK_USE_STRING_BUILTIN
#undef DUK_USE_STRLEN16
#define DUK_USE_STRTAB_GROW_LIMIT 17
#define DUK_USE_STRTAB_GROW_LIMIT 65536
#define DUK_USE_STRTAB_MAXSIZE 268435456L
#define DUK_USE_STRTAB_MINSIZE 1024
#undef DUK_USE_STRTAB_PTRCOMP
#define DUK_USE_STRTAB_RESIZE_CHECK_MASK 255
#define DUK_USE_STRTAB_SHRINK_LIMIT 6
#define DUK_USE_STRTAB_SHRINK_LIMIT 0
#undef DUK_USE_STRTAB_TORTURE
#define DUK_USE_SYMBOL_BUILTIN
//#define DUK_USE_TAILCALL
Expand All @@ -3083,14 +3087,41 @@ typedef struct duk_hthread duk_context;
//#define DUK_USE_TRACEBACK_DEPTH 10
//#define DUK_USE_VALSTACK_GROW_SHIFT 2
#define DUK_USE_VALSTACK_LIMIT 1000000L
#define DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT 2
#define DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT 4
//#define DUK_USE_VALSTACK_UNSAFE
//#define DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT 2
//#define DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT 4
#define DUK_USE_VALSTACK_UNSAFE
//#define DUK_USE_VERBOSE_ERRORS
//#define DUK_USE_VERBOSE_EXECUTOR_ERRORS
//#define DUK_USE_VOLUNTARY_GC
//#define DUK_USE_ZERO_BUFFER_DATA




//#undef DUK_USE_BUFFEROBJECT_SUPPORT
//#undef DUK_USE_ES6
//#undef DUK_USE_ES7
//#undef DUK_USE_ES8
#undef DUK_USE_ES9
#undef DUK_USE_BASE64_SUPPORT
#undef DUK_USE_HEX_SUPPORT
//#undef DUK_USE_COROUTINE_SUPPORT
//#undef DUK_USE_SOURCE_NONBMP
//#undef DUK_USE_ES6_PROXY
#undef DUK_USE_ES7_EXP_OPERATOR
//#undef DUK_USE_ENCODING_BUILTINS
//#undef DUK_USE_PERFORMANCE_BUILTIN
#undef DUK_USE_ES6_UNICODE_ESCAPE
#undef DUK_USE_HTML_COMMENTS
#undef DUK_USE_SHEBANG_COMMENTS
//#undef DUK_USE_REFLECT_BUILTIN
//#undef DUK_USE_SYMBOL_BUILTIN
//#undef DUK_USE_CBOR_SUPPORT
//#undef DUK_USE_CBOR_BUILTIN




/*
* You may add overriding #define/#undef directives below for
* customization. You of course cannot un-#include or un-typedef
Expand Down
10 changes: 8 additions & 2 deletions src/automation/ScheduledScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Automation {
const char baseCode[] PROGMEM = "const $$ = {\n"
" get net() {\n"
" _url = '';\n"
" _command = '';\n"
" return {\n"
" webService: function(url) {\n"
" _url = url;\n"
Expand All @@ -51,10 +52,14 @@ namespace Automation {
" },\n"
" get boundModules() {\n"
" return {\n"
" command: function(cmd, opts) {\n"
" __boundModules_command(cmd, opts);\n"
" command: function(cmd) {\n"
" _command = cmd;"
" return this;\n"
" },\n"
" submit: function(opts) {\n"
" __boundModules_command(_command, opts);\n"
" return this;\n"
" },"
" on: function() {\n"
" __boundModules_command('Control.On', '');\n"
" return this;\n"
Expand Down Expand Up @@ -214,6 +219,7 @@ namespace Automation {
duk_ret_t ScheduledScript::boundModules_command(duk_context *ctx) {
String command = duk_to_string(ctx, 0);
String options = duk_to_string(ctx, 1);
if (options == nullptr || options == "undefined") options = "";
apiCommand(ctx, command.c_str(), options.c_str());
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


// disabling FreeRTOS task saves about ~10K or RAM
//#define CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK
#define CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK

// disabling SSE and MQTT saves only ~2K of RAM
//#define DISABLE_SSE
Expand Down
10 changes: 10 additions & 0 deletions src/service/api/HomeGenieHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ namespace Service { namespace API {
" \"transform\": \"rgb:hsb\"\n"
" }\n"
" }\n"
" },\n {\n"
" \"id\": \"command_remote_control\",\n"
" \"script\": \"cmd = $data$;\\n for (i = 0; i < cmd.length; i++) {\\n $$.boundModules\\n .command('Control.SendRaw')\\n .submit(cmd[i]);\\n }\\n\",\n"
" \"config\": {\n"
" \"data\": {\n"
" \"type\": \"capture:Receiver.RawData\",\n"
" \"value\": \"\",\n"
" \"transform\": \"multiline:array\"\n"
" }\n"
" }\n"
" },\n"
" {\n"
" \"id\": \"command_thermostat_mode\",\n"
Expand Down

0 comments on commit d48c88e

Please sign in to comment.