From fe9ff2f1a590e52599f038fe548baaa4488b2e67 Mon Sep 17 00:00:00 2001 From: Allen Schober Date: Thu, 1 Jan 2026 13:15:41 -0500 Subject: [PATCH] Fix Breathe animation to support ValueProviders passed for color (#24284) * Fix Breathe animation to support ValueProviders passed for color * Add tests --------- Co-authored-by: s-hadinger <49731213+s-hadinger@users.noreply.github.com> --- .../berry_animation/src/animations/breathe.be | 2 +- .../src/tests/breathe_animation_test.be | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/libesp32/berry_animation/src/animations/breathe.be b/lib/libesp32/berry_animation/src/animations/breathe.be index abf39ab27..645939e8d 100644 --- a/lib/libesp32/berry_animation/src/animations/breathe.be +++ b/lib/libesp32/berry_animation/src/animations/breathe.be @@ -46,7 +46,7 @@ class BreatheAnimation : animation.animation if name == "color" # When color is set, update the breathe_provider's base_color # but keep the breathe_provider as the actual color source for rendering - if type(value) == 'int' + if type(value) == 'int' || animation.is_value_provider(value) self.breathe_provider.base_color = value # Restore the breathe_provider as the color source (bypass on_param_changed) self.values["color"] = self.breathe_provider diff --git a/lib/libesp32/berry_animation/src/tests/breathe_animation_test.be b/lib/libesp32/berry_animation/src/tests/breathe_animation_test.be index 1144b6f3a..903521a9f 100644 --- a/lib/libesp32/berry_animation/src/tests/breathe_animation_test.be +++ b/lib/libesp32/berry_animation/src/tests/breathe_animation_test.be @@ -50,6 +50,15 @@ red_breathe.period = 3000 red_breathe.curve_factor = 2 print(f"Red breathe animation color: 0x{red_breathe.breathe_provider.base_color :08x}") +# Create green breathe animation with color as a closure value provider +var green_breathe = animation.breathe_animation(engine) +green_breathe.color = animation.create_closure_value(engine, def (engine) return 0xFF00FF00 end) +green_breathe.min_brightness = 10 +green_breathe.max_brightness = 180 +green_breathe.period = 3000 +green_breathe.curve_factor = 2 +print(f"Green breathe animation color: {green_breathe.breathe_provider.base_color}") + # Test parameter updates using virtual member assignment blue_breathe.min_brightness = 30 blue_breathe.max_brightness = 220 @@ -133,6 +142,8 @@ print("✓ Animation added to engine successfully") assert(anim != nil, "Default breathe animation should be created") assert(blue_breathe != nil, "Custom breathe animation should be created") assert(red_breathe != nil, "Red breathe animation should be created") +assert(green_breathe != nil, "Green breathe animation should be created") +assert(animation.is_value_provider(green_breathe.breathe_provider.base_color), "Green breathe should have color as a value provider") assert(blue_breathe.breathe_provider.base_color == 0xFF0000FF, "Blue breathe should have correct color") assert(blue_breathe.min_brightness == 30, "Min brightness should be updated to 30") assert(blue_breathe.max_brightness == 220, "Max brightness should be updated to 220")