Skip to content

Commit 123cb8e

Browse files
authored
Berry animation remove strip from DSL (arendst#23817)
1 parent 81be80b commit 123cb8e

23 files changed

Lines changed: 4102 additions & 4062 deletions

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# DSL Compilation Report
22

3-
Generated: Ven 1 aoû 2025 18:49:41 CEST
3+
Generated: Sam 23 aoû 2025 10:30:34 CEST
44

55
## Summary
66

7-
- **Total files**: 25
8-
- **Successfully compiled**: 25
7+
- **Total files**: 24
8+
- **Successfully compiled**: 24
99
- **Failed to compile**: 0
1010
- **Success rate**: 100%
1111

@@ -27,7 +27,6 @@ Generated: Ven 1 aoû 2025 18:49:41 CEST
2727
- ✅ ocean_waves.anim
2828
- ✅ palette_demo.anim
2929
- ✅ palette_showcase.anim
30-
- ✅ pattern_animation_demo.anim
3130
- ✅ plasma_wave.anim
3231
- ✅ police_lights.anim
3332
- ✅ property_assignment_demo.anim

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
# # Dark background
1515
# color matrix_bg = 0x000000
16-
# animation background = solid(color=matrix_bg)
16+
# animation background = solid(color=matrix_bg, priority=50)
1717
#
1818
# # Define matrix green palette
1919
# palette matrix_greens = [
@@ -29,33 +29,34 @@
2929
# animation stream1 = comet_animation(
3030
# color=stream1_pattern, # color source
3131
# tail_length=15, # long tail
32-
# speed=1.5s # speed
32+
# speed=1.5s, # speed
33+
# priority = 10
3334
# )
34-
# stream1.priority = 10
35+
#
3536
#
3637
# color stream2_pattern = rich_palette(palette=matrix_greens, cycle_period=1.8s, transition_type=LINEAR, brightness=200)
3738
# animation stream2 = comet_animation(
3839
# color=stream2_pattern, # color source
3940
# tail_length=12, # medium tail
40-
# speed=2.2s # different speed
41+
# speed=2.2s, # different speed
42+
# priority = 8
4143
# )
42-
# stream2.priority = 8
4344
#
4445
# color stream3_pattern = rich_palette(palette=matrix_greens, cycle_period=2.5s, transition_type=LINEAR, brightness=180)
4546
# animation stream3 = comet_animation(
4647
# color=stream3_pattern, # color source
4748
# tail_length=10, # shorter tail
48-
# speed=1.8s # another speed
49+
# speed=1.8s, # another speed
50+
# priority = 6
4951
# )
50-
# stream3.priority = 6
5152
#
5253
# # Add random bright flashes (like code highlights)
5354
# animation code_flash = twinkle_animation(
5455
# color=0x00FFAA, # Bright cyan-green
5556
# density=3, # density (few flashes)
56-
# twinkle_speed=150ms # twinkle speed (quick flash)
57+
# twinkle_speed=150ms, # twinkle speed (quick flash)
58+
# priority = 20
5759
# )
58-
# code_flash.priority = 20
5960
#
6061
# # Start all animations
6162
# run background
@@ -76,6 +77,7 @@ var engine = animation.init_strip()
7677
var matrix_bg_ = 0xFF000000
7778
var background_ = animation.solid(engine)
7879
background_.color = animation.global('matrix_bg_', 'matrix_bg')
80+
background_.priority = 50
7981
# Define matrix green palette
8082
var matrix_greens_ = bytes("00000000" "40003300" "80006600" "C000AA00" "FF00FF00")
8183
# Create multiple cascading streams
@@ -87,8 +89,8 @@ stream1_pattern_.brightness = 255
8789
var stream1_ = animation.comet_animation(engine)
8890
stream1_.color = animation.global('stream1_pattern_', 'stream1_pattern')
8991
stream1_.tail_length = 15
90-
stream1_.speed = 1500 # speed
91-
animation.global('stream1_').priority = 10
92+
stream1_.speed = 1500
93+
stream1_.priority = 10
9294
var stream2_pattern_ = animation.rich_palette(engine)
9395
stream2_pattern_.palette = animation.global('matrix_greens_', 'matrix_greens')
9496
stream2_pattern_.cycle_period = 1800
@@ -97,8 +99,8 @@ stream2_pattern_.brightness = 200
9799
var stream2_ = animation.comet_animation(engine)
98100
stream2_.color = animation.global('stream2_pattern_', 'stream2_pattern')
99101
stream2_.tail_length = 12
100-
stream2_.speed = 2200 # different speed
101-
animation.global('stream2_').priority = 8
102+
stream2_.speed = 2200
103+
stream2_.priority = 8
102104
var stream3_pattern_ = animation.rich_palette(engine)
103105
stream3_pattern_.palette = animation.global('matrix_greens_', 'matrix_greens')
104106
stream3_pattern_.cycle_period = 2500
@@ -107,14 +109,14 @@ stream3_pattern_.brightness = 180
107109
var stream3_ = animation.comet_animation(engine)
108110
stream3_.color = animation.global('stream3_pattern_', 'stream3_pattern')
109111
stream3_.tail_length = 10
110-
stream3_.speed = 1800 # another speed
111-
animation.global('stream3_').priority = 6
112+
stream3_.speed = 1800
113+
stream3_.priority = 6
112114
# Add random bright flashes (like code highlights)
113115
var code_flash_ = animation.twinkle_animation(engine)
114116
code_flash_.color = 0xFF00FFAA
115117
code_flash_.density = 3
116-
code_flash_.twinkle_speed = 150 # twinkle speed (quick flash)
117-
animation.global('code_flash_').priority = 20
118+
code_flash_.twinkle_speed = 150
119+
code_flash_.priority = 20
118120
# Start all animations
119121
# Start all animations/sequences
120122
if global.contains('sequence_background')

lib/libesp32/berry_animation/anim_examples/compiled/run_successful_tests.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,6 @@ else
154154
fi
155155
((TOTAL_COUNT++))
156156

157-
echo -n "Testing pattern_animation_demo.be... "
158-
if $BERRY_CMD "$COMPILED_DIR/pattern_animation_demo.be" > /dev/null 2>&1; then
159-
echo ""
160-
((SUCCESS_COUNT++))
161-
else
162-
echo ""
163-
fi
164-
((TOTAL_COUNT++))
165-
166157
echo -n "Testing plasma_wave.be... "
167158
if $BERRY_CMD "$COMPILED_DIR/plasma_wave.be" > /dev/null 2>&1; then
168159
echo ""

lib/libesp32/berry_animation/anim_examples/compiled/run_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
set -e
66

7-
BERRY_CMD="./berry -s -g -m lib/libesp32/berry_animation -e 'import tasmota'"
8-
COMPILED_DIR="anim_examples/compiled"
7+
BERRY_CMD="./berry -s -g -m lib/libesp32/berry_animation/src -e 'import tasmota'"
8+
COMPILED_DIR="lib/libesp32/berry_animation/anim_examples/compiled"
99

1010
echo "Running compiled DSL examples..."
1111
echo "==============================="

lib/libesp32/berry_animation/anim_examples/matrix_rain.anim

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Dark background
77
color matrix_bg = 0x000000
8-
animation background = solid(color=matrix_bg)
8+
animation background = solid(color=matrix_bg, priority=50)
99

1010
# Define matrix green palette
1111
palette matrix_greens = [
@@ -21,33 +21,34 @@ color stream1_pattern = rich_palette(palette=matrix_greens, cycle_period=2s, tra
2121
animation stream1 = comet_animation(
2222
color=stream1_pattern, # color source
2323
tail_length=15, # long tail
24-
speed=1.5s # speed
24+
speed=1.5s, # speed
25+
priority = 10
2526
)
26-
stream1.priority = 10
27+
2728

2829
color stream2_pattern = rich_palette(palette=matrix_greens, cycle_period=1.8s, transition_type=LINEAR, brightness=200)
2930
animation stream2 = comet_animation(
3031
color=stream2_pattern, # color source
3132
tail_length=12, # medium tail
32-
speed=2.2s # different speed
33+
speed=2.2s, # different speed
34+
priority = 8
3335
)
34-
stream2.priority = 8
3536

3637
color stream3_pattern = rich_palette(palette=matrix_greens, cycle_period=2.5s, transition_type=LINEAR, brightness=180)
3738
animation stream3 = comet_animation(
3839
color=stream3_pattern, # color source
3940
tail_length=10, # shorter tail
40-
speed=1.8s # another speed
41+
speed=1.8s, # another speed
42+
priority = 6
4143
)
42-
stream3.priority = 6
4344

4445
# Add random bright flashes (like code highlights)
4546
animation code_flash = twinkle_animation(
4647
color=0x00FFAA, # Bright cyan-green
4748
density=3, # density (few flashes)
48-
twinkle_speed=150ms # twinkle speed (quick flash)
49+
twinkle_speed=150ms, # twinkle speed (quick flash)
50+
priority = 20
4951
)
50-
code_flash.priority = 20
5152

5253
# Start all animations
5354
run background

lib/libesp32/berry_animation/docs/DSL_REFERENCE.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Comments use the `#` character and extend to the end of the line:
1212

1313
```dsl
1414
# This is a full-line comment
15-
strip length 30 # This is an inline comment
15+
# strip length 30 # This is an inline comment (TEMPORARILY DISABLED)
16+
color red = #FF0000 # This is an inline comment
1617
```
1718

1819
Comments are preserved in the generated code and can appear anywhere in the DSL.
@@ -22,8 +23,8 @@ Comments are preserved in the generated code and can appear anywhere in the DSL.
2223
A DSL program consists of statements that can appear in any order:
2324

2425
```dsl
25-
# Optional strip configuration (must be first if present)
26-
strip length 60
26+
# Strip configuration is handled automatically
27+
# strip length 60 # TEMPORARILY DISABLED
2728
2829
# Color definitions
2930
color red = #FF0000
@@ -52,7 +53,7 @@ run demo
5253
The following keywords are reserved and cannot be used as identifiers:
5354

5455
**Configuration Keywords:**
55-
- `strip` - Strip configuration
56+
- `strip` - Strip configuration (temporarily disabled, reserved keyword)
5657
- `set` - Variable assignment
5758

5859
**Definition Keywords:**
@@ -179,13 +180,15 @@ Color123 # Valid identifier
179180

180181
### Strip Configuration
181182

182-
The `strip` statement configures the LED strip and must be the first statement if present:
183+
**Note: The `strip` directive is temporarily disabled.** Strip configuration is handled automatically by the host system.
184+
185+
~~The `strip` statement configures the LED strip and must be the first statement if present:~~
183186

184187
```dsl
185-
strip length 60 # Set strip length to 60 LEDs
188+
# strip length 60 # TEMPORARILY DISABLED
186189
```
187190

188-
If omitted, the system uses the configured strip length from the host system.
191+
~~If omitted,~~ The system uses the configured strip length from the host system.
189192

190193
### Variable Assignment
191194

@@ -578,8 +581,8 @@ statement = config_stmt
578581
| execution_stmt ;
579582
580583
(* Configuration *)
581-
config_stmt = strip_config | variable_assignment ;
582-
strip_config = "strip" "length" number ;
584+
config_stmt = variable_assignment ;
585+
(* strip_config = "strip" "length" number ; -- TEMPORARILY DISABLED *)
583586
variable_assignment = "set" identifier "=" expression ;
584587
585588
(* Definitions *)

lib/libesp32/berry_animation/src/animation.be

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ register_to_animation(rich_palette_animation)
156156

157157
# Function called to initialize the `Leds` and `engine` objects
158158
#
159+
# It keeps track of previously created engines and strips to reuse
160+
# when called with the same arguments
161+
#
159162
# Parameters:
160163
# l - list of arguments (vararg)
161164
#
@@ -164,8 +167,24 @@ register_to_animation(rich_palette_animation)
164167
def animation_init_strip(*l)
165168
import global
166169
import animation
167-
var strip = call(global.Leds, l) # call global.Leds() with vararg
168-
var engine = animation.create_engine(strip)
170+
import introspect
171+
# we keep a hash of strip configurations to reuse existing engines
172+
if !introspect.contains(animation, "_engines")
173+
animation._engines = {}
174+
end
175+
176+
var l_as_string = str(l)
177+
var engine = animation._engines.find(l_as_string)
178+
if (engine != nil)
179+
# we reuse it
180+
engine.stop()
181+
engine.clear()
182+
else
183+
var strip = call(global.Leds, l) # call global.Leds() with vararg
184+
engine = animation.create_engine(strip)
185+
animation._engines[l_as_string] = engine
186+
end
187+
169188
return engine
170189
end
171190
animation.init_strip = animation_init_strip

lib/libesp32/berry_animation/src/dsl/transpiler.be

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,10 @@ class SimpleDSLTranspiler
102102
# Handle keywords
103103
if tok.type == animation_dsl.Token.KEYWORD
104104
if tok.value == "strip"
105-
if !is_first_real_statement
106-
self.error("'strip' declaration must be the first statement")
107-
self.skip_statement()
108-
return
109-
end
110-
self.process_strip()
105+
# Strip directive is temporarily disabled but remains a reserved keyword
106+
self.error("'strip' directive is temporarily disabled. Strip configuration is handled automatically.")
107+
self.skip_statement()
108+
return
111109
else
112110
# For any other statement, ensure strip is initialized
113111
if !self.strip_initialized
@@ -324,16 +322,17 @@ class SimpleDSLTranspiler
324322
end
325323

326324
# Process strip configuration: strip length 60
327-
def process_strip()
328-
self.next() # skip 'strip'
329-
var prop = self.expect_identifier()
330-
if prop == "length"
331-
var length = self.expect_number()
332-
var inline_comment = self.collect_inline_comment()
333-
self.add(f"var engine = animation.init_strip({length}){inline_comment}")
334-
self.strip_initialized = true # Mark that strip was initialized
335-
end
336-
end
325+
# Temporarily disabled
326+
# def process_strip()
327+
# self.next() # skip 'strip'
328+
# var prop = self.expect_identifier()
329+
# if prop == "length"
330+
# var length = self.expect_number()
331+
# var inline_comment = self.collect_inline_comment()
332+
# self.add(f"var engine = animation.init_strip({length}){inline_comment}")
333+
# self.strip_initialized = true # Mark that strip was initialized
334+
# end
335+
# end
337336

338337
# Process variable assignment: set brightness = 80%
339338
def process_set()

0 commit comments

Comments
 (0)