Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berry make Leds animate calls reentrant #22643

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
### Breaking Changed

### Changed
- Berry make Leds animate calls reentrant

### Fixed
- ESP32 rules operation priority regression from v13.3.0.4 (#22636)
Expand Down
8 changes: 8 additions & 0 deletions lib/libesp32/berry_animate/src/embedded/animate_1_core.be
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class Animate_core
self.strip.clear()
end
def start()
# check if the strip had a different animate object, stop it
var prev_animate = self.strip.get_animate()
import introspect
if (prev_animate != nil) && (type(prev_animate) == 'instance') && (prev_animate != self)
prev_animate.stop()
end
self.strip.set_animate(self)

self.running = true
var animators = self.animators
var idx = 0
Expand Down
76 changes: 50 additions & 26 deletions lib/libesp32/berry_animate/src/solidify/solidified_animate_1_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Generated code, don't edit *
\********************************************************************/
#include "be_constobj.h"
// compact class 'Animate_core' ktab size: 48, total: 98 (saved 400 bytes)
static const bvalue be_ktab_class_Animate_core[48] = {
// compact class 'Animate_core' ktab size: 52, total: 104 (saved 416 bytes)
static const bvalue be_ktab_class_Animate_core[52] = {
/* K0 */ be_nested_str_weak(stop),
/* K1 */ be_nested_str_weak(strip),
/* K2 */ be_nested_str_weak(clear),
Expand Down Expand Up @@ -51,8 +51,12 @@ static const bvalue be_ktab_class_Animate_core[48] = {
/* K43 */ be_nested_str_weak(set_cb),
/* K44 */ be_nested_str_weak(set_back_color),
/* K45 */ be_nested_str_weak(add_animator),
/* K46 */ be_nested_str_weak(start),
/* K47 */ be_nested_str_weak(add_fast_loop),
/* K46 */ be_nested_str_weak(get_animate),
/* K47 */ be_nested_str_weak(introspect),
/* K48 */ be_nested_str_weak(instance),
/* K49 */ be_nested_str_weak(set_animate),
/* K50 */ be_nested_str_weak(start),
/* K51 */ be_nested_str_weak(add_fast_loop),
};


Expand Down Expand Up @@ -716,7 +720,7 @@ be_local_closure(class_Animate_core_remove, /* name */
********************************************************************/
be_local_closure(class_Animate_core_start, /* name */
be_nested_proto(
6, /* nstack */
8, /* nstack */
1, /* argc */
10, /* varg */
0, /* has upvals */
Expand All @@ -727,27 +731,47 @@ be_local_closure(class_Animate_core_start, /* name */
&be_ktab_class_Animate_core, /* shared constants */
be_str_weak(start),
&be_const_str_solidified,
( &(const binstruction[20]) { /* code */
0x50040200, // 0000 LDBOOL R1 1 0
0x90021601, // 0001 SETMBR R0 K11 R1
0x8804010C, // 0002 GETMBR R1 R0 K12
0x58080007, // 0003 LDCONST R2 K7
0x600C000C, // 0004 GETGBL R3 G12
0x5C100200, // 0005 MOVE R4 R1
0x7C0C0200, // 0006 CALL R3 1
0x140C0403, // 0007 LT R3 R2 R3
0x780E0004, // 0008 JMPF R3 #000E
0x940C0202, // 0009 GETIDX R3 R1 R2
0x8C0C072E, // 000A GETMET R3 R3 K46
0x7C0C0200, // 000B CALL R3 1
0x0008050D, // 000C ADD R2 R2 K13
0x7001FFF5, // 000D JMP #0004
0x90022707, // 000E SETMBR R0 K19 K7
0xB80E0800, // 000F GETNGBL R3 K4
0x8C0C072F, // 0010 GETMET R3 R3 K47
0x8814010F, // 0011 GETMBR R5 R0 K15
0x7C0C0400, // 0012 CALL R3 2
0x80000000, // 0013 RET 0
( &(const binstruction[40]) { /* code */
0x88040101, // 0000 GETMBR R1 R0 K1
0x8C04032E, // 0001 GETMET R1 R1 K46
0x7C040200, // 0002 CALL R1 1
0xA40A5E00, // 0003 IMPORT R2 K47
0x4C0C0000, // 0004 LDNIL R3
0x200C0203, // 0005 NE R3 R1 R3
0x780E0008, // 0006 JMPF R3 #0010
0x600C0004, // 0007 GETGBL R3 G4
0x5C100200, // 0008 MOVE R4 R1
0x7C0C0200, // 0009 CALL R3 1
0x1C0C0730, // 000A EQ R3 R3 K48
0x780E0003, // 000B JMPF R3 #0010
0x200C0200, // 000C NE R3 R1 R0
0x780E0001, // 000D JMPF R3 #0010
0x8C0C0300, // 000E GETMET R3 R1 K0
0x7C0C0200, // 000F CALL R3 1
0x880C0101, // 0010 GETMBR R3 R0 K1
0x8C0C0731, // 0011 GETMET R3 R3 K49
0x5C140000, // 0012 MOVE R5 R0
0x7C0C0400, // 0013 CALL R3 2
0x500C0200, // 0014 LDBOOL R3 1 0
0x90021603, // 0015 SETMBR R0 K11 R3
0x880C010C, // 0016 GETMBR R3 R0 K12
0x58100007, // 0017 LDCONST R4 K7
0x6014000C, // 0018 GETGBL R5 G12
0x5C180600, // 0019 MOVE R6 R3
0x7C140200, // 001A CALL R5 1
0x14140805, // 001B LT R5 R4 R5
0x78160004, // 001C JMPF R5 #0022
0x94140604, // 001D GETIDX R5 R3 R4
0x8C140B32, // 001E GETMET R5 R5 K50
0x7C140200, // 001F CALL R5 1
0x0010090D, // 0020 ADD R4 R4 K13
0x7001FFF5, // 0021 JMP #0018
0x90022707, // 0022 SETMBR R0 K19 K7
0xB8160800, // 0023 GETNGBL R5 K4
0x8C140B33, // 0024 GETMET R5 R5 K51
0x881C010F, // 0025 GETMBR R7 R0 K15
0x7C140400, // 0026 CALL R5 2
0x80000000, // 0027 RET 0
})
)
);
Expand Down
1 change: 0 additions & 1 deletion lib/libesp32/berry_tasmota/src/be_leds_ntv_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extern int be_leds_apply_bri_gamma(bvm *vm);
/* @const_object_info_begin
class be_class_Leds_ntv (scope: global, name: Leds_ntv, strings: weak) {
_p, var
_t, var

WS2812_GRB, int(ws2812_grb)
SK6812_GRBW, int(sk6812_grbw)
Expand Down
36 changes: 31 additions & 5 deletions lib/libesp32/berry_tasmota/src/embedded/leds.be
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,51 @@ class Leds : Leds_ntv
var gamma # if true, apply gamma (true is default)
var leds # number of leds
var bri # implicit brightness for this led strip (0..255, default is 50% = 127)
var animate # attached animate object or nil - this allows to stop any existing animation for this strip if we add a new animate
# leds:int = number of leds of the strip
# gpio:int (optional) = GPIO for NeoPixel. If not specified, takes the WS2812 gpio
# typ:int (optional) = Type of LED, defaults to WS2812 RGB
# hardware:int (optional) = hardware support (Leds.RMT, Leds.SPI)
def init(leds, gpio_phy, typ, hardware)
import gpio
self.gamma = true # gamma is enabled by default, it should be disabled explicitly if needed
if (gpio_phy == nil) || (gpio_phy == gpio.pin(gpio.WS2812, 0))
if (leds == nil ) || (gpio_phy == nil) || (gpio_phy == gpio.pin(gpio.WS2812, 0))
# use native driver
self.ctor() # no parameters
# in such case, `self._p` is equal to `0`
self.leds = self.pixel_count()
import light
self.bri = light.get()['bri']
else
# use pure Berry driver
self.leds = int(leds)
leds = int(leds)
self.leds = leds
self.bri = 127 # 50% brightness by default

# initialize the structure
self.ctor(self.leds, gpio_phy, typ, hardware)
# check if already in global `_lhw`
if !global.contains('_lhw')
global._lhw = {}
end
if global._lhw.find(leds) != nil
# an object already exists, attach it
var prov_led = global._lhw.find(leds) # already provisioned leds instance
if self.leds != prov_led.leds
raise "value_error", f"number of leds do not match with previous instanciation {self.leds} vs {prov_led.leds}"
end
self._p = prov_led._p
self.animate = prov_led.animate
global._lhw[leds] = self # put the most recent as current
else
self.ctor(leds, gpio_phy, typ, hardware)
global._lhw[leds] = self
# call begin
self.begin()
end
end

if self._p == nil raise "internal_error", "couldn't not initialize noepixelbus" end

# call begin
self.begin()
end

def clear()
Expand All @@ -71,6 +90,13 @@ class Leds : Leds_ntv
return self.bri
end

def set_animate(animate)
self.animate = animate
end
def get_animate()
return self.animate
end

def ctor(leds, gpio_phy, typ, hardware)
if gpio_phy == nil
self.call_native(0) # native driver
Expand Down
Loading
Loading