mirror of https://github.com/arendst/Tasmota.git
Berry : fix custom command +more (#11592)
* fix custom command + more * missing berry lib changes * solidifying
This commit is contained in:
parent
f6f13fe249
commit
59510da9e1
|
@ -1146,10 +1146,14 @@ const bclosure run_deferred_closure = {
|
|||
/********************************************************************
|
||||
// Add command to list
|
||||
"def add_cmd(c,f) "
|
||||
"if !self._cmd "
|
||||
"self._cmd={} "
|
||||
"if !self._ccmd "
|
||||
"self._ccmd={} "
|
||||
"end "
|
||||
"if type(f) == 'function' "
|
||||
"self._ccmd[c]=f "
|
||||
"else "
|
||||
"raise 'value_error', 'the second argument is not a function' "
|
||||
"end "
|
||||
"self._cmd[c]=f "
|
||||
"end "
|
||||
********************************************************************/
|
||||
/********************************************************************
|
||||
|
@ -1158,28 +1162,41 @@ const bclosure run_deferred_closure = {
|
|||
|
||||
be_define_local_const_str(add_cmd_str_name, "add_cmd", -933336417, 0, 7, 0);
|
||||
be_define_local_const_str(add_cmd_str_source, "string", 398550328, 0, 6, 0);
|
||||
be_define_local_const_str(add_cmd_str_0, "_cmd", -875145154, 0, 4, 0);
|
||||
be_define_local_const_str(add_cmd_str_0, "_ccmd", -2131545883, 0, 5, 0);
|
||||
be_define_local_const_str(add_cmd_str_1, "function", -1630125495, 0, 8, 0);
|
||||
be_define_local_const_str(add_cmd_str_2, "value_error", 773297791, 0, 11, 0);
|
||||
be_define_local_const_str(add_cmd_str_3, "the second argument is not a function", -340392827, 0, 37, 0);
|
||||
|
||||
static const bvalue add_cmd_ktab[1] = {
|
||||
static const bvalue add_cmd_ktab[4] = {
|
||||
{ { .s=be_local_const_str(add_cmd_str_0) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(add_cmd_str_1) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(add_cmd_str_2) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(add_cmd_str_3) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t add_cmd_code[8] = {
|
||||
static const uint32_t add_cmd_code[15] = {
|
||||
0x880C0100, // 0000 GETMBR R3 R0 R256
|
||||
0x740E0002, // 0001 JMPT R3 #0005
|
||||
0x600C000B, // 0002 GETGBL R3 G11
|
||||
0x7C0C0000, // 0003 CALL R3 0
|
||||
0x90020003, // 0004 SETMBR R0 R256 R3
|
||||
0x880C0100, // 0005 GETMBR R3 R0 R256
|
||||
0x980C0202, // 0006 SETIDX R3 R1 R2
|
||||
0x80000000, // 0007 RET 0 R0
|
||||
0x600C0015, // 0005 GETGBL R3 G21
|
||||
0x5C100400, // 0006 MOVE R4 R2
|
||||
0x7C0C0200, // 0007 CALL R3 1
|
||||
0x1C0C0701, // 0008 EQ R3 R3 R257
|
||||
0x780E0002, // 0009 JMPF R3 #000D
|
||||
0x880C0100, // 000A GETMBR R3 R0 R256
|
||||
0x980C0202, // 000B SETIDX R3 R1 R2
|
||||
0x70020000, // 000C JMP #000E
|
||||
0xB0060503, // 000D RAISE 1 R258 R259
|
||||
0x80000000, // 000E RET 0 R0
|
||||
};
|
||||
|
||||
static const bproto add_cmd_proto = {
|
||||
NULL, // bgcobject *next
|
||||
8, // type
|
||||
GC_CONST, // marked
|
||||
4, // nstack
|
||||
5, // nstack
|
||||
0, // nupvals
|
||||
3, // argc
|
||||
0, // varg
|
||||
|
@ -1189,8 +1206,8 @@ static const bproto add_cmd_proto = {
|
|||
NULL, // bproto **ptab
|
||||
(binstruction*) &add_cmd_code, // code
|
||||
be_local_const_str(add_cmd_str_name), // name
|
||||
8, // codesize
|
||||
1, // nconst
|
||||
15, // codesize
|
||||
4, // nconst
|
||||
0, // nproto
|
||||
be_local_const_str(add_cmd_str_source), // source
|
||||
#if BE_DEBUG_RUNTIME_INFO /* debug information */
|
||||
|
@ -1203,7 +1220,7 @@ static const bproto add_cmd_proto = {
|
|||
#endif
|
||||
};
|
||||
|
||||
const bclosure add_cmd_closure = {
|
||||
static const bclosure add_cmd_closure = {
|
||||
NULL, // bgcobject *next
|
||||
36, // type
|
||||
GC_CONST, // marked
|
||||
|
@ -1215,15 +1232,89 @@ const bclosure add_cmd_closure = {
|
|||
|
||||
/*******************************************************************/
|
||||
|
||||
|
||||
/********************************************************************
|
||||
// Remove command from list
|
||||
"def remove_cmd(c) "
|
||||
"if self._ccmd "
|
||||
"self._ccmd.remove(c) "
|
||||
"end "
|
||||
"end "
|
||||
********************************************************************/
|
||||
/********************************************************************
|
||||
** Solidified function: remove_cmd
|
||||
********************************************************************/
|
||||
|
||||
be_define_local_const_str(remove_cmd_str_name, "remove_cmd", -462651594, 0, 10, 0);
|
||||
be_define_local_const_str(remove_cmd_str_source, "string", 398550328, 0, 6, 0);
|
||||
be_define_local_const_str(remove_cmd_str_0, "_ccmd", -2131545883, 0, 5, 0);
|
||||
be_define_local_const_str(remove_cmd_str_1, "remove", -611183107, 0, 6, 0);
|
||||
|
||||
static const bvalue remove_cmd_ktab[2] = {
|
||||
{ { .s=be_local_const_str(remove_cmd_str_0) }, BE_STRING},
|
||||
{ { .s=be_local_const_str(remove_cmd_str_1) }, BE_STRING},
|
||||
};
|
||||
|
||||
static const uint32_t remove_cmd_code[7] = {
|
||||
0x88080100, // 0000 GETMBR R2 R0 R256
|
||||
0x780A0003, // 0001 JMPF R2 #0006
|
||||
0x88080100, // 0002 GETMBR R2 R0 R256
|
||||
0x8C080501, // 0003 GETMET R2 R2 R257
|
||||
0x5C100200, // 0004 MOVE R4 R1
|
||||
0x7C080400, // 0005 CALL R2 2
|
||||
0x80000000, // 0006 RET 0 R0
|
||||
};
|
||||
|
||||
static const bproto remove_cmd_proto = {
|
||||
NULL, // bgcobject *next
|
||||
8, // type
|
||||
GC_CONST, // marked
|
||||
5, // nstack
|
||||
0, // nupvals
|
||||
2, // argc
|
||||
0, // varg
|
||||
NULL, // bgcobject *gray
|
||||
NULL, // bupvaldesc *upvals
|
||||
(bvalue*) &remove_cmd_ktab, // ktab
|
||||
NULL, // bproto **ptab
|
||||
(binstruction*) &remove_cmd_code, // code
|
||||
be_local_const_str(remove_cmd_str_name), // name
|
||||
7, // codesize
|
||||
2, // nconst
|
||||
0, // nproto
|
||||
be_local_const_str(remove_cmd_str_source), // source
|
||||
#if BE_DEBUG_RUNTIME_INFO /* debug information */
|
||||
NULL, // lineinfo
|
||||
0, // nlineinfo
|
||||
#endif
|
||||
#if BE_DEBUG_VAR_INFO
|
||||
NULL, // varinfo
|
||||
0, // nvarinfo
|
||||
#endif
|
||||
};
|
||||
|
||||
static const bclosure remove_cmd_closure = {
|
||||
NULL, // bgcobject *next
|
||||
36, // type
|
||||
GC_CONST, // marked
|
||||
0, // nupvals
|
||||
NULL, // bgcobject *gray
|
||||
(bproto*) &remove_cmd_proto, // proto
|
||||
{ NULL } // upvals
|
||||
};
|
||||
|
||||
/*******************************************************************/
|
||||
|
||||
/********************************************************************
|
||||
// Execute custom command
|
||||
"def exec_cmd(cmd, idx, payload) "
|
||||
"if self._cmd "
|
||||
"if self._ccmd "
|
||||
"import json "
|
||||
"var payload_json = json.load(payload) "
|
||||
"var cmd_found = self.find_key_i(self._cmd, cmd) "
|
||||
"var cmd_found = self.find_key_i(self._ccmd, cmd) "
|
||||
"if cmd_found != nil "
|
||||
"self.resolvecmnd(cmd_found) " // set the command name in XdrvMailbox.command
|
||||
"self._cmd[cmd_found](cmd_found, idx, payload, payload_json) "
|
||||
"self._ccmd[cmd_found](cmd_found, idx, payload, payload_json) "
|
||||
"return true "
|
||||
"end "
|
||||
"end "
|
||||
|
@ -1236,7 +1327,7 @@ const bclosure add_cmd_closure = {
|
|||
|
||||
be_define_local_const_str(exec_cmd_str_name, "exec_cmd", 493567399, 0, 8, 0);
|
||||
be_define_local_const_str(exec_cmd_str_source, "string", 398550328, 0, 6, 0);
|
||||
be_define_local_const_str(exec_cmd_str_0, "_cmd", -875145154, 0, 4, 0);
|
||||
be_define_local_const_str(exec_cmd_str_0, "_ccmd", -2131545883, 0, 5, 0);
|
||||
be_define_local_const_str(exec_cmd_str_1, "json", 916562499, 0, 4, 0);
|
||||
be_define_local_const_str(exec_cmd_str_2, "load", -435725847, 0, 4, 0);
|
||||
be_define_local_const_str(exec_cmd_str_3, "find_key_i", 850136726, 0, 10, 0);
|
||||
|
@ -1308,7 +1399,7 @@ static const bproto exec_cmd_proto = {
|
|||
#endif
|
||||
};
|
||||
|
||||
const bclosure exec_cmd_closure = {
|
||||
static const bclosure exec_cmd_closure = {
|
||||
NULL, // bgcobject *next
|
||||
36, // type
|
||||
GC_CONST, // marked
|
||||
|
@ -2314,7 +2405,7 @@ void be_load_tasmota_ntvlib(bvm *vm)
|
|||
static const bnfuncinfo members[] = {
|
||||
{ "_rules", NULL },
|
||||
{ "_timers", NULL },
|
||||
{ "_cmd", NULL },
|
||||
{ "_ccmd", NULL },
|
||||
{ "_drivers", NULL },
|
||||
{ "wire1", NULL },
|
||||
{ "wire2", NULL },
|
||||
|
@ -2351,11 +2442,13 @@ void be_load_tasmota_ntvlib(bvm *vm)
|
|||
{ "find_key_i", (bntvfunc) &find_key_i_closure },
|
||||
{ "find_op", (bntvfunc) &find_op_closure },
|
||||
{ "add_rule", (bntvfunc) &add_rule_closure },
|
||||
{ "remove_rule", (bntvfunc) &remove_rule_closure },
|
||||
{ "try_rule", (bntvfunc) &try_rule_closure },
|
||||
{ "exec_rules", (bntvfunc) &exec_rules_closure },
|
||||
{ "set_timer", (bntvfunc) &set_timer_closure },
|
||||
{ "run_deferred", (bntvfunc) &run_deferred_closure },
|
||||
{ "add_cmd", (bntvfunc) &add_cmd_closure },
|
||||
{ "remove_cmd", (bntvfunc) &remove_cmd_closure },
|
||||
{ "exec_cmd", (bntvfunc) &exec_cmd_closure },
|
||||
{ "gc", (bntvfunc) &gc_closure },
|
||||
{ "event", (bntvfunc) &event_closure },
|
||||
|
|
|
@ -193,20 +193,32 @@ const char berry_prog[] =
|
|||
|
||||
// // Add command to list
|
||||
// "def add_cmd(c,f) "
|
||||
// "if !self._cmd "
|
||||
// "self._cmd={} "
|
||||
// "if !self._ccmd "
|
||||
// "self._ccmd={} "
|
||||
// "end "
|
||||
// "if type(f) == 'function' "
|
||||
// "self._ccmd[c]=f "
|
||||
// "else "
|
||||
// "raise 'value_error', 'the second argument is not a function' "
|
||||
// "end "
|
||||
// "self._cmd[c]=f "
|
||||
// "end "
|
||||
|
||||
// // Remove command from list
|
||||
// "def remove_cmd(c) "
|
||||
// "if self._ccmd "
|
||||
// "self._ccmd.remove(c) "
|
||||
// "end "
|
||||
// "end "
|
||||
|
||||
// // Execute custom command
|
||||
// "def exec_cmd(cmd, idx, payload) "
|
||||
// "if self._cmd "
|
||||
// "if self._ccmd "
|
||||
// "import json "
|
||||
// "var payload_json = json.load(payload) "
|
||||
// "var cmd_found = self.find_key_i(self._cmd, cmd) "
|
||||
// "var cmd_found = self.find_key_i(self._ccmd, cmd) "
|
||||
// "if cmd_found != nil "
|
||||
// "self.resolvecmnd(cmd_found) " // set the command name in XdrvMailbox.command
|
||||
// "self._cmd[cmd_found](cmd_found, idx, payload, payload_json) "
|
||||
// "self._ccmd[cmd_found](cmd_found, idx, payload, payload_json) "
|
||||
// "return true "
|
||||
// "end "
|
||||
// "end "
|
||||
|
|
Loading…
Reference in New Issue