Skip to content

Commit b5ac09d

Browse files
authored
Berry animation template system and performance improvements (#24086)
1 parent 5025715 commit b5ac09d

File tree

85 files changed

+21575
-21520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+21575
-21520
lines changed

lib/libesp32/berry_animation/anim_examples/compiled/compilation_summary.md

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,12 @@ SUCCESS
182182

183183
## Symbol Table
184184

185-
| Symbol | Type | Builtin | Dangerous | Takes Args |
186-
|----------------|----------|---------|-----------|------------|
187-
| `cylon_effect` | template | | | |
188-
| `red` | color || | |
189-
| `transparent` | color || | |
185+
| Symbol | Type | Builtin | Dangerous | Takes Args |
186+
|---------------|-----------------------|---------|-----------|------------|
187+
| `cylon_red` | animation | | | |
188+
| `cylon` | animation_constructor | | ||
189+
| `red` | color || | |
190+
| `transparent` | color || | |
190191

191192
### Compilation Output
192193

@@ -286,10 +287,11 @@ SUCCESS
286287

287288
## Symbol Table
288289

289-
| Symbol | Type | Builtin | Dangerous | Takes Args |
290-
|----------------------|----------|---------|-----------|------------|
291-
| `rainbow_with_white` | palette | | | |
292-
| `shutter_bidir` | template | | | |
290+
| Symbol | Type | Builtin | Dangerous | Takes Args |
291+
|----------------------|-----------------------|---------|-----------|------------|
292+
| `main` | animation | | | |
293+
| `rainbow_with_white` | palette | | | |
294+
| `shutter_bidir` | animation_constructor | | ||
293295

294296
### Compilation Output
295297

@@ -303,17 +305,18 @@ SUCCESS
303305

304306
## Symbol Table
305307

306-
| Symbol | Type | Builtin | Dangerous | Takes Args |
307-
|----------------------|----------|---------|-----------|------------|
308-
| `blue` | color || | |
309-
| `green` | color || | |
310-
| `indigo` | color || | |
311-
| `orange` | color || | |
312-
| `rainbow_with_white` | palette | | | |
313-
| `red` | color || | |
314-
| `shutter_central` | template | | | |
315-
| `white` | color || | |
316-
| `yellow` | color || | |
308+
| Symbol | Type | Builtin | Dangerous | Takes Args |
309+
|----------------------|-----------------------|---------|-----------|------------|
310+
| `blue` | color || | |
311+
| `green` | color || | |
312+
| `indigo` | color || | |
313+
| `main` | animation | | | |
314+
| `orange` | color || | |
315+
| `rainbow_with_white` | palette | | | |
316+
| `red` | color || | |
317+
| `shutter_central` | animation_constructor | | ||
318+
| `white` | color || | |
319+
| `yellow` | color || | |
317320

318321
### Compilation Output
319322

@@ -327,17 +330,18 @@ SUCCESS
327330

328331
## Symbol Table
329332

330-
| Symbol | Type | Builtin | Dangerous | Takes Args |
331-
|----------------------|----------|---------|-----------|------------|
332-
| `blue` | color || | |
333-
| `green` | color || | |
334-
| `indigo` | color || | |
335-
| `orange` | color || | |
336-
| `rainbow_with_white` | palette | | | |
337-
| `red` | color || | |
338-
| `shutter_lr` | template | | | |
339-
| `white` | color || | |
340-
| `yellow` | color || | |
333+
| Symbol | Type | Builtin | Dangerous | Takes Args |
334+
|----------------------|-----------------------|---------|-----------|------------|
335+
| `blue` | color || | |
336+
| `green` | color || | |
337+
| `indigo` | color || | |
338+
| `main` | animation | | | |
339+
| `orange` | color || | |
340+
| `rainbow_with_white` | palette | | | |
341+
| `red` | color || | |
342+
| `shutter_lr` | animation_constructor | | ||
343+
| `white` | color || | |
344+
| `yellow` | color || | |
341345

342346
### Compilation Output
343347

@@ -1000,9 +1004,9 @@ SUCCESS
10001004

10011005
## Symbol Table
10021006

1003-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1004-
|----------------|----------|---------|-----------|------------|
1005-
| `cylon_effect` | template | | | |
1007+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1008+
|----------------|-----------------------|---------|-----------|------------|
1009+
| `cylon_effect` | animation_constructor | | | |
10061010

10071011
### Compilation Output
10081012

@@ -1016,11 +1020,12 @@ SUCCESS
10161020

10171021
## Symbol Table
10181022

1019-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1020-
|-----------------|----------|---------|-----------|------------|
1021-
| `fire_palette` | palette | | | |
1022-
| `ocean_palette` | palette | | | |
1023-
| `rainbow_pulse` | template | | | |
1023+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1024+
|-----------------|-----------------------|---------|-----------|------------|
1025+
| `fire_palette` | palette | | | |
1026+
| `main` | animation | | | |
1027+
| `ocean_palette` | palette | | | |
1028+
| `rainbow_pulse` | animation_constructor | | ||
10241029

10251030
### Compilation Output
10261031

@@ -1055,17 +1060,18 @@ SUCCESS
10551060

10561061
## Symbol Table
10571062

1058-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1059-
|----------------------|----------|---------|-----------|------------|
1060-
| `blue` | color || | |
1061-
| `green` | color || | |
1062-
| `indigo` | color || | |
1063-
| `orange` | color || | |
1064-
| `rainbow_with_white` | palette | | | |
1065-
| `red` | color || | |
1066-
| `shutter_bidir` | template | | | |
1067-
| `white` | color || | |
1068-
| `yellow` | color || | |
1063+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1064+
|----------------------|-----------------------|---------|-----------|------------|
1065+
| `blue` | color || | |
1066+
| `green` | color || | |
1067+
| `indigo` | color || | |
1068+
| `main` | animation | | | |
1069+
| `orange` | color || | |
1070+
| `rainbow_with_white` | palette | | | |
1071+
| `red` | color || | |
1072+
| `shutter_bidir` | animation_constructor | | ||
1073+
| `white` | color || | |
1074+
| `yellow` | color || | |
10691075

10701076
### Compilation Output
10711077

@@ -1079,17 +1085,18 @@ SUCCESS
10791085

10801086
## Symbol Table
10811087

1082-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1083-
|----------------------|----------|---------|-----------|------------|
1084-
| `blue` | color || | |
1085-
| `green` | color || | |
1086-
| `indigo` | color || | |
1087-
| `orange` | color || | |
1088-
| `rainbow_with_white` | palette | | | |
1089-
| `red` | color || | |
1090-
| `shutter_central` | template | | | |
1091-
| `white` | color || | |
1092-
| `yellow` | color || | |
1088+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1089+
|----------------------|-----------------------|---------|-----------|------------|
1090+
| `blue` | color || | |
1091+
| `green` | color || | |
1092+
| `indigo` | color || | |
1093+
| `main` | animation | | | |
1094+
| `orange` | color || | |
1095+
| `rainbow_with_white` | palette | | | |
1096+
| `red` | color || | |
1097+
| `shutter_central` | animation_constructor | | ||
1098+
| `white` | color || | |
1099+
| `yellow` | color || | |
10931100

10941101
### Compilation Output
10951102

@@ -1142,10 +1149,11 @@ SUCCESS
11421149

11431150
## Symbol Table
11441151

1145-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1146-
|----------------|----------|---------|-----------|------------|
1147-
| `pulse_effect` | template | | | |
1148-
| `red` | color || | |
1152+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1153+
|----------------|-----------------------|---------|-----------|------------|
1154+
| `main` | animation | | | |
1155+
| `pulse_effect` | animation_constructor | | ||
1156+
| `red` | color || | |
11491157

11501158
### Compilation Output
11511159

@@ -1159,10 +1167,11 @@ SUCCESS
11591167

11601168
## Symbol Table
11611169

1162-
| Symbol | Type | Builtin | Dangerous | Takes Args |
1163-
|----------------|----------|---------|-----------|------------|
1164-
| `pulse_effect` | template | | | |
1165-
| `red` | color || | |
1170+
| Symbol | Type | Builtin | Dangerous | Takes Args |
1171+
|----------------|-----------------------|---------|-----------|------------|
1172+
| `main` | animation | | | |
1173+
| `pulse_effect` | animation_constructor | | ||
1174+
| `red` | color || | |
11661175

11671176
### Compilation Output
11681177

lib/libesp32/berry_animation/anim_examples/compiled/cylon_generic.be

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,62 @@ import animation
88

99
# Cylon Red Eye
1010
# Automatically adapts to the length of the strip
11-
# Template function: cylon_effect
12-
def cylon_effect_template(engine, eye_color_, back_color_, duration_)
13-
var strip_len_ = animation.strip_length(engine)
14-
var eye_animation_ = animation.beacon_animation(engine)
15-
eye_animation_.color = eye_color_
16-
eye_animation_.back_color = back_color_
17-
eye_animation_.pos = (def (engine)
18-
var provider = animation.cosine_osc(engine)
19-
provider.min_value = (-1)
20-
provider.max_value = animation.create_closure_value(engine, def (engine) return animation.resolve(strip_len_) - 2 end)
21-
provider.duration = duration_
22-
return provider
23-
end)(engine)
24-
eye_animation_.beacon_size = 3 # small 3 pixels eye
25-
eye_animation_.slew_size = 2 # with 2 pixel shading around
26-
eye_animation_.priority = 5
27-
engine.add(eye_animation_)
28-
end
11+
# Template animation class: cylon
12+
class cylon_animation : animation.engine_proxy
13+
static var PARAMS = animation.enc_params({
14+
"eye_color": {"type": "color"},
15+
"back_color": {"type": "color"},
16+
"period": {"type": "time"}
17+
})
18+
19+
# Template setup method - overrides EngineProxy placeholder
20+
def setup_template()
21+
var engine = self # using 'self' as a proxy to engine object (instead of 'self.engine')
2922

30-
animation.register_user_function('cylon_effect', cylon_effect_template)
23+
var strip_len_ = animation.strip_length(engine)
24+
var eye_animation_ = animation.beacon_animation(engine)
25+
eye_animation_.color = animation.create_closure_value(engine, def (engine) return self.eye_color end)
26+
eye_animation_.back_color = animation.create_closure_value(engine, def (engine) return self.back_color end)
27+
eye_animation_.pos = (def (engine)
28+
var provider = animation.cosine_osc(engine)
29+
provider.min_value = (-1)
30+
provider.max_value = animation.create_closure_value(engine, def (engine) return animation.resolve(strip_len_) - 2 end)
31+
provider.duration = animation.create_closure_value(engine, def (engine) return self.period end)
32+
return provider
33+
end)(engine)
34+
eye_animation_.beacon_size = 3 # small 3 pixels eye
35+
eye_animation_.slew_size = 2 # with 2 pixel shading around
36+
eye_animation_.priority = 5
37+
self.add(eye_animation_)
38+
end
39+
end
3140

3241
# Auto-generated strip initialization (using Tasmota configuration)
3342
var engine = animation.init_strip()
3443

35-
cylon_effect_template(engine, 0xFFFF0000, 0x00000000, 3000)
44+
var cylon_red_ = cylon_animation(engine)
45+
cylon_red_.eye_color = 0xFFFF0000
46+
cylon_red_.back_color = 0x00000000
47+
cylon_red_.period = 3000
48+
engine.add(cylon_red_)
3649
engine.run()
3750

3851

3952
#- Original DSL source:
4053
# Cylon Red Eye
4154
# Automatically adapts to the length of the strip
4255
43-
template cylon_effect {
56+
template animation cylon {
4457
param eye_color type color
4558
param back_color type color
46-
param duration
59+
param period type time
4760
4861
set strip_len = strip_length()
4962
5063
animation eye_animation = beacon_animation(
5164
color = eye_color
5265
back_color = back_color
53-
pos = cosine_osc(min_value = -1, max_value = strip_len - 2, duration = duration)
66+
pos = cosine_osc(min_value = -1, max_value = strip_len - 2, duration = period)
5467
beacon_size = 3 # small 3 pixels eye
5568
slew_size = 2 # with 2 pixel shading around
5669
priority = 5
@@ -59,6 +72,7 @@ template cylon_effect {
5972
run eye_animation
6073
}
6174
62-
cylon_effect(red, transparent, 3s)
75+
animation cylon_red = cylon(eye_color = red, back_color = transparent, period = 3s)
76+
run cylon_red
6377
6478
-#

0 commit comments

Comments
 (0)