Merge pull request #13734 from s-hadinger/berry_neopixel_2

Berry add animation framework
This commit is contained in:
s-hadinger 2021-11-19 22:28:21 +01:00 committed by GitHub
commit ec50ee1688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1508 additions and 324 deletions

View File

@ -0,0 +1,733 @@
/********************************************************************
* Berry module `animate`
*
* To use: `import animate`
*
*******************************************************************/
#include "be_constobj.h"
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_rotate_init, /* name */
be_nested_proto(
12, /* nstack */
5, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 8]) { /* constants */
/* K0 */ be_nested_string("init", 380752755, 4),
/* K1 */ be_nested_string("closure", 1548407746, 7),
/* K2 */ be_nested_string("code", -114201356, 4),
/* K3 */ be_nested_string("push", -2022703139, 4),
/* K4 */ be_nested_string("animate", -409180496, 7),
/* K5 */ be_nested_string("ins_ramp", 1068049360, 8),
/* K6 */ be_nested_string("ins_goto", 1342843963, 8),
/* K7 */ be_const_int(0),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[28]) { /* code */
0x60140003, // 0000 GETGBL R5 G3
0x5C180000, // 0001 MOVE R6 R0
0x7C140200, // 0002 CALL R5 1
0x8C140B00, // 0003 GETMET R5 R5 K0
0x7C140200, // 0004 CALL R5 1
0x4C140000, // 0005 LDNIL R5
0x20140205, // 0006 NE R5 R1 R5
0x78160000, // 0007 JMPF R5 #0009
0x90020201, // 0008 SETMBR R0 K1 R1
0x88140102, // 0009 GETMBR R5 R0 K2
0x8C140B03, // 000A GETMET R5 R5 K3
0xB81E0800, // 000B GETNGBL R7 K4
0x8C1C0F05, // 000C GETMET R7 R7 K5
0x5C240400, // 000D MOVE R9 R2
0x5C280600, // 000E MOVE R10 R3
0x5C2C0800, // 000F MOVE R11 R4
0x7C1C0800, // 0010 CALL R7 4
0x7C140400, // 0011 CALL R5 2
0x88140102, // 0012 GETMBR R5 R0 K2
0x8C140B03, // 0013 GETMET R5 R5 K3
0xB81E0800, // 0014 GETNGBL R7 K4
0x8C1C0F06, // 0015 GETMET R7 R7 K6
0x58240007, // 0016 LDCONST R9 K7
0x58280007, // 0017 LDCONST R10 K7
0x582C0007, // 0018 LDCONST R11 K7
0x7C1C0800, // 0019 CALL R7 4
0x7C140400, // 001A CALL R5 2
0x80000000, // 001B RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_rotate
********************************************************************/
extern const bclass be_class_Animate_engine;
be_local_class(Animate_rotate,
0,
&be_class_Animate_engine,
be_nested_map(1,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(Animate_rotate_init_closure) },
})),
(be_nested_const_str("Animate_rotate", -787188142, 14))
);
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_from_to_init, /* name */
be_nested_proto(
12, /* nstack */
5, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 6]) { /* constants */
/* K0 */ be_nested_string("init", 380752755, 4),
/* K1 */ be_nested_string("closure", 1548407746, 7),
/* K2 */ be_nested_string("code", -114201356, 4),
/* K3 */ be_nested_string("push", -2022703139, 4),
/* K4 */ be_nested_string("animate", -409180496, 7),
/* K5 */ be_nested_string("ins_ramp", 1068049360, 8),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[19]) { /* code */
0x60140003, // 0000 GETGBL R5 G3
0x5C180000, // 0001 MOVE R6 R0
0x7C140200, // 0002 CALL R5 1
0x8C140B00, // 0003 GETMET R5 R5 K0
0x7C140200, // 0004 CALL R5 1
0x4C140000, // 0005 LDNIL R5
0x20140205, // 0006 NE R5 R1 R5
0x78160000, // 0007 JMPF R5 #0009
0x90020201, // 0008 SETMBR R0 K1 R1
0x88140102, // 0009 GETMBR R5 R0 K2
0x8C140B03, // 000A GETMET R5 R5 K3
0xB81E0800, // 000B GETNGBL R7 K4
0x8C1C0F05, // 000C GETMET R7 R7 K5
0x5C240400, // 000D MOVE R9 R2
0x5C280600, // 000E MOVE R10 R3
0x5C2C0800, // 000F MOVE R11 R4
0x7C1C0800, // 0010 CALL R7 4
0x7C140400, // 0011 CALL R5 2
0x80000000, // 0012 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_from_to
********************************************************************/
extern const bclass be_class_Animate_engine;
be_local_class(Animate_from_to,
0,
&be_class_Animate_engine,
be_nested_map(1,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(Animate_from_to_init_closure) },
})),
(be_nested_const_str("Animate_from_to", 1699049867, 15))
);
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_back_forth_init, /* name */
be_nested_proto(
12, /* nstack */
5, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 9]) { /* constants */
/* K0 */ be_nested_string("init", 380752755, 4),
/* K1 */ be_nested_string("closure", 1548407746, 7),
/* K2 */ be_nested_string("code", -114201356, 4),
/* K3 */ be_nested_string("push", -2022703139, 4),
/* K4 */ be_nested_string("animate", -409180496, 7),
/* K5 */ be_nested_string("ins_ramp", 1068049360, 8),
/* K6 */ be_const_int(2),
/* K7 */ be_nested_string("ins_goto", 1342843963, 8),
/* K8 */ be_const_int(0),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[37]) { /* code */
0x60140003, // 0000 GETGBL R5 G3
0x5C180000, // 0001 MOVE R6 R0
0x7C140200, // 0002 CALL R5 1
0x8C140B00, // 0003 GETMET R5 R5 K0
0x7C140200, // 0004 CALL R5 1
0x4C140000, // 0005 LDNIL R5
0x20140205, // 0006 NE R5 R1 R5
0x78160000, // 0007 JMPF R5 #0009
0x90020201, // 0008 SETMBR R0 K1 R1
0x88140102, // 0009 GETMBR R5 R0 K2
0x8C140B03, // 000A GETMET R5 R5 K3
0xB81E0800, // 000B GETNGBL R7 K4
0x8C1C0F05, // 000C GETMET R7 R7 K5
0x5C240400, // 000D MOVE R9 R2
0x5C280600, // 000E MOVE R10 R3
0x0C2C0906, // 000F DIV R11 R4 K6
0x7C1C0800, // 0010 CALL R7 4
0x7C140400, // 0011 CALL R5 2
0x88140102, // 0012 GETMBR R5 R0 K2
0x8C140B03, // 0013 GETMET R5 R5 K3
0xB81E0800, // 0014 GETNGBL R7 K4
0x8C1C0F05, // 0015 GETMET R7 R7 K5
0x5C240600, // 0016 MOVE R9 R3
0x5C280400, // 0017 MOVE R10 R2
0x0C2C0906, // 0018 DIV R11 R4 K6
0x7C1C0800, // 0019 CALL R7 4
0x7C140400, // 001A CALL R5 2
0x88140102, // 001B GETMBR R5 R0 K2
0x8C140B03, // 001C GETMET R5 R5 K3
0xB81E0800, // 001D GETNGBL R7 K4
0x8C1C0F07, // 001E GETMET R7 R7 K7
0x58240008, // 001F LDCONST R9 K8
0x58280008, // 0020 LDCONST R10 K8
0x582C0008, // 0021 LDCONST R11 K8
0x7C1C0800, // 0022 CALL R7 4
0x7C140400, // 0023 CALL R5 2
0x80000000, // 0024 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_back_forth
********************************************************************/
extern const bclass be_class_Animate_engine;
be_local_class(Animate_back_forth,
0,
&be_class_Animate_engine,
be_nested_map(1,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(Animate_back_forth_init_closure) },
})),
(be_nested_const_str("Animate_back_forth", 5319526, 18))
);
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_ins_goto_init, /* name */
be_nested_proto(
4, /* nstack */
4, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("pc_rel", 991921176, 6),
/* K1 */ be_nested_string("pc_abs", 920256495, 6),
/* K2 */ be_nested_string("duration", 799079693, 8),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 4]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x90020202, // 0001 SETMBR R0 K1 R2
0x90020403, // 0002 SETMBR R0 K2 R3
0x80000000, // 0003 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_ins_goto
********************************************************************/
be_local_class(Animate_ins_goto,
3,
NULL,
be_nested_map(4,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("pc_rel", 991921176, 6, -1), be_const_var(0) },
{ be_nested_key("duration", 799079693, 8, -1), be_const_var(2) },
{ be_nested_key("pc_abs", 920256495, 6, -1), be_const_var(1) },
{ be_nested_key("init", 380752755, 4, 2), be_const_closure(Animate_ins_goto_init_closure) },
})),
(be_nested_const_str("Animate_ins_goto", 1667367043, 16))
);
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_ins_ramp_init, /* name */
be_nested_proto(
4, /* nstack */
4, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("a", -468965076, 1),
/* K1 */ be_nested_string("b", -418632219, 1),
/* K2 */ be_nested_string("duration", 799079693, 8),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 4]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x90020202, // 0001 SETMBR R0 K1 R2
0x90020403, // 0002 SETMBR R0 K2 R3
0x80000000, // 0003 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_ins_ramp
********************************************************************/
be_local_class(Animate_ins_ramp,
3,
NULL,
be_nested_map(4,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("a", -468965076, 1, -1), be_const_var(0) },
{ be_nested_key("b", -418632219, 1, 2), be_const_var(1) },
{ be_nested_key("duration", 799079693, 8, -1), be_const_var(2) },
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(Animate_ins_ramp_init_closure) },
})),
(be_nested_const_str("Animate_ins_ramp", 785058280, 16))
);
/********************************************************************
** Solidified function: is_running
********************************************************************/
be_local_closure(Animate_engine_is_running, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("is_running", -2068120035, 10)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 2]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x80040200, // 0001 RET 1 R1
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: run
********************************************************************/
be_local_closure(Animate_engine_run, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 5]) { /* constants */
/* K0 */ be_nested_string("tasmota", 424643812, 7),
/* K1 */ be_nested_string("millis", 1214679063, 6),
/* K2 */ be_nested_string("ins_time", -1314721743, 8),
/* K3 */ be_nested_string("running", 343848780, 7),
/* K4 */ be_nested_string("add_driver", 1654458371, 10),
}),
(be_nested_const_str("run", 718098122, 3)),
((bstring*) &be_const_str_input),
( &(const binstruction[15]) { /* code */
0x4C080000, // 0000 LDNIL R2
0x1C080202, // 0001 EQ R2 R1 R2
0x780A0003, // 0002 JMPF R2 #0007
0xB80A0000, // 0003 GETNGBL R2 K0
0x8C080501, // 0004 GETMET R2 R2 K1
0x7C080200, // 0005 CALL R2 1
0x5C040400, // 0006 MOVE R1 R2
0x90020401, // 0007 SETMBR R0 K2 R1
0x50080200, // 0008 LDBOOL R2 1 0
0x90020602, // 0009 SETMBR R0 K3 R2
0xB80A0000, // 000A GETNGBL R2 K0
0x8C080504, // 000B GETMET R2 R2 K4
0x5C100000, // 000C MOVE R4 R0
0x7C080400, // 000D CALL R2 2
0x80000000, // 000E RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Animate_engine_init, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
1, /* has sup protos */
( &(const struct bproto*[ 1]) {
be_nested_proto(
4, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("Animate next value:", 443143038, 19),
}),
(be_nested_const_str("_anonymous_", 1957281476, 11)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 5]) { /* code */
0x60040001, // 0000 GETGBL R1 G1
0x58080000, // 0001 LDCONST R2 K0
0x5C0C0000, // 0002 MOVE R3 R0
0x7C040400, // 0003 CALL R1 2
0x80000000, // 0004 RET 0
})
),
}),
1, /* has constants */
( &(const bvalue[ 6]) { /* constants */
/* K0 */ be_nested_string("code", -114201356, 4),
/* K1 */ be_nested_string("closure", 1548407746, 7),
/* K2 */ be_nested_string("pc", 1313756516, 2),
/* K3 */ be_const_int(0),
/* K4 */ be_nested_string("ins_time", -1314721743, 8),
/* K5 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[10]) { /* code */
0x60040012, // 0000 GETGBL R1 G18
0x7C040000, // 0001 CALL R1 0
0x90020001, // 0002 SETMBR R0 K0 R1
0x84040000, // 0003 CLOSURE R1 P0
0x90020201, // 0004 SETMBR R0 K1 R1
0x90020503, // 0005 SETMBR R0 K2 K3
0x90020903, // 0006 SETMBR R0 K4 K3
0x50040000, // 0007 LDBOOL R1 0 0
0x90020A01, // 0008 SETMBR R0 K5 R1
0x80000000, // 0009 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: every_50ms
********************************************************************/
be_local_closure(Animate_engine_every_50ms, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("animate", -409180496, 7),
}),
(be_nested_const_str("every_50ms", -1911083288, 10)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 3]) { /* code */
0x8C040100, // 0000 GETMET R1 R0 K0
0x7C040200, // 0001 CALL R1 1
0x80000000, // 0002 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: stop
********************************************************************/
be_local_closure(Animate_engine_stop, /* name */
be_nested_proto(
4, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
/* K1 */ be_nested_string("tasmota", 424643812, 7),
/* K2 */ be_nested_string("remove_driver", 1030243768, 13),
}),
(be_nested_const_str("stop", -883741979, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 7]) { /* code */
0x50040000, // 0000 LDBOOL R1 0 0
0x90020001, // 0001 SETMBR R0 K0 R1
0xB8060200, // 0002 GETNGBL R1 K1
0x8C040302, // 0003 GETMET R1 R1 K2
0x5C0C0000, // 0004 MOVE R3 R0
0x7C040400, // 0005 CALL R1 2
0x80000000, // 0006 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: animate
********************************************************************/
be_local_closure(Animate_engine_animate, /* name */
be_nested_proto(
12, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[21]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
/* K1 */ be_nested_string("tasmota", 424643812, 7),
/* K2 */ be_nested_string("millis", 1214679063, 6),
/* K3 */ be_nested_string("ins_time", -1314721743, 8),
/* K4 */ be_nested_string("pc", 1313756516, 2),
/* K5 */ be_nested_string("code", -114201356, 4),
/* K6 */ be_const_int(0),
/* K7 */ be_nested_string("internal_error", -1775809127, 14),
/* K8 */ be_nested_string("Animate pc is out of range", 1854929421, 26),
/* K9 */ be_nested_string("animate", -409180496, 7),
/* K10 */ be_nested_string("ins_ramp", 1068049360, 8),
/* K11 */ be_nested_string("closure", 1548407746, 7),
/* K12 */ be_nested_string("duration", 799079693, 8),
/* K13 */ be_nested_string("scale_uint", -1204156202, 10),
/* K14 */ be_nested_string("a", -468965076, 1),
/* K15 */ be_nested_string("b", -418632219, 1),
/* K16 */ be_const_int(1),
/* K17 */ be_nested_string("ins_goto", 1342843963, 8),
/* K18 */ be_nested_string("pc_rel", 991921176, 6),
/* K19 */ be_nested_string("pc_abs", 920256495, 6),
/* K20 */ be_nested_string("unknown instruction", 1093911841, 19),
}),
(be_nested_const_str("animate", -409180496, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[93]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x740A0000, // 0001 JMPT R2 #0003
0x80000400, // 0002 RET 0
0x4C080000, // 0003 LDNIL R2
0x1C080202, // 0004 EQ R2 R1 R2
0x780A0003, // 0005 JMPF R2 #000A
0xB80A0200, // 0006 GETNGBL R2 K1
0x8C080502, // 0007 GETMET R2 R2 K2
0x7C080200, // 0008 CALL R2 1
0x5C040400, // 0009 MOVE R1 R2
0x50080200, // 000A LDBOOL R2 1 0
0x780A004F, // 000B JMPF R2 #005C
0x88080103, // 000C GETMBR R2 R0 K3
0x04080202, // 000D SUB R2 R1 R2
0x880C0104, // 000E GETMBR R3 R0 K4
0x6010000C, // 000F GETGBL R4 G12
0x88140105, // 0010 GETMBR R5 R0 K5
0x7C100200, // 0011 CALL R4 1
0x280C0604, // 0012 GE R3 R3 R4
0x780E0002, // 0013 JMPF R3 #0017
0x500C0000, // 0014 LDBOOL R3 0 0
0x90020003, // 0015 SETMBR R0 K0 R3
0x70020044, // 0016 JMP #005C
0x880C0104, // 0017 GETMBR R3 R0 K4
0x140C0706, // 0018 LT R3 R3 K6
0x780E0000, // 0019 JMPF R3 #001B
0xB0060F08, // 001A RAISE 1 K7 K8
0x880C0104, // 001B GETMBR R3 R0 K4
0x88100105, // 001C GETMBR R4 R0 K5
0x940C0803, // 001D GETIDX R3 R4 R3
0x6014000F, // 001E GETGBL R5 G15
0x5C180600, // 001F MOVE R6 R3
0xB81E1200, // 0020 GETNGBL R7 K9
0x881C0F0A, // 0021 GETMBR R7 R7 K10
0x7C140400, // 0022 CALL R5 2
0x7816001B, // 0023 JMPF R5 #0040
0x8810010B, // 0024 GETMBR R4 R0 K11
0x8814070C, // 0025 GETMBR R5 R3 K12
0x14140405, // 0026 LT R5 R2 R5
0x7816000C, // 0027 JMPF R5 #0035
0xB8160200, // 0028 GETNGBL R5 K1
0x8C140B0D, // 0029 GETMET R5 R5 K13
0x5C1C0400, // 002A MOVE R7 R2
0x58200006, // 002B LDCONST R8 K6
0x8824070C, // 002C GETMBR R9 R3 K12
0x8828070E, // 002D GETMBR R10 R3 K14
0x882C070F, // 002E GETMBR R11 R3 K15
0x7C140C00, // 002F CALL R5 6
0x5C180800, // 0030 MOVE R6 R4
0x5C1C0A00, // 0031 MOVE R7 R5
0x7C180200, // 0032 CALL R6 1
0x70020027, // 0033 JMP #005C
0x70020009, // 0034 JMP #003F
0x5C140800, // 0035 MOVE R5 R4
0x8818070F, // 0036 GETMBR R6 R3 K15
0x7C140200, // 0037 CALL R5 1
0x88140104, // 0038 GETMBR R5 R0 K4
0x00140B10, // 0039 ADD R5 R5 K16
0x90020805, // 003A SETMBR R0 K4 R5
0x8814070C, // 003B GETMBR R5 R3 K12
0x04140405, // 003C SUB R5 R2 R5
0x04140205, // 003D SUB R5 R1 R5
0x90020605, // 003E SETMBR R0 K3 R5
0x7002001A, // 003F JMP #005B
0x6010000F, // 0040 GETGBL R4 G15
0x5C140600, // 0041 MOVE R5 R3
0xB81A1200, // 0042 GETNGBL R6 K9
0x88180D11, // 0043 GETMBR R6 R6 K17
0x7C100400, // 0044 CALL R4 2
0x78120013, // 0045 JMPF R4 #005A
0x8810070C, // 0046 GETMBR R4 R3 K12
0x14100404, // 0047 LT R4 R2 R4
0x78120001, // 0048 JMPF R4 #004B
0x70020011, // 0049 JMP #005C
0x7002000D, // 004A JMP #0059
0x88100712, // 004B GETMBR R4 R3 K18
0x20100906, // 004C NE R4 R4 K6
0x78120004, // 004D JMPF R4 #0053
0x88100104, // 004E GETMBR R4 R0 K4
0x88140712, // 004F GETMBR R5 R3 K18
0x00100805, // 0050 ADD R4 R4 R5
0x90020804, // 0051 SETMBR R0 K4 R4
0x70020001, // 0052 JMP #0055
0x88100713, // 0053 GETMBR R4 R3 K19
0x90020804, // 0054 SETMBR R0 K4 R4
0x8810070C, // 0055 GETMBR R4 R3 K12
0x04100404, // 0056 SUB R4 R2 R4
0x04100204, // 0057 SUB R4 R1 R4
0x90020604, // 0058 SETMBR R0 K3 R4
0x70020000, // 0059 JMP #005B
0xB0060F14, // 005A RAISE 1 K7 K20
0x7001FFAD, // 005B JMP #000A
0x80000000, // 005C RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: autorun
********************************************************************/
be_local_closure(Animate_engine_autorun, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("run", 718098122, 3),
/* K1 */ be_nested_string("tasmota", 424643812, 7),
/* K2 */ be_nested_string("add_driver", 1654458371, 10),
}),
(be_nested_const_str("autorun", 1447527407, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 8]) { /* code */
0x8C080100, // 0000 GETMET R2 R0 K0
0x5C100200, // 0001 MOVE R4 R1
0x7C080400, // 0002 CALL R2 2
0xB80A0200, // 0003 GETNGBL R2 K1
0x8C080502, // 0004 GETMET R2 R2 K2
0x5C100000, // 0005 MOVE R4 R0
0x7C080400, // 0006 CALL R2 2
0x80000000, // 0007 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Animate_engine
********************************************************************/
be_local_class(Animate_engine,
5,
NULL,
be_nested_map(12,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("running", 343848780, 7, -1), be_const_var(4) },
{ be_nested_key("is_running", -2068120035, 10, 7), be_const_closure(Animate_engine_is_running_closure) },
{ be_nested_key("run", 718098122, 3, -1), be_const_closure(Animate_engine_run_closure) },
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(Animate_engine_init_closure) },
{ be_nested_key("every_50ms", -1911083288, 10, -1), be_const_closure(Animate_engine_every_50ms_closure) },
{ be_nested_key("stop", -883741979, 4, -1), be_const_closure(Animate_engine_stop_closure) },
{ be_nested_key("pc", 1313756516, 2, 4), be_const_var(2) },
{ be_nested_key("ins_time", -1314721743, 8, -1), be_const_var(3) },
{ be_nested_key("animate", -409180496, 7, 9), be_const_closure(Animate_engine_animate_closure) },
{ be_nested_key("code", -114201356, 4, 6), be_const_var(0) },
{ be_nested_key("closure", 1548407746, 7, -1), be_const_var(1) },
{ be_nested_key("autorun", 1447527407, 7, -1), be_const_closure(Animate_engine_autorun_closure) },
})),
(be_nested_const_str("Animate_engine", 1498417667, 14))
);
/********************************************************************
** Solidified module: animate
********************************************************************/
be_local_module(animate,
"animate",
be_nested_map(6,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("rotate", -1510671094, 6, 2), be_const_class(be_class_Animate_rotate) },
{ be_nested_key("from_to", 21625507, 7, 3), be_const_class(be_class_Animate_from_to) },
{ be_nested_key("back_forth", -1629925234, 10, -1), be_const_class(be_class_Animate_back_forth) },
{ be_nested_key("ins_goto", 1342843963, 8, -1), be_const_class(be_class_Animate_ins_goto) },
{ be_nested_key("ins_ramp", 1068049360, 8, -1), be_const_class(be_class_Animate_ins_ramp) },
{ be_nested_key("engine", -301606853, 6, -1), be_const_class(be_class_Animate_engine) },
}))
);
BE_EXPORT_VARIABLE be_define_const_native_module(animate);
/********************************************************************/

View File

@ -6,10 +6,60 @@
#ifdef USE_WS2812
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Leds_animator_init, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 8]) { /* constants */
/* K0 */ be_nested_string("strip", -48555823, 5),
/* K1 */ be_nested_string("bri", 2112284244, 3),
/* K2 */ be_nested_string("running", 343848780, 7),
/* K3 */ be_nested_string("pixel_count", -1855836553, 11),
/* K4 */ be_nested_string("animators", 279858213, 9),
/* K5 */ be_nested_string("clear", 1550717474, 5),
/* K6 */ be_nested_string("tasmota", 424643812, 7),
/* K7 */ be_nested_string("add_driver", 1654458371, 10),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[18]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x540A0031, // 0001 LDINT R2 50
0x90020202, // 0002 SETMBR R0 K1 R2
0x50080000, // 0003 LDBOOL R2 0 0
0x90020402, // 0004 SETMBR R0 K2 R2
0x8C080303, // 0005 GETMET R2 R1 K3
0x7C080200, // 0006 CALL R2 1
0x90020602, // 0007 SETMBR R0 K3 R2
0x60080012, // 0008 GETGBL R2 G18
0x7C080000, // 0009 CALL R2 0
0x90020802, // 000A SETMBR R0 K4 R2
0x8C080105, // 000B GETMET R2 R0 K5
0x7C080200, // 000C CALL R2 1
0xB80A0C00, // 000D GETNGBL R2 K6
0x8C080507, // 000E GETMET R2 R2 K7
0x5C100000, // 000F MOVE R4 R0
0x7C080400, // 0010 CALL R2 2
0x80000000, // 0011 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_bri
********************************************************************/
be_local_closure(set_bri, /* name */
be_local_closure(Leds_animator_set_bri, /* name */
be_nested_proto(
2, /* nstack */
2, /* argc */
@ -33,10 +83,238 @@ be_local_closure(set_bri, /* name */
/*******************************************************************/
/********************************************************************
** Solidified function: stop
********************************************************************/
be_local_closure(Leds_animator_stop, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("stop", -883741979, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 3]) { /* code */
0x50040000, // 0000 LDBOOL R1 0 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x80000000, // 0002 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: animate
********************************************************************/
be_local_closure(Leds_animator_animate, /* name */
be_nested_proto(
1, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
0, /* has constants */
NULL, /* no const */
(be_nested_const_str("animate", -409180496, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 1]) { /* code */
0x80000000, // 0000 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: remove
********************************************************************/
be_local_closure(Leds_animator_remove, /* name */
be_nested_proto(
4, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_string("tasmota", 424643812, 7),
/* K1 */ be_nested_string("remove_driver", 1030243768, 13),
}),
(be_nested_const_str("remove", -611183107, 6)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 5]) { /* code */
0xB8060000, // 0000 GETNGBL R1 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x5C0C0000, // 0002 MOVE R3 R0
0x7C040400, // 0003 CALL R1 2
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: every_50ms
********************************************************************/
be_local_closure(Leds_animator_every_50ms, /* name */
be_nested_proto(
6, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 7]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
/* K1 */ be_const_int(0),
/* K2 */ be_nested_string("animators", 279858213, 9),
/* K3 */ be_nested_string("is_running", -2068120035, 10),
/* K4 */ be_nested_string("animate", -409180496, 7),
/* K5 */ be_const_int(1),
/* K6 */ be_nested_string("remove", -611183107, 6),
}),
(be_nested_const_str("every_50ms", -1911083288, 10)),
((bstring*) &be_const_str_input),
( &(const binstruction[25]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x78060015, // 0001 JMPF R1 #0018
0x58040001, // 0002 LDCONST R1 K1
0x6008000C, // 0003 GETGBL R2 G12
0x880C0102, // 0004 GETMBR R3 R0 K2
0x7C080200, // 0005 CALL R2 1
0x14080202, // 0006 LT R2 R1 R2
0x780A000D, // 0007 JMPF R2 #0016
0x88080102, // 0008 GETMBR R2 R0 K2
0x94080401, // 0009 GETIDX R2 R2 R1
0x8C0C0503, // 000A GETMET R3 R2 K3
0x7C0C0200, // 000B CALL R3 1
0x780E0003, // 000C JMPF R3 #0011
0x8C0C0504, // 000D GETMET R3 R2 K4
0x7C0C0200, // 000E CALL R3 1
0x00040305, // 000F ADD R1 R1 K5
0x70020003, // 0010 JMP #0015
0x880C0102, // 0011 GETMBR R3 R0 K2
0x8C0C0706, // 0012 GETMET R3 R3 K6
0x5C140200, // 0013 MOVE R5 R1
0x7C0C0400, // 0014 CALL R3 2
0x7001FFEC, // 0015 JMP #0003
0x8C080104, // 0016 GETMET R2 R0 K4
0x7C080200, // 0017 CALL R2 1
0x80000000, // 0018 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_bri
********************************************************************/
be_local_closure(Leds_animator_get_bri, /* name */
be_nested_proto(
3, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("bri", 2112284244, 3),
}),
(be_nested_const_str("get_bri", 2041809895, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 2]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x80040400, // 0001 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: start
********************************************************************/
be_local_closure(Leds_animator_start, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("start", 1697318111, 5)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 3]) { /* code */
0x50040200, // 0000 LDBOOL R1 1 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x80000000, // 0002 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: add_anim
********************************************************************/
be_local_closure(Leds_animator_add_anim, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_string("animators", 279858213, 9),
/* K1 */ be_nested_string("push", -2022703139, 4),
/* K2 */ be_nested_string("run", 718098122, 3),
}),
(be_nested_const_str("add_anim", -314304628, 8)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 7]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x7C080400, // 0003 CALL R2 2
0x8C080302, // 0004 GETMET R2 R1 K2
0x7C080200, // 0005 CALL R2 1
0x80000000, // 0006 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: clear
********************************************************************/
be_local_closure(clear, /* name */
be_local_closure(Leds_animator_clear, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
@ -66,242 +344,29 @@ be_local_closure(clear, /* name */
/*******************************************************************/
/********************************************************************
** Solidified function: get_bri
********************************************************************/
be_local_closure(get_bri, /* name */
be_nested_proto(
3, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("bri", 2112284244, 3),
}),
(be_nested_const_str("get_bri", 2041809895, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 2]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x80040400, // 0001 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: every_50ms
********************************************************************/
be_local_closure(every_50ms, /* name */
be_nested_proto(
3, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
/* K1 */ be_nested_string("animate", -409180496, 7),
}),
(be_nested_const_str("every_50ms", -1911083288, 10)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 5]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x78060001, // 0001 JMPF R1 #0004
0x8C040101, // 0002 GETMET R1 R0 K1
0x7C040200, // 0003 CALL R1 1
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: stop
********************************************************************/
be_local_closure(stop, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("stop", -883741979, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 3]) { /* code */
0x50040000, // 0000 LDBOOL R1 0 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x80000000, // 0002 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: remove
********************************************************************/
be_local_closure(remove, /* name */
be_nested_proto(
4, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_string("tasmota", 424643812, 7),
/* K1 */ be_nested_string("remove_driver", 1030243768, 13),
}),
(be_nested_const_str("remove", -611183107, 6)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 5]) { /* code */
0xB8060000, // 0000 GETNGBL R1 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x5C0C0000, // 0002 MOVE R3 R0
0x7C040400, // 0003 CALL R1 2
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: start
********************************************************************/
be_local_closure(start, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_string("running", 343848780, 7),
}),
(be_nested_const_str("start", 1697318111, 5)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 3]) { /* code */
0x50040200, // 0000 LDBOOL R1 1 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x80000000, // 0002 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(init, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 7]) { /* constants */
/* K0 */ be_nested_string("strip", -48555823, 5),
/* K1 */ be_nested_string("bri", 2112284244, 3),
/* K2 */ be_nested_string("running", 343848780, 7),
/* K3 */ be_nested_string("pixel_count", -1855836553, 11),
/* K4 */ be_nested_string("clear", 1550717474, 5),
/* K5 */ be_nested_string("tasmota", 424643812, 7),
/* K6 */ be_nested_string("add_driver", 1654458371, 10),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[15]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x540A0031, // 0001 LDINT R2 50
0x90020202, // 0002 SETMBR R0 K1 R2
0x50080000, // 0003 LDBOOL R2 0 0
0x90020402, // 0004 SETMBR R0 K2 R2
0x8C080303, // 0005 GETMET R2 R1 K3
0x7C080200, // 0006 CALL R2 1
0x90020602, // 0007 SETMBR R0 K3 R2
0x8C080104, // 0008 GETMET R2 R0 K4
0x7C080200, // 0009 CALL R2 1
0xB80A0A00, // 000A GETNGBL R2 K5
0x8C080506, // 000B GETMET R2 R2 K6
0x5C100000, // 000C MOVE R4 R0
0x7C080400, // 000D CALL R2 2
0x80000000, // 000E RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: animate
********************************************************************/
be_local_closure(animate, /* name */
be_nested_proto(
1, /* nstack */
1, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
0, /* has constants */
NULL, /* no const */
(be_nested_const_str("animate", -409180496, 7)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 1]) { /* code */
0x80000000, // 0000 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Leds_animator
********************************************************************/
be_local_class(Leds_animator,
4,
5,
NULL,
be_nested_map(13,
be_nested_map(15,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("set_bri", -1505848517, 7, 9), be_const_closure(set_bri_closure) },
{ be_nested_key("clear", 1550717474, 5, -1), be_const_closure(clear_closure) },
{ be_nested_key("init", 380752755, 4, 7), be_const_closure(Leds_animator_init_closure) },
{ be_nested_key("set_bri", -1505848517, 7, -1), be_const_closure(Leds_animator_set_bri_closure) },
{ be_nested_key("stop", -883741979, 4, -1), be_const_closure(Leds_animator_stop_closure) },
{ be_nested_key("strip", -48555823, 5, 4), be_const_var(0) },
{ be_nested_key("animators", 279858213, 9, 12), be_const_var(4) },
{ be_nested_key("animate", -409180496, 7, -1), be_const_closure(Leds_animator_animate_closure) },
{ be_nested_key("remove", -611183107, 6, -1), be_const_closure(Leds_animator_remove_closure) },
{ be_nested_key("running", 343848780, 7, -1), be_const_var(3) },
{ be_nested_key("get_bri", 2041809895, 7, -1), be_const_closure(get_bri_closure) },
{ be_nested_key("every_50ms", -1911083288, 10, -1), be_const_closure(every_50ms_closure) },
{ be_nested_key("bri", 2112284244, 3, 0), be_const_var(2) },
{ be_nested_key("stop", -883741979, 4, 11), be_const_closure(stop_closure) },
{ be_nested_key("remove", -611183107, 6, 1), be_const_closure(remove_closure) },
{ be_nested_key("start", 1697318111, 5, 3), be_const_closure(start_closure) },
{ be_nested_key("strip", -48555823, 5, -1), be_const_var(0) },
{ be_nested_key("every_50ms", -1911083288, 10, -1), be_const_closure(Leds_animator_every_50ms_closure) },
{ be_nested_key("bri", 2112284244, 3, 6), be_const_var(2) },
{ be_nested_key("get_bri", 2041809895, 7, -1), be_const_closure(Leds_animator_get_bri_closure) },
{ be_nested_key("start", 1697318111, 5, -1), be_const_closure(Leds_animator_start_closure) },
{ be_nested_key("add_anim", -314304628, 8, 13), be_const_closure(Leds_animator_add_anim_closure) },
{ be_nested_key("pixel_count", -1855836553, 11, -1), be_const_var(1) },
{ be_nested_key("init", 380752755, 4, -1), be_const_closure(init_closure) },
{ be_nested_key("animate", -409180496, 7, 4), be_const_closure(animate_closure) },
{ be_nested_key("clear", 1550717474, 5, 1), be_const_closure(Leds_animator_clear_closure) },
})),
(be_nested_const_str("Leds_animator", 142168673, 13))
);

View File

@ -36,6 +36,7 @@ be_extern_native_module(webserver);
be_extern_native_module(flash);
be_extern_native_module(path);
be_extern_native_module(unishox);
be_extern_native_module(animate);
#ifdef USE_LVGL
be_extern_native_module(lv);
#endif // USE_LVGL
@ -103,6 +104,7 @@ BERRY_LOCAL const bntvmodule* const be_module_table[] = {
#ifdef USE_UNISHOX_COMPRESSION
&be_native_module(unishox),
#endif // USE_UNISHOX_COMPRESSION
&be_native_module(animate),
#ifdef USE_LVGL
&be_native_module(lv),

View File

@ -1859,6 +1859,102 @@ be_local_closure(exec_cmd, /* name */
);
/*******************************************************************/
/********************************************************************
** Solidified function: hs2rgb
********************************************************************/
be_local_closure(hs2rgb, /* name */
be_nested_proto(
17, /* nstack */
3, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 6]) { /* constants */
/* K0 */ be_const_int(0),
/* K1 */ be_nested_string("tasmota", 424643812, 7),
/* K2 */ be_nested_string("scale_uint", -1204156202, 10),
/* K3 */ be_const_int(1),
/* K4 */ be_const_int(2),
/* K5 */ be_const_int(3),
}),
(be_nested_const_str("hs2rgb", 1040816349, 6)),
((bstring*) &be_const_str_input),
( &(const binstruction[68]) { /* code */
0x4C0C0000, // 0000 LDNIL R3
0x1C0C0403, // 0001 EQ R3 R2 R3
0x780E0000, // 0002 JMPF R3 #0004
0x540A00FE, // 0003 LDINT R2 255
0x540E00FE, // 0004 LDINT R3 255
0x541200FE, // 0005 LDINT R4 255
0x541600FE, // 0006 LDINT R5 255
0x541A0167, // 0007 LDINT R6 360
0x10040206, // 0008 MOD R1 R1 R6
0x24180500, // 0009 GT R6 R2 K0
0x781A0031, // 000A JMPF R6 #003D
0x541A003B, // 000B LDINT R6 60
0x0C180206, // 000C DIV R6 R1 R6
0x541E003B, // 000D LDINT R7 60
0x101C0207, // 000E MOD R7 R1 R7
0x542200FE, // 000F LDINT R8 255
0x04201002, // 0010 SUB R8 R8 R2
0xB8260200, // 0011 GETNGBL R9 K1
0x8C241302, // 0012 GETMET R9 R9 K2
0x5C2C0E00, // 0013 MOVE R11 R7
0x58300000, // 0014 LDCONST R12 K0
0x5436003B, // 0015 LDINT R13 60
0x543A00FE, // 0016 LDINT R14 255
0x5C3C1000, // 0017 MOVE R15 R8
0x7C240C00, // 0018 CALL R9 6
0xB82A0200, // 0019 GETNGBL R10 K1
0x8C281502, // 001A GETMET R10 R10 K2
0x5C300E00, // 001B MOVE R12 R7
0x58340000, // 001C LDCONST R13 K0
0x543A003B, // 001D LDINT R14 60
0x5C3C1000, // 001E MOVE R15 R8
0x544200FE, // 001F LDINT R16 255
0x7C280C00, // 0020 CALL R10 6
0x1C2C0D00, // 0021 EQ R11 R6 K0
0x782E0002, // 0022 JMPF R11 #0026
0x5C141400, // 0023 MOVE R5 R10
0x5C101000, // 0024 MOVE R4 R8
0x70020016, // 0025 JMP #003D
0x1C2C0D03, // 0026 EQ R11 R6 K3
0x782E0002, // 0027 JMPF R11 #002B
0x5C0C1200, // 0028 MOVE R3 R9
0x5C101000, // 0029 MOVE R4 R8
0x70020011, // 002A JMP #003D
0x1C2C0D04, // 002B EQ R11 R6 K4
0x782E0002, // 002C JMPF R11 #0030
0x5C0C1000, // 002D MOVE R3 R8
0x5C101400, // 002E MOVE R4 R10
0x7002000C, // 002F JMP #003D
0x1C2C0D05, // 0030 EQ R11 R6 K5
0x782E0002, // 0031 JMPF R11 #0035
0x5C0C1000, // 0032 MOVE R3 R8
0x5C141200, // 0033 MOVE R5 R9
0x70020007, // 0034 JMP #003D
0x542E0003, // 0035 LDINT R11 4
0x1C2C0C0B, // 0036 EQ R11 R6 R11
0x782E0002, // 0037 JMPF R11 #003B
0x5C0C1400, // 0038 MOVE R3 R10
0x5C141000, // 0039 MOVE R5 R8
0x70020001, // 003A JMP #003D
0x5C141000, // 003B MOVE R5 R8
0x5C101200, // 003C MOVE R4 R9
0x541A000F, // 003D LDINT R6 16
0x38180606, // 003E SHL R6 R3 R6
0x541E0007, // 003F LDINT R7 8
0x381C0A07, // 0040 SHL R7 R5 R7
0x30180C07, // 0041 OR R6 R6 R7
0x30180C04, // 0042 OR R6 R6 R4
0x80040C00, // 0043 RET 1 R6
})
)
);
/*******************************************************************/
#include "../generate/be_fixed_be_class_tasmota.h"
@ -1954,6 +2050,8 @@ class be_class_tasmota (scope: global, name: Tasmota) {
wire_scan, closure(wire_scan_closure)
time_str, closure(time_str_closure)
hs2rgb, closure(hs2rgb_closure)
cb_dispatch, closure(cb_dispatch_closure)
gen_cb, closure(gen_cb_closure)

View File

@ -0,0 +1,184 @@
#
# class Animate
#
# Animation framework
#
animate = module("animate")
# state-machine: from val a to b
class Animate_ins_ramp
var a # starting value
var b # end value
var duration # duration in milliseconds
def init(a,b,duration)
self.a = a
self.b = b
self.duration = duration
end
end
animate.ins_ramp = Animate_ins_ramp
# state-machine: pause and goto
class Animate_ins_goto
var pc_rel # relative PC, -1 previous instruction, 1 next instruction, 0 means see pc_abs
var pc_abs # absolute PC, only if pc_rel == 0, address if next instruction
var duration # pause in milliseconds before goto, -1 means infinite (state-machine can be changed externally)
def init(pc_rel, pc_abs, duration)
self.pc_rel = pc_rel
self.pc_abs = pc_abs
self.duration = duration
end
end
animate.ins_goto = Animate_ins_goto
class Animate_engine
var code # array of state-machine instructions
var closure # closure to call with the new value
var pc # program-counter
var ins_time # absolute time when the current instruction started
var running # is the animation running? allows fast return
def init()
self.code = []
self.closure = def (v) print("Animate next value:", v) end # default to debug function
self.pc = 0 # start at instruction 0
self.ins_time = 0
self.running = false # not running by default
#
end
# run but needs external calls to `animate()`
def run(cur_time)
if cur_time == nil cur_time = tasmota.millis() end
self.ins_time = cur_time
self.running = true
tasmota.add_driver(self)
end
# runs autonomously in the Tasmota event loop
def autorun(cur_time)
self.run(cur_time)
tasmota.add_driver(self)
end
def stop()
self.running = false
tasmota.remove_driver(self)
end
def is_running()
return self.running
end
def every_50ms()
self.animate()
end
def animate(cur_time) # time in milliseconds, optional, defaults to `tasmota.millis()`
if !self.running return end
if cur_time == nil cur_time = tasmota.millis() end
# run through instructions
while true
var sub_index = cur_time - self.ins_time # time since the beginning of current instruction
#
# make sure PC is valid
if self.pc >= size(self.code)
self.running = false
break
end
#
if self.pc < 0 raise "internal_error", "Animate pc is out of range" end
var ins = self.code[self.pc]
# Instruction Ramp
if isinstance(ins, animate.ins_ramp)
var f = self.closure # assign to a local variable to not call a method
if sub_index < ins.duration
# we're still in the ramp
var v = tasmota.scale_uint(sub_index, 0, ins.duration, ins.a, ins.b)
# call closure
f(v) # call closure, need try? TODO
break
else
f(ins.b) # set to last value
self.pc += 1 # next instruction
self.ins_time = cur_time - (sub_index - ins.duration)
end
# Instruction Goto
elif isinstance(ins, animate.ins_goto)
if sub_index < ins.duration
break
else
if ins.pc_rel != 0
self.pc += ins.pc_rel
else
self.pc = ins.pc_abs
end
self.ins_time = cur_time - (sub_index - ins.duration)
end
# Invalid
else
raise "internal_error", "unknown instruction"
end
end
end
end
animate.engine = Animate_engine
class Animate_from_to : Animate_engine
def init(closure, from, to, duration)
super(self).init()
if closure != nil self.closure = closure end
self.code.push(animate.ins_ramp(from, to, duration))
end
end
animate.from_to = Animate_from_to
#-
a=Animate_from_to(nil, 0, 100, 5000)
a.autorun()
-#
class Animate_rotate : Animate_engine
def init(closure, from, to, duration)
super(self).init()
if closure != nil self.closure = closure end
self.code.push(animate.ins_ramp(from, to, duration))
self.code.push(animate.ins_goto(0, 0, 0)) # goto abs pc = 0 without any pause
end
end
animate.rotate = Animate_rotate
#-
a=Animate_rotate(nil, 0, 100, 5000)
a.autorun()
-#
class Animate_back_forth : Animate_engine
def init(closure, from, to, duration)
super(self).init()
if closure != nil self.closure = closure end
self.code.push(animate.ins_ramp(from, to, duration / 2))
self.code.push(animate.ins_ramp(to, from, duration / 2))
self.code.push(animate.ins_goto(0, 0, 0)) # goto abs pc = 0 without any pause
end
end
animate.back_forth = Animate_back_forth
#-
a=Animate_back_forth(nil, 0, 100, 5000)
a.autorun()
-#

View File

@ -509,4 +509,52 @@ class Tasmota
raise "internal_error", "No callback available"
end
#- convert hue/sat to rgb -#
#- hue:int in range 0..359 -#
#- sat:int (optional) in range 0..255 -#
#- returns int: 0xRRGGBB -#
def hs2rgb(hue,sat)
if sat == nil sat = 255 end
var r = 255 # default to white
var b = 255
var g = 255
# we take brightness at 100%, brightness should be set separately
hue = hue % 360 # normalize to 0..359
if sat > 0
var i = hue / 60 # quadrant 0..5
var f = hue % 60 # 0..59
var p = 255 - sat
var q = tasmota.scale_uint(f, 0, 60, 255, p) # 0..59
var t = tasmota.scale_uint(f, 0, 60, p, 255)
if i == 0
# r = 255
g = t
b = p
elif i == 1
r = q
# g = 255
b = p
elif i == 2
r = p
#g = 255
b = t
elif i == 3
r = p
g = q
#b = 255
elif i == 4
r = t
g = p
#b = 255
else
#r = 255
g = p
b = q
end
end
return (r << 16) | (g << 8) | b
end
end

View File

@ -5,18 +5,25 @@ class Leds_animator
var pixel_count # number of pixels in the strip
var bri # brightness of the animation, 0..100, default 50
var running # is the animation running
var animators # animators list
def init(strip)
self.strip = strip
self.bri = 50 # percentage of brightness 0..100
self.running = false
self.pixel_count = strip.pixel_count()
self.animators = []
#
self.clear() # clear all leds first
#
tasmota.add_driver(self)
end
def add_anim(anim)
self.animators.push(anim)
anim.run() # start the animator
end
def clear()
self.stop()
self.strip.clear()
@ -37,6 +44,18 @@ class Leds_animator
def every_50ms()
if self.running
# run animators first
var i = 0
while i < size(self.animators)
var anim = self.animators[i]
if anim.is_running()
anim.animate()
i += 1
else
self.animators.remove(i) # remove any finished animator
end
end
# tirgger animate and display
self.animate()
end
end

View File

@ -84,6 +84,7 @@ extern const bcstring be_const_str_false;
extern const bcstring be_const_str_add_rule;
extern const bcstring be_const_str_setbits;
extern const bcstring be_const_str_write_file;
extern const bcstring be_const_str_hs2rgb;
extern const bcstring be_const_str_SERIAL_8O1;
extern const bcstring be_const_str_wd;
extern const bcstring be_const_str_wire_scan;

View File

@ -84,6 +84,7 @@ be_define_const_str(false, "false", 184981848u, 62, 5, NULL);
be_define_const_str(add_rule, "add_rule", 596540743u, 0, 8, &be_const_str_setbits);
be_define_const_str(setbits, "setbits", 2762408167u, 0, 7, &be_const_str_write_file);
be_define_const_str(write_file, "write_file", 3177658879u, 0, 10, NULL);
be_define_const_str(hs2rgb, "hs2rgb", 1040816349u, 0, 6, NULL);
be_define_const_str(SERIAL_8O1, "SERIAL_8O1", 289122742u, 0, 10, &be_const_str_wd);
be_define_const_str(wd, "wd", 1531424278u, 0, 2, &be_const_str_wire_scan);
be_define_const_str(wire_scan, "wire_scan", 2671275880u, 0, 9, NULL);
@ -391,7 +392,7 @@ static const bstring* const m_string_table[] = {
(const bstring *)&be_const_str_chars_in_string,
(const bstring *)&be_const_str_add_rule,
NULL,
NULL,
(const bstring *)&be_const_str_hs2rgb,
(const bstring *)&be_const_str_SERIAL_8O1,
(const bstring *)&be_const_str_AudioFileSourceFS,
(const bstring *)&be_const_str_AudioGenerator,
@ -512,6 +513,6 @@ static const bstring* const m_string_table[] = {
static const struct bconststrtab m_const_string_table = {
.size = 162,
.count = 324,
.count = 325,
.table = m_string_table
};

View File

@ -1,87 +1,88 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(exec_rules, 20), be_const_closure(exec_rules_closure) },
{ be_const_key(publish_result, 75), be_const_func(l_publish_result) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(strftime, 6), be_const_func(l_strftime) },
{ be_const_key(remove_driver, -1), be_const_closure(remove_driver_closure) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(add_driver, 37), be_const_closure(add_driver_closure) },
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
{ be_const_key(arch, 38), be_const_func(l_arch) },
{ be_const_key(eth, 26), be_const_func(l_eth) },
{ be_const_key(response_append, -1), be_const_func(l_respAppend) },
{ be_const_key(_timers, -1), be_const_var(0) },
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) },
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
{ be_const_key(chars_in_string, 62), be_const_closure(chars_in_string_closure) },
{ be_const_key(publish, -1), be_const_func(l_publish) },
{ be_const_key(time_reached, 32), be_const_func(l_timereached) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(wire1, 27), be_const_var(1) },
{ be_const_key(rtc, 43), be_const_func(l_rtc) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(cmd_res, -1), be_const_var(2) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
{ be_const_key(delay, 40), be_const_func(l_delay) },
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(add_cmd, 74), be_const_closure(add_cmd_closure) },
{ be_const_key(global, -1), be_const_var(3) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(wire2, -1), be_const_var(4) },
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(get_option, 48), be_const_func(l_getoption) },
{ be_const_key(try_rule, 5), be_const_closure(try_rule_closure) },
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
{ be_const_key(get_free_heap, 43), be_const_func(l_getFreeHeap) },
{ be_const_key(eth, 55), be_const_func(l_eth) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(wd, 28), be_const_var(5) },
{ be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) },
{ be_const_key(wire_scan, 61), be_const_closure(wire_scan_closure) },
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
{ be_const_key(exec_tele, 69), be_const_closure(exec_tele_closure) },
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(chars_in_string, 66), be_const_closure(chars_in_string_closure) },
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(time_str, -1), be_const_closure(time_str_closure) },
{ be_const_key(_rules, 73), be_const_var(6) },
{ be_const_key(remove_cmd, 50), be_const_closure(remove_cmd_closure) },
{ be_const_key(_cb, -1), be_const_var(7) },
{ be_const_key(_ccmd, -1), be_const_var(8) },
{ be_const_key(i2c_enabled, 53), be_const_func(l_i2cenabled) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(init, -1), be_const_closure(init_closure) },
{ be_const_key(save, 10), be_const_func(l_save) },
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
{ be_const_key(get_switch, 21), be_const_func(l_getswitch) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(_cmd, 72), be_const_func(l_cmd) },
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
{ be_const_key(event, -1), be_const_closure(event_closure) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
{ be_const_key(web_send, 1), be_const_func(l_webSend) },
{ be_const_key(hs2rgb, -1), be_const_closure(hs2rgb_closure) },
{ be_const_key(time_str, 56), be_const_closure(time_str_closure) },
{ be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(response_append, 1), be_const_func(l_respAppend) },
{ be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(remove_driver, 47), be_const_closure(remove_driver_closure) },
{ be_const_key(yield, 37), be_const_func(l_yield) },
{ be_const_key(exec_cmd, 2), be_const_closure(exec_cmd_closure) },
{ be_const_key(rtc, 14), be_const_func(l_rtc) },
{ be_const_key(cmd_res, -1), be_const_var(0) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
{ be_const_key(exec_tele, -1), be_const_closure(exec_tele_closure) },
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(global, 51), be_const_var(1) },
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(add_driver, 12), be_const_closure(add_driver_closure) },
{ be_const_key(_timers, 53), be_const_var(2) },
{ be_const_key(_cb, 71), be_const_var(3) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(remove_rule, 0), be_const_closure(remove_rule_closure) },
{ be_const_key(web_send, 9), be_const_func(l_webSend) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) },
{ be_const_key(remove_timer, 10), be_const_closure(remove_timer_closure) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(remove_rule, 36), be_const_closure(remove_rule_closure) },
{ be_const_key(wire2, -1), be_const_var(4) },
{ be_const_key(find_op, -1), be_const_closure(find_op_closure) },
{ be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) },
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
{ be_const_key(settings, 60), be_const_var(9) },
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(kv, 65), be_const_closure(kv_closure) },
{ be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ be_const_key(yield, -1), be_const_func(l_yield) },
{ be_const_key(_drivers, -1), be_const_var(10) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(cmd, 60), be_const_closure(cmd_closure) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(settings, -1), be_const_var(5) },
{ be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(arch, -1), be_const_func(l_arch) },
{ be_const_key(_ccmd, -1), be_const_var(6) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(find_key_i, 19), be_const_closure(find_key_i_closure) },
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
{ be_const_key(save, 25), be_const_func(l_save) },
{ be_const_key(millis, -1), be_const_func(l_millis) },
{ be_const_key(kv, -1), be_const_closure(kv_closure) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(wire1, 72), be_const_var(7) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(scale_uint, 50), be_const_func(l_scaleuint) },
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
{ be_const_key(wifi, 38), be_const_func(l_wifi) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(_drivers, -1), be_const_var(8) },
{ be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) },
{ be_const_key(strftime, -1), be_const_func(l_strftime) },
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) },
{ be_const_key(resp_cmnd_done, 74), be_const_func(l_respCmndDone) },
{ be_const_key(_rules, 16), be_const_var(9) },
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) },
{ be_const_key(init, -1), be_const_closure(init_closure) },
{ be_const_key(wd, 52), be_const_var(10) },
};
static be_define_const_map(
be_class_tasmota_map,
76
77
);
BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -127,7 +127,9 @@ static void m_solidify_bvalue(bvm *vm, bvalue * value, const char *classname, co
}
break;
case BE_CLOSURE:
logfmt("be_const_closure(%s_closure)", str(((bclosure*) var_toobj(value))->proto->name));
logfmt("be_const_closure(%s%s%s_closure)",
classname ? classname : "", classname ? "_" : "",
str(((bclosure*) var_toobj(value))->proto->name));
break;
case BE_CLASS:
logfmt("be_const_class(be_class_%s)", str(((bclass*) var_toobj(value))->name));
@ -271,7 +273,7 @@ static void m_solidify_proto(bvm *vm, bproto *pr, const char * func_name, int bu
}
static void m_solidify_closure(bvm *vm, bclosure *cl, int builtins)
static void m_solidify_closure(bvm *vm, bclosure *cl, const char * classname, int builtins)
{
bproto *pr = cl->proto;
const char * func_name = str(pr->name);
@ -289,7 +291,9 @@ static void m_solidify_closure(bvm *vm, bclosure *cl, int builtins)
logfmt("** Solidified function: %s\n", func_name);
logfmt("********************************************************************/\n");
logfmt("be_local_closure(%s, /* name */\n", func_name);
logfmt("be_local_closure(%s%s%s, /* name */\n",
classname ? classname : "", classname ? "_" : "",
func_name);
m_solidify_proto(vm, pr, func_name, builtins, indent);
logfmt("\n");
@ -310,7 +314,7 @@ static void m_solidify_subclass(bvm *vm, bclass *cl, int builtins)
while ((node = be_map_next(cl->members, &iter)) != NULL) {
if (var_isstr(&node->key) && var_isclosure(&node->value)) {
bclosure *f = var_toobj(&node->value);
m_solidify_closure(vm, f, builtins);
m_solidify_closure(vm, f, class_name, builtins);
}
}
}
@ -364,14 +368,18 @@ static void m_solidify_module(bvm *vm, bmodule *ml, int builtins)
const char * module_name = be_module_name(ml);
if (!module_name) { module_name = ""; }
/* iterate on members to dump closures */
/* iterate on members to dump closures and classes */
if (ml->table) {
bmapnode *node;
bmapiter iter = be_map_iter();
while ((node = be_map_next(ml->table, &iter)) != NULL) {
if (var_isstr(&node->key) && var_isclosure(&node->value)) {
bclosure *f = var_toobj(&node->value);
m_solidify_closure(vm, f, builtins);
m_solidify_closure(vm, f, NULL, builtins);
}
if (var_isstr(&node->key) && var_isclass(&node->value)) {
bclass *cl = var_toobj(&node->value);
m_solidify_subclass(vm, cl, builtins);
}
}
}
@ -405,7 +413,7 @@ static int m_dump(bvm *vm)
if (be_top(vm) >= 1) {
bvalue *v = be_indexof(vm, 1);
if (var_isclosure(v)) {
m_solidify_closure(vm, var_toobj(v), be_builtin_count(vm));
m_solidify_closure(vm, var_toobj(v), NULL, be_builtin_count(vm));
} else if (var_isclass(v)) {
m_solidify_class(vm, var_toobj(v), be_builtin_count(vm));
} else if (var_ismodule(v)) {

View File

@ -9,6 +9,8 @@ rainbow.start()
-#
import animate
# https://stackoverflow.com/questions/34187171/fast-integer-square-root-approximation
def fast_sqrt_int(val)
var a, b
@ -42,13 +44,14 @@ class Rainbow : Leds_animator
0xEE82EE, #- violet -#
]
def init(strip)
def init(strip, duration)
super(self).init(strip)
self.cur_offset = 0
# add an animator to change `self.cur_offset` to each value of the palette
self.add_anim(animate.rotate(def(v) self.cur_offset = v end, 0, size(self.palette), int(duration * 1000)))
end
def animate()
var i = 0
# move instance variables to registers to avoid GETMBR inside the loop
var cur_offset = self.cur_offset
var modulus = size(self.palette)
@ -57,18 +60,25 @@ class Rainbow : Leds_animator
var bri = self.bri
var set_pixel_color = strip.set_pixel_color
var i = 0
while i < self.pixel_count # doing a loop rather than a `for` prevents from allocating a new object
var col = palette[(cur_offset + i) % modulus]
set_pixel_color(strip, i, col, bri) # simulate the method call without GETMET
i += 1
end
strip.show()
# advance to next color
self.cur_offset = (self.cur_offset + 1) % modulus
end
end
#-
var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Rainbow(strip, 1.0)
r.start()
-#
class Rainbow_Matrix : Leds_animator
var cur_offset # current offset in the palette
static palette = [ 0xFF0000, #- red -#
@ -80,9 +90,11 @@ class Rainbow_Matrix : Leds_animator
0xEE82EE, #- violet -#
]
def init(strip)
def init(strip, duration)
super(self).init(strip)
self.cur_offset = 0
# add an animator to change `self.cur_offset` to each value of the palette
self.add_anim(animate.rotate(def(v) self.cur_offset = v end, 0, size(self.palette), int(duration * 1000)))
end
def animate()
@ -107,24 +119,31 @@ class Rainbow_Matrix : Leds_animator
y += 1
end
strip.show()
# advance to next color
self.cur_offset = (self.cur_offset + 1) % modulus
end
end
#-
var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Rainbow_Matrix(strip, 0.5)
r.start()
-#
class Round : Leds_animator
var cur_val
var min_val, max_val
var incr_val
var h
def init(strip)
def init(strip, glow_duration, color_duration)
super(self).init(strip)
self.cur_val = 5 << 8
self.min_val = 2 << 8
self.max_val = 6 << 8
self.incr_val = 50
self.h = 0 # start with hue = 0 (red)
# add animator for color over 30 colors
self.add_anim(animate.rotate(def(h) self.h = h end, 0, 359, int(color_duration * 1000)))
self.add_anim(animate.back_forth(def(v) self.cur_val = v end, 2 << 8, 6 << 8, int(glow_duration * 1000)))
end
def animate()
@ -136,12 +155,13 @@ class Round : Leds_animator
var w = self.strip.w
var ch = h / 2
var cw = w / 2
var col_ref = tasmota.hs2rgb(self.h)
var y = 0
while y < h
var x = 0
while x < w
var col = 0xFF0000 # red
var col = col_ref
var dist = fast_sqrt_int( ((y - ch)*(y - ch) + (x - cw)*(x - cw)) << 16)
var rel_bri = tasmota.scale_uint(dist, 0, self.cur_val, bri, 0)
set_matrix_pixel_color(strip, x, y, col, rel_bri) # simulate the method call without GETMET
@ -150,10 +170,14 @@ class Round : Leds_animator
y += 1
end
strip.show()
#
self.cur_val += self.incr_val
if self.cur_val > self.max_val self.cur_val = self.max_val self.incr_val = -self.incr_val end
if self.cur_val < self.min_val self.cur_val = self.min_val self.incr_val = -self.incr_val end
end
end
#-
var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Round(strip, 2, 30)
r.start()
-#