From c1f8ee5dbb0371c769fced9b4f8e386b84c6521a Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Thu, 14 Dec 2023 20:13:17 +0100 Subject: [PATCH] Refactoring of Berry `animate` module for WS2812 Leds (#20236) --- CHANGELOG.md | 1 + lib/libesp32/berry/default/be_modtab.c | 9 +- .../berry_tasmota/src/be_animate_lib.c | 7 - .../berry_tasmota/src/be_animate_module.c | 197 ++ .../src/be_leds_animator_class.c | 9 - .../berry_tasmota/src/be_leds_pulse_class.c | 9 - .../berry_tasmota/src/be_tasmota_lib.c | 2 + .../{leds_0_animator.be => animate_0_core.be} | 17 +- ...ffects.be => animate_1_animate_effects.be} | 48 +- .../src/embedded/animate_9_module.be | 508 +++++ .../src/embedded/animate_module.be | 573 ------ ...animator.h => solidified_animate_0_core.h} | 159 +- ...=> solidified_animate_1_animate_effects.h} | 114 +- ...module.h => solidified_animate_9_module.h} | 1640 ++++++++--------- .../animate_demo_palette_background.be | 11 + .../berry/animate_demo/animate_demo_pulse.be | 23 + tasmota/berry/animate_demo/leds_animation.be | 173 ++ tasmota/berry/animate_demo/leds_blend_demo.be | 37 + tasmota/berry/emulator/Leds_frame.be | 42 + .../leds_animate_demo_palette_background.be | 51 - tasmota/berry/leds/rainbow.be | 185 -- .../xdrv_52_3_berry_tasmota.ino | 55 + 22 files changed, 1993 insertions(+), 1877 deletions(-) delete mode 100644 lib/libesp32/berry_tasmota/src/be_animate_lib.c create mode 100644 lib/libesp32/berry_tasmota/src/be_animate_module.c delete mode 100644 lib/libesp32/berry_tasmota/src/be_leds_animator_class.c delete mode 100644 lib/libesp32/berry_tasmota/src/be_leds_pulse_class.c rename lib/libesp32/berry_tasmota/src/embedded/{leds_0_animator.be => animate_0_core.be} (94%) rename lib/libesp32/berry_tasmota/src/embedded/{leds_1_animate_effects.be => animate_1_animate_effects.be} (82%) create mode 100644 lib/libesp32/berry_tasmota/src/embedded/animate_9_module.be delete mode 100644 lib/libesp32/berry_tasmota/src/embedded/animate_module.be rename lib/libesp32/berry_tasmota/src/solidify/{solidified_leds_0_animator.h => solidified_animate_0_core.h} (85%) rename lib/libesp32/berry_tasmota/src/solidify/{solidified_leds_1_animate_effects.h => solidified_animate_1_animate_effects.h} (89%) rename lib/libesp32/berry_tasmota/src/solidify/{solidified_animate_module.h => solidified_animate_9_module.h} (60%) create mode 100644 tasmota/berry/animate_demo/animate_demo_palette_background.be create mode 100644 tasmota/berry/animate_demo/animate_demo_pulse.be create mode 100644 tasmota/berry/animate_demo/leds_animation.be create mode 100644 tasmota/berry/animate_demo/leds_blend_demo.be create mode 100644 tasmota/berry/emulator/Leds_frame.be delete mode 100644 tasmota/berry/leds/leds_animate_demo_palette_background.be delete mode 100644 tasmota/berry/leds/rainbow.be diff --git a/CHANGELOG.md b/CHANGELOG.md index 1978a41f460d..2a77974ef4c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Added ### Breaking Changed +- Refactoring of Berry `animate` module for WS2812 Leds ### Changed diff --git a/lib/libesp32/berry/default/be_modtab.c b/lib/libesp32/berry/default/be_modtab.c index 0333db5ea503..a4e7c7a339e9 100644 --- a/lib/libesp32/berry/default/be_modtab.c +++ b/lib/libesp32/berry/default/be_modtab.c @@ -146,7 +146,10 @@ BERRY_LOCAL const bntvmodule_t* const be_module_table[] = { #ifdef USE_UNISHOX_COMPRESSION &be_native_module(unishox), #endif // USE_UNISHOX_COMPRESSION + +#ifdef USE_WS2812 &be_native_module(animate), +#endif // USE_WS2812 #ifdef USE_LVGL &be_native_module(lv), @@ -206,10 +209,7 @@ be_extern_native_class(AXP192); be_extern_native_class(AXP202); be_extern_native_class(OneWire); be_extern_native_class(Leds_ntv); -be_extern_native_class(Leds_frame); be_extern_native_class(Leds); -be_extern_native_class(Leds_animator); -be_extern_native_class(Leds_pulse); be_extern_native_class(AudioGenerator); be_extern_native_class(AudioFileSource); be_extern_native_class(AudioOutputI2S); @@ -278,9 +278,6 @@ BERRY_LOCAL bclass_array be_class_table = { #ifdef USE_WS2812 &be_native_class(Leds_ntv), &be_native_class(Leds), - &be_native_class(Leds_frame), - &be_native_class(Leds_animator), - &be_native_class(Leds_pulse), #endif // USE_WS2812 #ifdef USE_ENERGY_SENSOR &be_native_class(energy_struct), diff --git a/lib/libesp32/berry_tasmota/src/be_animate_lib.c b/lib/libesp32/berry_tasmota/src/be_animate_lib.c deleted file mode 100644 index 77a88bbc8bc9..000000000000 --- a/lib/libesp32/berry_tasmota/src/be_animate_lib.c +++ /dev/null @@ -1,7 +0,0 @@ -/******************************************************************** - * Berry module `animate` - * - * To use: `import animate` - * - *******************************************************************/ -#include "solidify/solidified_animate_module.h" diff --git a/lib/libesp32/berry_tasmota/src/be_animate_module.c b/lib/libesp32/berry_tasmota/src/be_animate_module.c new file mode 100644 index 000000000000..b21102e8fd13 --- /dev/null +++ b/lib/libesp32/berry_tasmota/src/be_animate_module.c @@ -0,0 +1,197 @@ +/* + be_animate_module.c - implements the animate module for Leds + + Copyright (C) 2023 Stephan Hadinger & Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/*******************************************************************\ + * `animate` global module +\*******************************************************************/ + +#include "be_constobj.h" +#include "be_mapping.h" + +#include "solidify/solidified_animate_0_core.h" +#include "solidify/solidified_animate_1_animate_effects.h" +#include "solidify/solidified_animate_9_module.h" + + +/*******************************************************************\ + * standard palettes +\*******************************************************************/ +static const uint8_t PALETTE_RAINBOW_WHITE[] = { + 0x50, 0xFF, 0x00, 0x00, // red + 0x30, 0xFF, 0x00, 0x00, // red + 0x50, 0xFF, 0xA5, 0x00, // orange + 0x30, 0xFF, 0xA5, 0x00, // orange + 0x50, 0xFF, 0xFF, 0x00, // yellow + 0x30, 0xFF, 0xFF, 0x00, // yellow + 0x50, 0x00, 0xFF, 0x00, // green + 0x30, 0x00, 0xFF, 0x00, // green + 0x50, 0x00, 0x00, 0xFF, // blue + 0x30, 0x00, 0x00, 0xFF, // blue + 0x50, 0xFF, 0x00, 0xFF, // indigo + 0x30, 0xFF, 0x00, 0xFF, // indigo + 0x50, 0xFF, 0xFF, 0xFF, // white + 0x30, 0xFF, 0xFF, 0xFF, // white + 0x00, 0xFF, 0x00, 0x00, // red +}; + +static const uint8_t PALETTE_STANDARD_TAG[] = { + 0x40, 0xFF, 0x00, 0x00, // red + 0x40, 0xFF, 0xA5, 0x00, // orange + 0x40, 0xFF, 0xFF, 0x00, // yellow + 0x40, 0x00, 0xFF, 0x00, // green + 0x40, 0x00, 0x00, 0xFF, // blue + 0x40, 0xFF, 0x00, 0xFF, // indigo + 0x40, 0xFF, 0xFF, 0xFF, // violet + 0x00, 0xFF, 0x00, 0x00, // red +}; + +// Gradient palette "ib_jul01_gp", originally from +// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html +static const uint8_t PALETTE_ib_jul01_gp[] = { + 0x00, 0xE6, 0x06, 0x11, // rgb(230, 6, 17) 0.000%, + 0x5E, 0x25, 0x60, 0x5A, // rgb( 37, 96, 90) 37.010%, + 0x85, 0x90, 0xBD, 0x6A, // rgb(144,189,106) 52.000%, + 0xFF, 0xBB, 0x03, 0x0D, // rgb(187, 3, 13) 100.000% +}; + +static const uint8_t PALETTE_STANDARD_VAL[] = { + 0x00, 0xFF, 0x00, 0x00, // red + 0x24, 0xFF, 0xA5, 0x00, // orange + 0x49, 0xFF, 0xFF, 0x00, // yellow + 0x6E, 0x00, 0xFF, 0x00, // green + 0x92, 0x00, 0x00, 0xFF, // blue + 0xB7, 0xFF, 0x00, 0xFF, // indigo + 0xDB, 0xFF, 0xFF, 0xFF, // violet + 0xFF, 0xFF, 0x00, 0x00, // red +}; + +static const uint8_t PALETTE_SATURATED_TAG[] = { + 0x40, 0xFF, 0x00, 0x00, // red + 0x40, 0xFF, 0xA5, 0x00, // orange + 0x40, 0xFF, 0xFF, 0x00, // yellow + 0x40, 0x00, 0xFF, 0x00, // green + 0x40, 0x00, 0x00, 0xFF, // blue + 0x40, 0xFF, 0x00, 0xFF, // indigo + 0x40, 0xFF, 0xFF, 0xFF, // violet + 0x00, 0xFF, 0x00, 0x00, // red +}; + +extern const bclass be_class_Leds_frame; + +#include "be_fixed_animate.h" + +/* @const_object_info_begin + +module animate (scope: global, strings: weak) { + SAWTOOTH, int(1) + TRIANGLE, int(2) + SQUARE, int(3) + COSINE, int(4) + SINE, int(5) + LASTFORM, int(5) + + PALETTE_STANDARD_TAG, comptr(PALETTE_STANDARD_TAG) + PALETTE_RAINBOW_WHITE, comptr(PALETTE_RAINBOW_WHITE) + PALETTE_STANDARD_VAL, comptr(PALETTE_STANDARD_VAL) + PALETTE_SATURATED_TAG, comptr(PALETTE_SATURATED_TAG) + + (), class(be_class_Animate_core) + core, class(be_class_Animate_core) // alias + animator, class(be_class_Animate_animator) + frame, class(be_class_Leds_frame) + pulse, class(be_class_Animate_pulse) + palette, class(be_class_Animate_palette) + oscillator, class(be_class_Animate_oscillator) +} + +@const_object_info_end */ + +/* Unit test for palettes + +import animate +var p, gradient +p = animate.palette.ptr_to_palette(animate.PALETTE_STANDARD_TAG) +assert(p == bytes('40FF000040FFA50040FFFF004000FF00400000FF40FF00FF40FFFFFF00FF0000')) +gradient = animate.palette.to_css_gradient(p) +assert(gradient == 'background:linear-gradient(to right,#FF0000 0.0%,#FFA500 14.3%,#FFFF00 28.6%,#00FF00 42.9%,#0000FF 57.1%,#FF00FF 71.4%,#FFFFFF 85.7%,#FF0000 100.0%);') + +p = animate.palette.ptr_to_palette(animate.PALETTE_STANDARD_VAL) +assert(p == bytes('00FF000024FFA50049FFFF006E00FF00920000FFB7FF00FFDBFFFFFFFFFF0000')) +gradient = animate.palette.to_css_gradient(animate.PALETTE_STANDARD_VAL) +assert(gradient == 'background:linear-gradient(to right,#FF0000 0.0%,#FFA500 14.1%,#FFFF00 28.6%,#00FF00 43.1%,#0000FF 57.3%,#FF00FF 71.8%,#FFFFFF 85.9%,#FF0000 100.0%);') + + +# unit tests +import animate +var o = animate.oscillator(-1000, 1000, 3000) +o.start(1000) +assert(o.value == -1000) +assert(o.animate(1500) == -667) +assert(o.animate(2500) == 0) +assert(o.animate(3999) == 1000) +assert(o.animate(4000) == -1000) +assert(o.animate(4100) == -933) + +o = animate.oscillator(-1000, 1000, 6000, animate.TRIANGLE) +o.start(1000) +assert(o.value == -1000) +assert(o.animate(1500) == -667) +assert(o.animate(2500) == 0) +assert(o.animate(3999) == 1000) +assert(o.animate(4000) == 1000) +assert(o.animate(4100) == 933) +assert(o.animate(6000) == -334) +assert(o.animate(7000) == -1000) +assert(o.animate(7100) == -933) + +o = animate.oscillator(-1000, 1000, 6000, animate.SQUARE) +o.start(1000) +assert(o.value == -1000) +assert(o.animate(1500) == -1000) +assert(o.animate(2500) == -1000) +assert(o.animate(3999) == -1000) +assert(o.animate(4000) == 1000) +assert(o.animate(4100) == 1000) +assert(o.animate(6000) == 1000) +assert(o.animate(7000) == -1000) +assert(o.animate(7100) == -1000) + +o = animate.oscillator(-1000, 1000, 6000, animate.SINE) +o.start(1000) +assert(o.animate(1000) == 0) +assert(o.animate(1500) == 500) +assert(o.animate(2000) == 867) +assert(o.animate(2500) == 1000) +assert(o.animate(4000) == 0) +assert(o.animate(5500) == -1000) +assert(o.animate(7000) == 0) + +o = animate.oscillator(-1000, 1000, 6000, animate.COSINE) +o.start(1000) +assert(o.animate(1000) == -1000) +assert(o.animate(1500) == -867) +assert(o.animate(2000) == -500) +assert(o.animate(2500) == 0) +assert(o.animate(4000) == 1000) +assert(o.animate(5500) == 0) +assert(o.animate(7000) == -1000) + + + +*/ \ No newline at end of file diff --git a/lib/libesp32/berry_tasmota/src/be_leds_animator_class.c b/lib/libesp32/berry_tasmota/src/be_leds_animator_class.c deleted file mode 100644 index 3bf10367ab2d..000000000000 --- a/lib/libesp32/berry_tasmota/src/be_leds_animator_class.c +++ /dev/null @@ -1,9 +0,0 @@ -/******************************************************************** - * Berry class `Leds_animator` - * - *******************************************************************/ -#ifdef USE_WS2812 - -#include "solidify/solidified_leds_0_animator.h" - -#endif // USE_WS2812 diff --git a/lib/libesp32/berry_tasmota/src/be_leds_pulse_class.c b/lib/libesp32/berry_tasmota/src/be_leds_pulse_class.c deleted file mode 100644 index 3a2753b566cc..000000000000 --- a/lib/libesp32/berry_tasmota/src/be_leds_pulse_class.c +++ /dev/null @@ -1,9 +0,0 @@ -/******************************************************************** - * Berry class `Leds_pulse` - * - *******************************************************************/ -#ifdef USE_WS2812 - -#include "solidify/solidified_leds_1_animate_effects.h" - -#endif // USE_WS2812 diff --git a/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c b/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c index 9bd9120b7469..f023a832fb1a 100644 --- a/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_tasmota_lib.c @@ -35,6 +35,7 @@ extern int l_delay(bvm *vm); extern int l_delay_microseconds(bvm *vm); extern int l_scaleuint(bvm *vm); extern int l_scaleint(bvm *vm); +extern int l_sineint(bvm *vm); extern int l_logInfo(bvm *vm); extern int l_loglevel(bvm *vm); extern int l_save(bvm *vm); @@ -120,6 +121,7 @@ class be_class_tasmota (scope: global, name: Tasmota) { delay_microseconds, func(l_delay_microseconds) scale_uint, static_func(l_scaleuint) scale_int, static_func(l_scaleint) + sine_int, static_func(l_sineint) log, func(l_logInfo) loglevel, func(l_loglevel) save, func(l_save) diff --git a/lib/libesp32/berry_tasmota/src/embedded/leds_0_animator.be b/lib/libesp32/berry_tasmota/src/embedded/animate_0_core.be similarity index 94% rename from lib/libesp32/berry_tasmota/src/embedded/leds_0_animator.be rename to lib/libesp32/berry_tasmota/src/embedded/animate_0_core.be index e6de57d096b3..f7bdf2e5219e 100644 --- a/lib/libesp32/berry_tasmota/src/embedded/leds_0_animator.be +++ b/lib/libesp32/berry_tasmota/src/embedded/animate_0_core.be @@ -1,13 +1,8 @@ -# class Leds_animator - -#@ solidify:Leds_animator,weak - -# for solidification -class Leds_frame end +# class Animate_core ########################################################################################## # -# class Leds_animator +# class Animate_core # # Simple framework to orchestrate all the animations for a led strip or led matrix # @@ -15,7 +10,8 @@ class Leds_frame end # This version uses `fast_loop` for up to 5ms animation time (200 Hz) # ########################################################################################## -class Leds_animator +#@ solidify:Animate_core,weak +class Animate_core var strip # neopixelbus object var pixel_count # number of pixels in the strip var bri # brightness of the animation, 0..100, default 50 @@ -35,6 +31,7 @@ class Leds_animator var back_color # background color RRGGBB def init(strip, bri) + import animate self.strip = strip if (bri == nil) bri = 50 end self.bri = bri # percentage of brightness 0..100 @@ -44,8 +41,8 @@ class Leds_animator self.painters = [] # self.clear() # clear all leds first - self.frame = Leds_frame(self.pixel_count) - self.layer = Leds_frame(self.pixel_count) + self.frame = animate.frame(self.pixel_count) + self.layer = animate.frame(self.pixel_count) # self.fast_loop_cb = def() self.fast_loop() end self.back_color = 0x000000 diff --git a/lib/libesp32/berry_tasmota/src/embedded/leds_1_animate_effects.be b/lib/libesp32/berry_tasmota/src/embedded/animate_1_animate_effects.be similarity index 82% rename from lib/libesp32/berry_tasmota/src/embedded/leds_1_animate_effects.be rename to lib/libesp32/berry_tasmota/src/embedded/animate_1_animate_effects.be index fd8d112edb5b..e2a5a9736b74 100644 --- a/lib/libesp32/berry_tasmota/src/embedded/leds_1_animate_effects.be +++ b/lib/libesp32/berry_tasmota/src/embedded/animate_1_animate_effects.be @@ -1,14 +1,12 @@ -# class Leds_pulse - -#@ solidify:Leds_pulse,weak +# class Animate_pulse ########################################################################################## # -# class Leds_pulse +# class Animate_pulse # # Display a color pulse # -# index (1) +# pos (1) # | # v # _______ @@ -17,16 +15,17 @@ # | | | | # |2| 3 |2| # -# 1: `index`, start of the pulse (in pixel) +# 1: `pos`, start of the pulse (in pixel) # 2: `slew_size`, number of pixels to fade from back to fore color, can be `0` # 3: `pulse_size`, number of pixels of the pulse # ########################################################################################## -class Leds_pulse +#@ solidify:Animate_pulse,weak +class Animate_pulse var color var back_color - var index + var pos var slew_size var pulse_size @@ -54,8 +53,8 @@ class Leds_pulse self.back_color = c end - def set_index(index) - self.index = index + def set_pos(pos) + self.pos = pos end def set_slew_size(slew_size) @@ -72,18 +71,18 @@ class Leds_pulse if (back_color != 0xFF000000) frame.fill_pixels(back_color) # fill with transparent color end - var index = self.index + var pos = self.pos var slew_size = self.slew_size var pulse_size = self.pulse_size var color = self.color var pixel_size = frame.pixel_size - # var min_index = index - slew_size - # var max_index = index + pulse_size + slew_size - 1 + # var min_index = pos - slew_size + # var max_index = pos + pulse_size + slew_size - 1 var pulse_min, pulse_max - pulse_min = index - pulse_max = index + pulse_size + pulse_min = pos + pulse_max = pos + pulse_size if (pulse_min < 0) pulse_min = 0 end if (pulse_max >= pixel_size) pulse_max = pixel_size end @@ -94,28 +93,28 @@ class Leds_pulse end if (slew_size > 0) - # check first slew, from `min_index` to `index - 1` + # check first slew, from `min_index` to `pos - 1` # Slew 1 - pulse_min = index - slew_size - pulse_max = index + pulse_min = pos - slew_size + pulse_max = pos if (pulse_min < 0) pulse_min = 0 end if (pulse_max >= pixel_size) pulse_max = pixel_size end i = pulse_min while (i < pulse_max) # blend from 255 (back) to 0 (fore) - frame[i] = frame.blend(back_color, color, tasmota.scale_int(i, index - slew_size - 1, index, 255, 0)) + frame[i] = frame.blend(back_color, color, tasmota.scale_int(i, pos - slew_size - 1, pos, 255, 0)) # blend i += 1 end # Slew 2 - pulse_min = index + pulse_size - pulse_max = index + pulse_size + slew_size + pulse_min = pos + pulse_size + pulse_max = pos + pulse_size + slew_size if (pulse_min < 0) pulse_min = 0 end if (pulse_max >= pixel_size) pulse_max = pixel_size end i = pulse_min while (i < pulse_max) # blend - frame[i] = frame.blend(back_color, color, tasmota.scale_int(i, index + pulse_size - 1, index + pulse_size + slew_size, 0, 255)) + frame[i] = frame.blend(back_color, color, tasmota.scale_int(i, pos + pulse_size - 1, pos + pulse_size + slew_size, 0, 255)) i += 1 end end @@ -130,10 +129,11 @@ end # if false -var frame = Leds_frame(10) +import animate +var frame = animate.frame(10) assert(frame.tohex() == '00000000000000000000000000000000000000000000000000000000000000000000000000000000') -var pulse = Leds_pulse(0x00FF00, 3, 2) +var pulse = Animate_pulse(0x00FF00, 3, 2) pulse.set_index(5) pulse.paint(frame) assert(frame.tohex() == '0000000000000000000000000055000000AA000000FF000000FF000000FF000000AA000000550000') diff --git a/lib/libesp32/berry_tasmota/src/embedded/animate_9_module.be b/lib/libesp32/berry_tasmota/src/embedded/animate_9_module.be new file mode 100644 index 000000000000..45f22b81bf86 --- /dev/null +++ b/lib/libesp32/berry_tasmota/src/embedded/animate_9_module.be @@ -0,0 +1,508 @@ +# +# class Animate +# +# Animation framework +# + +animate = module("animate") + +# for solidification +class Leds_frame end + +animate.("()") = Animate_core # make it available as `animate()` +animate.frame = Leds_frame +animate.pulse = Animate_pulse + +################################################################################# +# class Animate_palette +# +# Animated color palette +################################################################################# + +################################################################################# +# Palette format compatible +# +# Takes a binary array with a set of 4 bytes elements: VRGB +# V: Value in a range 0..255. The first value must be 0, +# the last needs to be 255. +# Numbers must be in strictly increasin numbers. +# The algorithm maps a 0..255 rotating value to its color +# in the palette. +# R: Red component +# G: Green component +# B: Blue component +# Note: RGB is in big Endian to make it more readable, although +# it's little-endian when in memory. Be aware! +# RGB values are stored at max brightness and without gamma correction +################################################################################# + +# # Gradient palette "ib_jul01_gp", originally from +# # http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html +# var PALETTE_ib_jul01_gp = bytes( +# "00" "E60611" +# "5E" "25605A" +# "85" "90BD6A" +# "FF" "BB030D" +# ) +# # animate.PALETTE_ib_jul01_gp = PALETTE_ib_jul01_gp +# # rgb(230, 6, 17) 0.000%, +# # rgb( 37, 96, 90) 37.010%, +# # rgb(144,189,106) 52.000%, +# # rgb(187, 3, 13) 100.000% + +# var PALETTE_STANDARD_VAL = bytes( +# "00" "FF0000" # red +# "24" "FFA500" # orange +# "49" "FFFF00" # yellow +# "6E" "008800" # green +# "92" "0000FF" # blue +# "B7" "4B0082" # indigo +# "DB" "EE82EE" # violet +# "FF" "FF0000" # red +# ) +# # animate.PALETTE_STANDARD = PALETTE_STANDARD + +# var PALETTE_SATURATED_TAG = bytes( +# "40" "FF0000" # red +# "40" "FFA500" # orange +# "40" "FFFF00" # yellow +# "40" "00FF00" # green +# "40" "0000FF" # blue +# "40" "FF00FF" # indigo +# "40" "EE44A5" # violet +# "00" "FF0000" # red +# ) + +# var PALETTE_STANDARD_TAG = bytes( +# "40" "FF0000" # red +# "40" "FFA500" # orange +# "40" "FFFF00" # yellow +# "40" "008800" # green +# "40" "0000FF" # blue +# "40" "4B0082" # indigo +# "40" "EE82EE" # violet +# "00" "FF0000" # red +# ) +# # animate.PALETTE_STANDARD = PALETTE_STANDARD + + +#@ solidify:Animate_animator,weak +class Animate_animator + # timing information + var running # true if running + var duration_ms # duration_ms of the entire cycle in ms, cannot be `0` + var origin # origin in ms of the current cycle, as per tasmota.millis() reference + # callback information + var obj # object to call + var mth # object method to call + + def init(duration_ms) + self.duration_ms = duration_ms + end + + def set_duration_ms(duration_ms) + self.duration_ms = duration_ms + end + + def set_cb(obj, mth) + self.obj = obj + self.mth = mth + end + + def start(millis) + if (self.duration_ms == nil) return end + if millis == nil millis = tasmota.millis() end + self.origin = millis + self.running = true + end + + def stop() + self.origin = nil + self.running = false + end + + def is_running() + return bool(self.running) + end + + # called at the end of each cycle + def beat() + end + +end + +#@ solidify:Animate_palette,weak +class Animate_palette : Animate_animator + ## inherited + ## timing information + # var running + # var duration_ms # duration_ms of the entire cycle in ms, cannot be `0` + # var origin # origin in ms of the current cycle, as per tasmota.millis() reference + ## callback information + # var obj # object to call + # var mth # object method to call + + # parsing of palette + var palette # raw bytes object + var slots_arr # constructed array of timestamp slots + var slots # number of slots + # range information (when used as range color) + var range_min # minimum value expected as input + var range_max # maximum value expected as input, needs (range_min < range_max, can be negative) + # brightness + var bri # brightness to be applied to palette 0..100 + # color object to do RGB color calculation + var color # instance of light_state, used for color calculation (reuse of object) + + def init(palette, duration_ms) + super(self).init(duration_ms) + self.running = false + if (type(palette) == 'ptr') palette = self.ptr_to_palette(palette) end # convert comptr to palette buffer + self.palette = palette + self.bri = 100 + self.slots = size(palette) / 4 + if duration_ms != nil + self.set_duration(duration_ms) + end + self.color = light_state(light_state.RGB) + end + + # setter to be used as cb + def set_bri(bri) + self.bri = int(bri) + end + + # convert a comptr to a bytes() for palette + # parse the raw bytes to find the actual length + # + # input: comptr + # return: bytes() object of palette + static def ptr_to_palette(p) + if type(p) == 'ptr' + var b_raw = bytes(p, 2000) # arbitrary large size + var idx = 1 + if b_raw[0] != 0 + # palette in tick counts + while true + if b_raw[idx * 4] == 0 + break + end + idx += 1 + end + else + # palette is in value range from 0..255 + while true + if b_raw[idx * 4] == 0xFF + break + end + idx += 1 + end + end + var sz = (idx + 1) * 4 + return bytes(p, sz) + end + end + + def parse_palette(min, max) + var arr = [] + var slots = self.slots + arr.resize(slots) + + # check if we have slots or values + # if first value index is non-zero, it's ticks count + if self.palette.get(0, 1) != 0 + # palette in tick counts + # compute the total number of ticks + var total_ticks = 0 + var idx = 0 + while idx < slots - 1 + total_ticks += self.palette.get(idx * 4, 1) + idx += 1 + end + var cur_ticks = 0 + idx = 0 + while idx < slots + arr[idx] = tasmota.scale_int(cur_ticks, 0, total_ticks, min, max) + cur_ticks += self.palette.get(idx * 4, 1) + idx += 1 + end + else + # palette is in value range from 0..255 + var idx = 0 + while idx < slots + var val = self.palette.get(idx * 4, 1) + arr[idx] = tasmota.scale_int(val, 0, 255, min, max) + idx += 1 + end + end + # print(f"ANM: {arr=}") + return arr + end + + def set_duration(duration_ms) + if (duration_ms == nil) return end + if duration_ms <= 0 raise "value_error", "duration_ms must be positive" end + self.duration_ms = duration_ms + + self.slots_arr = self.parse_palette(0, duration_ms - 1) + end + + def set_range(min, max) + if (min >= max) raise "value_error", "min must be lower than mex" end + self.range_min = min + self.range_max = max + + self.slots_arr = self.parse_palette(min, max) + end + + # compute the css linear-gradient description + # + # Example: background: linear-gradient(to right, #000000, #e66465 11.0%, #9198e5); + static def to_css_gradient(palette) + var p = _class(palette) + var arr = p.parse_palette(0, 1000) + var ret = "background:linear-gradient(to right" + var idx = 0 + while idx < size(arr) + var prm = arr[idx] # per mile + + var bgrt = p.palette.get(idx * 4, 4) + var r = (bgrt >> 8) & 0xFF + var g = (bgrt >> 16) & 0xFF + var b = (bgrt >> 24) & 0xFF + ret += f",#{r:02X}{g:02X}{b:02X} {prm/10.0:.1f}%" + idx += 1 + end + ret += ");" + return ret + end + + def set_value(value) + if (self.range_min == nil || self.range_max == nil) return nil end + var scale_int = tasmota.scale_int + + # find slot + var slots = self.slots + var idx = slots - 2 + while idx > 0 + if value >= self.slots_arr[idx] break end + idx -= 1 + end + var bgrt0 = self.palette.get(idx * 4, 4) + var bgrt1 = self.palette.get((idx + 1) * 4, 4) + var t0 = self.slots_arr[idx] + var t1 = self.slots_arr[idx + 1] + var r = scale_int(value, t0, t1, (bgrt0 >> 8) & 0xFF, (bgrt1 >> 8) & 0xFF) + var g = scale_int(value, t0, t1, (bgrt0 >> 16) & 0xFF, (bgrt1 >> 16) & 0xFF) + var b = scale_int(value, t0, t1, (bgrt0 >> 24) & 0xFF, (bgrt1 >> 24) & 0xFF) + var rgb = (r << 16) | (g << 8) | b + # + var obj = self.obj + var mth = self.mth + if (obj && mth) + mth(obj, rgb) + end + # if self.cb != nil + # self.cb(rgb) + # end + # + # print(f"ANM: {rgb=:%06X}") + return rgb + end + + def animate(millis) + if (self.duration_ms == nil) return end + if millis == nil millis = tasmota.millis() end + var past = millis - self.origin + if past < 0 + past = 0 + millis = self.origin + end + var duration_ms = self.duration_ms + var scale_uint = tasmota.scale_uint + if past >= duration_ms + self.origin += (past / duration_ms) * duration_ms + past = past % duration_ms + end + # find slot + var slots = self.slots + var idx = slots - 2 + while idx > 0 + if past >= self.slots_arr[idx] break end + idx -= 1 + end + var bgrt0 = self.palette.get(idx * 4, 4) + var bgrt1 = self.palette.get((idx + 1) * 4, 4) + var t0 = self.slots_arr[idx] + var t1 = self.slots_arr[idx + 1] + var r = scale_uint(past, t0, t1, (bgrt0 >> 8) & 0xFF, (bgrt1 >> 8) & 0xFF) + var g = scale_uint(past, t0, t1, (bgrt0 >> 16) & 0xFF, (bgrt1 >> 16) & 0xFF) + var b = scale_uint(past, t0, t1, (bgrt0 >> 24) & 0xFF, (bgrt1 >> 24) & 0xFF) + + var color = self.color + color.set_rgb((bgrt0 >> 8) & 0xFF, (bgrt0 >> 16) & 0xFF, (bgrt0 >> 24) & 0xFF) + var bri0 = color.bri + color.set_rgb((bgrt1 >> 8) & 0xFF, (bgrt1 >> 16) & 0xFF, (bgrt1 >> 24) & 0xFF) + var bri1 = color.bri + var bri2 = scale_uint(past, t0, t1, bri0, bri1) + color.set_rgb(r, g, b) + color.set_bri(bri2) + + r = color.r + g = color.g + b = color.b + + # apply self.bri if not `100` + var bri = self.bri + if bri != 100 + r = tasmota.scale_uint(r, 0, 100, 0, bri) + g = tasmota.scale_uint(g, 0, 100, 0, bri) + b = tasmota.scale_uint(b, 0, 100, 0, bri) + end + + # var rgb = (r << 16) | (g << 8) | b + var rgb = (r << 16) | (g << 8) | b + + var obj = self.obj + var mth = self.mth + if (obj && mth) + mth(obj, rgb) + end + + return rgb + end +end +animate.palette = Animate_palette + +#- + +pal = Animate_palette(PALETTE_STANDARD_TAG, 7000) +pal = Animate_palette(PALETTE_STANDARD_VAL, 7000) + + +import animate +var pal = animate.palette(PALETTE_STANDARD_TAG, 7000) +pal.start(0) +for t: range(0,8000,200) + pal.tick(t) +end + +-# + +animate.SAWTOOTH = 1 +animate.TRIANGLE = 2 +animate.SQUARE = 3 +animate.COSINE = 4 +animate.SINE = 5 +animate.LASTFOMR = 5 # identify last form + +#@ solidify:Animate_oscillator,weak +class Animate_oscillator : Animate_animator + ## inherited + ## timing information + # var running + # var duration_ms # duration_ms of the entire cycle in ms, cannot be `0` + # var origin # origin in ms of the current cycle, as per tasmota.millis() reference + var phase # 0..100% - phase shift, default 0 + var duty_cycle # 0..100% - duty cycle, default 50% + ## callback information + # var obj # object to call + # var mth # object method to call + var a # starting value + var b # end value + var form # waveform + # current value + var value + + def init(a, b, duration_ms, form) + self.phase = 0 + self.duty_cycle = 50 + self.a = a + self.b = b + self.duration_ms = duration_ms + self.value = a + if (form == nil) form = 1 end + self.form = form + end + + def set_phase(phase) + if (phase < 0) phase = 0 end + if (phase > 100) phase = 100 end + self.phase = phase + end + + def set_duty_cycle(duty_cycle) + if (duty_cycle < 0) duty_cycle = 0 end + if (duty_cycle > 100) duty_cycle = 100 end + self.duty_cycle = duty_cycle + end + + def set_a(a) + self.a = a + end + def set_b(b) + self.b = b + end + + def animate(millis) + if (self.duration_ms == nil) return end + if millis == nil millis = tasmota.millis() end + var past = millis - self.origin + if past < 0 + past = 0 + millis = self.originally + end + var duration_ms = self.duration_ms + var duration_ms_mid # mid point considering duty cycle + duration_ms_mid = tasmota.scale_uint(self.duty_cycle, 0, 100, 0, duration_ms) + if past >= duration_ms + self.origin += (past / duration_ms) * duration_ms + past = past % duration_ms + # handle end of cycle + self.beat() + end + + var a = self.a + var b = self.b + var value = self.value + var past_with_phase = past # adjust past with phase + if self.phase > 0 + past_with_phase += tasmota.scale_uint(self.phase, 0, 100, 0, duration_ms) + if (past_with_phase > duration_ms) past_with_phase -= duration_ms end # if overflow, take modulus + end + + if self.form == 1 #-SAWTOOTH-# + value = tasmota.scale_int(past_with_phase, 0, duration_ms - 1, a, b) + elif self.form == 2 #-TRIANGLE-# + if past_with_phase < duration_ms_mid + value = tasmota.scale_int(past_with_phase, 0, duration_ms_mid - 1, a, b) + else + value = tasmota.scale_int(past_with_phase, duration_ms_mid, duration_ms - 1, b, a) + end + elif self.form == 3 #-SQUARE-# + if past_with_phase < duration_ms_mid + value = a + else + value = b + end + elif (self.form == 4) #-COSINE-# || (self.form == 5) #-SINE-# + # map timing to 0..32767 + var angle = tasmota.scale_int(past_with_phase, 0, duration_ms - 1, 0, 32767) + if (self.form == 4) #-COSINE-# + angle -= 8192 + end + var x = tasmota.sine_int(angle) # -4096 .. 4096 + value = tasmota.scale_int(x, -4096, 4096, a, b) + end + self.value = value + + var obj = self.obj + var mth = self.mth + if (obj && mth) + mth(obj, value) + end + + return value + end +end +animate.oscillator = Animate_oscillator diff --git a/lib/libesp32/berry_tasmota/src/embedded/animate_module.be b/lib/libesp32/berry_tasmota/src/embedded/animate_module.be deleted file mode 100644 index f1857c90cac3..000000000000 --- a/lib/libesp32/berry_tasmota/src/embedded/animate_module.be +++ /dev/null @@ -1,573 +0,0 @@ -# -# class Animate -# -# Animation framework -# - -#@ solidify:animate,weak -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 - - -################################################################################# -# class Animate_palette -# -# Animated color palette -################################################################################# - -################################################################################# -# Palette format compatible -# -# Takes a binary array with a set of 4 bytes elements: VRGB -# V: Value in a range 0..255. The first value must be 0, -# the last needs to be 255. -# Numbers must be in strictly increasin numbers. -# The algorithm maps a 0..255 rotating value to its color -# in the palette. -# R: Red component -# G: Green component -# B: Blue component -# Note: RGB is in big Endian to make it more readable, although -# it's little-endian when in memory. Be aware! -# RGB values are stored at max brightness and without gamma correction -################################################################################# - -# Gradient palette "ib_jul01_gp", originally from -# http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html -var PALETTE_ib_jul01_gp = bytes( - "00" "E60611" - "5E" "25605A" - "85" "90BD6A" - "FF" "BB030D" -) -# animate.PALETTE_ib_jul01_gp = PALETTE_ib_jul01_gp -# rgb(230, 6, 17) 0.000%, -# rgb( 37, 96, 90) 37.010%, -# rgb(144,189,106) 52.000%, -# rgb(187, 3, 13) 100.000% - -var PALETTE_STANDARD_VAL = bytes( - "00" "FF0000" # red - "24" "FFA500" # orange - "49" "FFFF00" # yellow - "6E" "008800" # green - "92" "0000FF" # blue - "B7" "4B0082" # indigo - "DB" "EE82EE" # violet - "FF" "FF0000" # red -) -# animate.PALETTE_STANDARD = PALETTE_STANDARD - -var PALETTE_SATURATED_TAG = bytes( - "40" "FF0000" # red - "40" "FFA500" # orange - "40" "FFFF00" # yellow - "40" "00FF00" # green - "40" "0000FF" # blue - "40" "FF00FF" # indigo - "40" "EE44A5" # violet - "00" "FF0000" # red -) - -var PALETTE_STANDARD_TAG = bytes( - "40" "FF0000" # red - "40" "FFA500" # orange - "40" "FFFF00" # yellow - "40" "008800" # green - "40" "0000FF" # blue - "40" "4B0082" # indigo - "40" "EE82EE" # violet - "00" "FF0000" # red -) -# animate.PALETTE_STANDARD = PALETTE_STANDARD - - -class Animate_palette - # parsing of palette - var palette # raw bytes object - var slots_arr # constructed array of timestamp slots - var slots # number of slots - # timing information - var running - var duration_ms # duration_ms of the entire cycle in ms, cannot be `0` - var origin # origin in ms of the current cycle, as per tasmota.millis() reference - # range information (when used as range color) - var range_min # minimum value expected as input - var range_max # maximum value expected as input, needs (range_min < range_max, can be negative) - # callback information - var animate_obj # object to call - var animate_mth # object method to call - # brightness - var bri # brightness to be applied to palette 0..100 - # color object to do RGB color calculation - var color # instance of light_state, used for color calculation (reuse of object) - - def init(palette, duration_s) - self.running = false - self.palette = palette - self.bri = 100 - self.slots = size(palette) / 4 - if duration_s != nil - self.set_duration(int(duration_s * 1000)) - end - self.color = light_state(light_state.RGB) - end - - def set_cb(obj, mth) - self.animate_obj = obj - self.animate_mth = mth - end - - # setter to be used as cb - def set_bri(bri) - self.bri = int(bri) - end - - def start(millis) - if (self.duration_ms == nil) return end - if millis == nil millis = tasmota.millis() end - self.origin = millis - self.running = true - end - - def stop() - self.origin = nil - self.running = false - end - - def is_running() - return bool(self.running) - end - - def parse_palette(min, max) - var arr = [] - var slots = self.slots - arr.resize(slots) - - # check if we have slots or values - # if first value index is non-zero, it's ticks count - if self.palette.get(0, 1) != 0 - # palette in tick counts - # compute the total number of ticks - var total_ticks = 0 - var idx = 0 - while idx < slots - 1 - total_ticks += self.palette.get(idx * 4, 1) - idx += 1 - end - var cur_ticks = 0 - idx = 0 - while idx < slots - arr[idx] = tasmota.scale_int(cur_ticks, 0, total_ticks, min, max) - cur_ticks += self.palette.get(idx * 4, 1) - idx += 1 - end - else - # palette is in value range from 0..255 - var idx = 0 - while idx < slots - var val = self.palette.get(idx * 4, 1) - arr[idx] = tasmota.scale_int(val, 0, 255, min, max) - idx += 1 - end - end - # print(f"ANM: {arr=}") - return arr - end - - def set_duration(duration_ms) - if (duration_ms == nil) return end - if duration_ms <= 0 raise "value_error", "duration_ms must be positive" end - self.duration_ms = duration_ms - - self.slots_arr = self.parse_palette(0, duration_ms - 1) - end - - def set_range(min, max) - if (min >= max) raise "value_error", "min must be lower than mex" end - self.range_min = min - self.range_max = max - - self.slots_arr = self.parse_palette(min, max) - end - - # compute the css linear-gradient description - # - # Example: background: linear-gradient(to right, #000000, #e66465 11.0%, #9198e5); - def to_css_gradient() - var arr = self.parse_palette(0, 1000) - var ret = "background:linear-gradient(to right" - var idx = 0 - while idx < size(arr) - var prm = arr[idx] # per mile - - var bgrt = self.palette.get(idx * 4, 4) - var r = (bgrt >> 8) & 0xFF - var g = (bgrt >> 16) & 0xFF - var b = (bgrt >> 24) & 0xFF - ret += f",#{r:02X}{g:02X}{b:02X} {prm/10.0:.1f}%" - idx += 1 - end - ret += ");" - return ret - end - - def set_value(value) - if (self.range_min == nil || self.range_max == nil) return nil end - var scale_int = tasmota.scale_int - - # find slot - var slots = self.slots - var idx = slots - 2 - while idx > 0 - if value >= self.slots_arr[idx] break end - idx -= 1 - end - var bgrt0 = self.palette.get(idx * 4, 4) - var bgrt1 = self.palette.get((idx + 1) * 4, 4) - var t0 = self.slots_arr[idx] - var t1 = self.slots_arr[idx + 1] - var r = scale_int(value, t0, t1, (bgrt0 >> 8) & 0xFF, (bgrt1 >> 8) & 0xFF) - var g = scale_int(value, t0, t1, (bgrt0 >> 16) & 0xFF, (bgrt1 >> 16) & 0xFF) - var b = scale_int(value, t0, t1, (bgrt0 >> 24) & 0xFF, (bgrt1 >> 24) & 0xFF) - var rgb = (r << 16) | (g << 8) | b - # - var obj = self.animate_obj - var mth = self.animate_mth - if (obj && mth) - mth(obj, rgb) - end - # if self.cb != nil - # self.cb(rgb) - # end - # - # print(f"ANM: {rgb=:%06X}") - return rgb - end - - def animate(millis) - if (self.duration_ms == nil) return end - if millis == nil millis = tasmota.millis() end - var past = millis - self.origin - if past < 0 - past = 0 - millis = self.origin - end - var duration_ms = self.duration_ms - var scale_uint = tasmota.scale_uint - if past >= duration_ms - self.origin += (past / duration_ms) * duration_ms - past = past % duration_ms - end - # find slot - var slots = self.slots - var idx = slots - 2 - while idx > 0 - if past >= self.slots_arr[idx] break end - idx -= 1 - end - var bgrt0 = self.palette.get(idx * 4, 4) - var bgrt1 = self.palette.get((idx + 1) * 4, 4) - var t0 = self.slots_arr[idx] - var t1 = self.slots_arr[idx + 1] - var r = scale_uint(past, t0, t1, (bgrt0 >> 8) & 0xFF, (bgrt1 >> 8) & 0xFF) - var g = scale_uint(past, t0, t1, (bgrt0 >> 16) & 0xFF, (bgrt1 >> 16) & 0xFF) - var b = scale_uint(past, t0, t1, (bgrt0 >> 24) & 0xFF, (bgrt1 >> 24) & 0xFF) - - var color = self.color - color.set_rgb((bgrt0 >> 8) & 0xFF, (bgrt0 >> 16) & 0xFF, (bgrt0 >> 24) & 0xFF) - var bri0 = color.bri - color.set_rgb((bgrt1 >> 8) & 0xFF, (bgrt1 >> 16) & 0xFF, (bgrt1 >> 24) & 0xFF) - var bri1 = color.bri - var bri2 = scale_uint(past, t0, t1, bri0, bri1) - color.set_rgb(r, g, b) - color.set_bri(bri2) - - r = color.r - g = color.g - b = color.b - - # apply self.bri if not `100` - var bri = self.bri - if bri != 100 - r = tasmota.scale_uint(r, 0, 100, 0, bri) - g = tasmota.scale_uint(g, 0, 100, 0, bri) - b = tasmota.scale_uint(b, 0, 100, 0, bri) - end - - # var rgb = (r << 16) | (g << 8) | b - var rgb = (r << 16) | (g << 8) | b - - var obj = self.animate_obj - var mth = self.animate_mth - if (obj && mth) - mth(obj, rgb) - end - - return rgb - end -end -animate.palette = Animate_palette - -#- - -pal = Animate_palette(PALETTE_STANDARD_TAG, 7000) -pal = Animate_palette(PALETTE_STANDARD_VAL, 7000) - - -import animate -var pal = animate.palette(PALETTE_STANDARD_TAG, 7000) -pal.start(0) -for t: range(0,8000,200) - pal.tick(t) -end - --# - -################################################################################# -# class Animate_segment -# -# Animate a small segment ______/+++\______ -# length in 1/256 pixels -# slew in 1/256 pixels -# fore foregroung color -# back background color (or transparent) -# origin in 1/256 pixels -# -# strip -################################################################################# -# class Animate_segment -# var strip -# var length -# var slew -# var fore -# var back -# var origin - -# def init(strip) -# self.strip = strip -# self.length = 256 # 1 pixel -# self.slew = 0 # 0 pixel (immediate) -# self.fore = 0x00FF0000 # red opaque -# self.back = 0xFF000000 # transparent -# self.origin = 0 # start of strip -# end - -# def paint(bri) -# # move all important values in registers -# var strip = self.strip -# var pix_offset = strip.pixel_offset() -# var pix_count = strip.pixel_count() -# var pix_buffer = strip.pixels_buffer() -# var pix_size = strip.pixel_size() - -# var length = self.length -# var slew = self.slew -# var fore = self.fore -# var back = self.back -# var origin = self.origin - -# var pix = 0 # iterate on each pixel -# var limit_low = (origin - slew) / 256 -# var limit_high = (origin + length + slew) / 256 -# while pix < pix_count -# # are we off limits -# if (pix >= limit_low) && (pix <= limit_high) # outside of those boundaries, we just apply backgroung -# strip.set_pixel_color(pix, fore, bri) -# else -# strip.set_pixel_color(pix, back, bri) -# end -# pix += 1 -# end -# end -# end -# animate.segment = Animate_segment - -# 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 animate_obj # object to call (alternative to closure) - var animate_mth # method to call on object - var pc # program-counter - var ins_time # absolute time when the current instruction started - var running # is the animation running? allows fast return - var value # current value - - def init() - self.code = [] - self.pc = 0 # start at instruction 0 - self.ins_time = 0 - self.running = false # not running by default - # - end - - def set_cb(obj, mth) - self.animate_obj = obj - self.animate_mth = mth - end - - # start but needs external calls to `animate()` - # cur_time:int (opt) current timestamp in ms, defaults to `tasmota.millis()` - # val:int (opt) starting value, default to `nil` - def start(cur_time, val) - if cur_time == nil cur_time = tasmota.millis() end - if (val != nil) self.value = val end - self.ins_time = cur_time - - self.running = true - end - - # # runs autonomously in the Tasmota event loop - # def autorun(cur_time, val) - # self.run(cur_time, val) - # end - - def stop() - self.running = false - end - - def is_running() - return self.running - 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 closure = self.closure # assign to a local variable to not call a method - var obj = self.animate_obj - var mth = self.animate_mth - if sub_index < ins.duration - # we're still in the ramp - self.value = tasmota.scale_uint(sub_index, 0, ins.duration, ins.a, ins.b) - # call method - if (obj && mth) mth(obj, self.value) end - # call closure - if (closure) closure(self.value) end # call closure, need try? TODO - break - else - self.value = ins.b - # call method - if (obj && mth) mth(obj, self.value) end - # call closure - if (closure) closure(self.value) end # 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 - return self.value - - end -end -animate.engine = Animate_engine - -class Animate_from_to : Animate_engine - - def init(obj, mth, from, to, duration) - super(self).init() - self.set_cb(obj, mth) - 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) -# -### - -class Animate_rotate : Animate_engine - - def init(obj, mth, from, to, duration) - super(self).init() - self.set_cb(obj, mth) - 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(obj, mth, from, to, duration) - super(self).init() - self.set_cb(obj, mth) - self.code.push(animate.ins_ramp(from, to, duration)) - self.code.push(animate.ins_ramp(to, from, duration)) - 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() --# diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_leds_0_animator.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_0_core.h similarity index 85% rename from lib/libesp32/berry_tasmota/src/solidify/solidified_leds_0_animator.h rename to lib/libesp32/berry_tasmota/src/solidify/solidified_animate_0_core.h index ea031d397014..f507d4144726 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_leds_0_animator.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_0_core.h @@ -1,15 +1,15 @@ -/* Solidification of leds_0_animator.h */ +/* Solidification of animate_0_core.h */ /********************************************************************\ * Generated code, don't edit * \********************************************************************/ #include "be_constobj.h" -extern const bclass be_class_Leds_animator; +extern const bclass be_class_Animate_core; /******************************************************************** ** Solidified function: remove ********************************************************************/ -be_local_closure(Leds_animator_remove, /* name */ +be_local_closure(Animate_core_remove, /* name */ be_nested_proto( 4, /* nstack */ 1, /* argc */ @@ -44,7 +44,7 @@ be_local_closure(Leds_animator_remove, /* name */ /******************************************************************** ** Solidified function: add_background_animator ********************************************************************/ -be_local_closure(Leds_animator_add_background_animator, /* name */ +be_local_closure(Animate_core_add_background_animator, /* name */ be_nested_proto( 6, /* nstack */ 2, /* argc */ @@ -79,7 +79,7 @@ be_local_closure(Leds_animator_add_background_animator, /* name */ /******************************************************************** ** Solidified function: clear ********************************************************************/ -be_local_closure(Leds_animator_clear, /* name */ +be_local_closure(Animate_core_clear, /* name */ be_nested_proto( 3, /* nstack */ 1, /* argc */ @@ -112,7 +112,7 @@ be_local_closure(Leds_animator_clear, /* name */ /******************************************************************** ** Solidified function: add_animator ********************************************************************/ -be_local_closure(Leds_animator_add_animator, /* name */ +be_local_closure(Animate_core_add_animator, /* name */ be_nested_proto( 5, /* nstack */ 2, /* argc */ @@ -143,7 +143,7 @@ be_local_closure(Leds_animator_add_animator, /* name */ /******************************************************************** ** Solidified function: animate ********************************************************************/ -be_local_closure(Leds_animator_animate, /* name */ +be_local_closure(Animate_core_animate, /* name */ be_nested_proto( 1, /* nstack */ 1, /* argc */ @@ -167,7 +167,7 @@ be_local_closure(Leds_animator_animate, /* name */ /******************************************************************** ** Solidified function: get_bri ********************************************************************/ -be_local_closure(Leds_animator_get_bri, /* name */ +be_local_closure(Animate_core_get_bri, /* name */ be_nested_proto( 3, /* nstack */ 2, /* argc */ @@ -194,7 +194,7 @@ be_local_closure(Leds_animator_get_bri, /* name */ /******************************************************************** ** Solidified function: set_bri ********************************************************************/ -be_local_closure(Leds_animator_set_bri, /* name */ +be_local_closure(Animate_core_set_bri, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -221,7 +221,7 @@ be_local_closure(Leds_animator_set_bri, /* name */ /******************************************************************** ** Solidified function: set_back_color ********************************************************************/ -be_local_closure(Leds_animator_set_back_color, /* name */ +be_local_closure(Animate_core_set_back_color, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -248,7 +248,7 @@ be_local_closure(Leds_animator_set_back_color, /* name */ /******************************************************************** ** Solidified function: stop ********************************************************************/ -be_local_closure(Leds_animator_stop, /* name */ +be_local_closure(Animate_core_stop, /* name */ be_nested_proto( 6, /* nstack */ 1, /* argc */ @@ -299,7 +299,7 @@ be_local_closure(Leds_animator_stop, /* name */ /******************************************************************** ** Solidified function: set_cb ********************************************************************/ -be_local_closure(Leds_animator_set_cb, /* name */ +be_local_closure(Animate_core_set_cb, /* name */ be_nested_proto( 3, /* nstack */ 3, /* argc */ @@ -328,9 +328,9 @@ be_local_closure(Leds_animator_set_cb, /* name */ /******************************************************************** ** Solidified function: init ********************************************************************/ -be_local_closure(Leds_animator_init, /* name */ +be_local_closure(Animate_core_init, /* name */ be_nested_proto( - 5, /* nstack */ + 7, /* nstack */ 3, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -363,15 +363,15 @@ be_local_closure(Leds_animator_init, /* name */ }), 1, /* has constants */ ( &(const bvalue[13]) { /* constants */ - /* K0 */ be_nested_str_weak(strip), - /* K1 */ be_nested_str_weak(bri), - /* K2 */ be_nested_str_weak(running), - /* K3 */ be_nested_str_weak(pixel_count), - /* K4 */ be_nested_str_weak(animators), - /* K5 */ be_nested_str_weak(painters), - /* K6 */ be_nested_str_weak(clear), - /* K7 */ be_nested_str_weak(frame), - /* K8 */ be_nested_str_weak(Leds_frame), + /* K0 */ be_nested_str_weak(animate), + /* K1 */ be_nested_str_weak(strip), + /* K2 */ be_nested_str_weak(bri), + /* K3 */ be_nested_str_weak(running), + /* K4 */ be_nested_str_weak(pixel_count), + /* K5 */ be_nested_str_weak(animators), + /* K6 */ be_nested_str_weak(painters), + /* K7 */ be_nested_str_weak(clear), + /* K8 */ be_nested_str_weak(frame), /* K9 */ be_nested_str_weak(layer), /* K10 */ be_nested_str_weak(fast_loop_cb), /* K11 */ be_nested_str_weak(back_color), @@ -379,39 +379,40 @@ be_local_closure(Leds_animator_init, /* name */ }), be_str_weak(init), &be_const_str_solidified, - ( &(const binstruction[32]) { /* code */ - 0x90020001, // 0000 SETMBR R0 K0 R1 - 0x4C0C0000, // 0001 LDNIL R3 - 0x1C0C0403, // 0002 EQ R3 R2 R3 - 0x780E0000, // 0003 JMPF R3 #0005 - 0x540A0031, // 0004 LDINT R2 50 - 0x90020202, // 0005 SETMBR R0 K1 R2 - 0x500C0000, // 0006 LDBOOL R3 0 0 - 0x90020403, // 0007 SETMBR R0 K2 R3 - 0x8C0C0303, // 0008 GETMET R3 R1 K3 - 0x7C0C0200, // 0009 CALL R3 1 - 0x90020603, // 000A SETMBR R0 K3 R3 - 0x600C0012, // 000B GETGBL R3 G18 - 0x7C0C0000, // 000C CALL R3 0 - 0x90020803, // 000D SETMBR R0 K4 R3 - 0x600C0012, // 000E GETGBL R3 G18 - 0x7C0C0000, // 000F CALL R3 0 - 0x90020A03, // 0010 SETMBR R0 K5 R3 - 0x8C0C0106, // 0011 GETMET R3 R0 K6 - 0x7C0C0200, // 0012 CALL R3 1 - 0xB80E1000, // 0013 GETNGBL R3 K8 - 0x88100103, // 0014 GETMBR R4 R0 K3 - 0x7C0C0200, // 0015 CALL R3 1 - 0x90020E03, // 0016 SETMBR R0 K7 R3 - 0xB80E1000, // 0017 GETNGBL R3 K8 - 0x88100103, // 0018 GETMBR R4 R0 K3 - 0x7C0C0200, // 0019 CALL R3 1 - 0x90021203, // 001A SETMBR R0 K9 R3 - 0x840C0000, // 001B CLOSURE R3 P0 - 0x90021403, // 001C SETMBR R0 K10 R3 - 0x9002170C, // 001D SETMBR R0 K11 K12 - 0xA0000000, // 001E CLOSE R0 - 0x80000000, // 001F RET 0 + ( &(const binstruction[33]) { /* code */ + 0xA40E0000, // 0000 IMPORT R3 K0 + 0x90020201, // 0001 SETMBR R0 K1 R1 + 0x4C100000, // 0002 LDNIL R4 + 0x1C100404, // 0003 EQ R4 R2 R4 + 0x78120000, // 0004 JMPF R4 #0006 + 0x540A0031, // 0005 LDINT R2 50 + 0x90020402, // 0006 SETMBR R0 K2 R2 + 0x50100000, // 0007 LDBOOL R4 0 0 + 0x90020604, // 0008 SETMBR R0 K3 R4 + 0x8C100304, // 0009 GETMET R4 R1 K4 + 0x7C100200, // 000A CALL R4 1 + 0x90020804, // 000B SETMBR R0 K4 R4 + 0x60100012, // 000C GETGBL R4 G18 + 0x7C100000, // 000D CALL R4 0 + 0x90020A04, // 000E SETMBR R0 K5 R4 + 0x60100012, // 000F GETGBL R4 G18 + 0x7C100000, // 0010 CALL R4 0 + 0x90020C04, // 0011 SETMBR R0 K6 R4 + 0x8C100107, // 0012 GETMET R4 R0 K7 + 0x7C100200, // 0013 CALL R4 1 + 0x8C100708, // 0014 GETMET R4 R3 K8 + 0x88180104, // 0015 GETMBR R6 R0 K4 + 0x7C100400, // 0016 CALL R4 2 + 0x90021004, // 0017 SETMBR R0 K8 R4 + 0x8C100708, // 0018 GETMET R4 R3 K8 + 0x88180104, // 0019 GETMBR R6 R0 K4 + 0x7C100400, // 001A CALL R4 2 + 0x90021204, // 001B SETMBR R0 K9 R4 + 0x84100000, // 001C CLOSURE R4 P0 + 0x90021404, // 001D SETMBR R0 K10 R4 + 0x9002170C, // 001E SETMBR R0 K11 K12 + 0xA0000000, // 001F CLOSE R0 + 0x80000000, // 0020 RET 0 }) ) ); @@ -421,7 +422,7 @@ be_local_closure(Leds_animator_init, /* name */ /******************************************************************** ** Solidified function: add_painter ********************************************************************/ -be_local_closure(Leds_animator_add_painter, /* name */ +be_local_closure(Animate_core_add_painter, /* name */ be_nested_proto( 5, /* nstack */ 2, /* argc */ @@ -452,7 +453,7 @@ be_local_closure(Leds_animator_add_painter, /* name */ /******************************************************************** ** Solidified function: fast_loop ********************************************************************/ -be_local_closure(Leds_animator_fast_loop, /* name */ +be_local_closure(Animate_core_fast_loop, /* name */ be_nested_proto( 12, /* nstack */ 1, /* argc */ @@ -585,7 +586,7 @@ be_local_closure(Leds_animator_fast_loop, /* name */ /******************************************************************** ** Solidified function: start ********************************************************************/ -be_local_closure(Leds_animator_start, /* name */ +be_local_closure(Animate_core_start, /* name */ be_nested_proto( 6, /* nstack */ 1, /* argc */ @@ -636,49 +637,49 @@ be_local_closure(Leds_animator_start, /* name */ /******************************************************************** -** Solidified class: Leds_animator +** Solidified class: Animate_core ********************************************************************/ -be_local_class(Leds_animator, +be_local_class(Animate_core, 13, NULL, be_nested_map(28, ( (struct bmapnode*) &(const bmapnode[]) { { be_const_key_weak(bri, 23), be_const_var(2) }, - { be_const_key_weak(remove, -1), be_const_closure(Leds_animator_remove_closure) }, - { be_const_key_weak(start, 21), be_const_closure(Leds_animator_start_closure) }, - { be_const_key_weak(fast_loop, -1), be_const_closure(Leds_animator_fast_loop_closure) }, - { be_const_key_weak(add_animator, -1), be_const_closure(Leds_animator_add_animator_closure) }, + { be_const_key_weak(remove, -1), be_const_closure(Animate_core_remove_closure) }, + { be_const_key_weak(start, 21), be_const_closure(Animate_core_start_closure) }, + { be_const_key_weak(fast_loop, -1), be_const_closure(Animate_core_fast_loop_closure) }, + { be_const_key_weak(add_animator, -1), be_const_closure(Animate_core_add_animator_closure) }, { be_const_key_weak(FAST_LOOP_MIN, 8), be_const_int(20) }, - { be_const_key_weak(animate, -1), be_const_closure(Leds_animator_animate_closure) }, + { be_const_key_weak(animate, -1), be_const_closure(Animate_core_animate_closure) }, { be_const_key_weak(pixel_count, -1), be_const_var(1) }, { be_const_key_weak(animators, -1), be_const_var(4) }, { be_const_key_weak(back_color, 11), be_const_var(12) }, { be_const_key_weak(fast_loop_cb, 12), be_const_var(6) }, { be_const_key_weak(frame, -1), be_const_var(10) }, { be_const_key_weak(animate_object, -1), be_const_var(8) }, - { be_const_key_weak(stop, -1), be_const_closure(Leds_animator_stop_closure) }, - { be_const_key_weak(init, -1), be_const_closure(Leds_animator_init_closure) }, - { be_const_key_weak(set_cb, 13), be_const_closure(Leds_animator_set_cb_closure) }, + { be_const_key_weak(stop, -1), be_const_closure(Animate_core_stop_closure) }, + { be_const_key_weak(init, -1), be_const_closure(Animate_core_init_closure) }, + { be_const_key_weak(set_cb, 13), be_const_closure(Animate_core_set_cb_closure) }, { be_const_key_weak(running, -1), be_const_var(3) }, { be_const_key_weak(strip, 15), be_const_var(0) }, { be_const_key_weak(fast_loop_next, -1), be_const_var(7) }, - { be_const_key_weak(set_back_color, 14), be_const_closure(Leds_animator_set_back_color_closure) }, - { be_const_key_weak(add_painter, -1), be_const_closure(Leds_animator_add_painter_closure) }, - { be_const_key_weak(set_bri, 24), be_const_closure(Leds_animator_set_bri_closure) }, + { be_const_key_weak(set_back_color, 14), be_const_closure(Animate_core_set_back_color_closure) }, + { be_const_key_weak(add_painter, -1), be_const_closure(Animate_core_add_painter_closure) }, + { be_const_key_weak(set_bri, 24), be_const_closure(Animate_core_set_bri_closure) }, { be_const_key_weak(layer, 9), be_const_var(11) }, { be_const_key_weak(animate_method, 6), be_const_var(9) }, - { be_const_key_weak(get_bri, -1), be_const_closure(Leds_animator_get_bri_closure) }, + { be_const_key_weak(get_bri, -1), be_const_closure(Animate_core_get_bri_closure) }, { be_const_key_weak(painters, -1), be_const_var(5) }, - { be_const_key_weak(clear, 3), be_const_closure(Leds_animator_clear_closure) }, - { be_const_key_weak(add_background_animator, 2), be_const_closure(Leds_animator_add_background_animator_closure) }, + { be_const_key_weak(clear, 3), be_const_closure(Animate_core_clear_closure) }, + { be_const_key_weak(add_background_animator, 2), be_const_closure(Animate_core_add_background_animator_closure) }, })), - be_str_weak(Leds_animator) + be_str_weak(Animate_core) ); /*******************************************************************/ -void be_load_Leds_animator_class(bvm *vm) { - be_pushntvclass(vm, &be_class_Leds_animator); - be_setglobal(vm, "Leds_animator"); +void be_load_Animate_core_class(bvm *vm) { + be_pushntvclass(vm, &be_class_Animate_core); + be_setglobal(vm, "Animate_core"); be_pop(vm, 1); } /********************************************************************/ diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_leds_1_animate_effects.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_1_animate_effects.h similarity index 89% rename from lib/libesp32/berry_tasmota/src/solidify/solidified_leds_1_animate_effects.h rename to lib/libesp32/berry_tasmota/src/solidify/solidified_animate_1_animate_effects.h index 1c2891e5b1c1..bb8b9dee31cc 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_leds_1_animate_effects.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_1_animate_effects.h @@ -1,15 +1,42 @@ -/* Solidification of leds_1_animate_effects.h */ +/* Solidification of animate_1_animate_effects.h */ /********************************************************************\ * Generated code, don't edit * \********************************************************************/ #include "be_constobj.h" -extern const bclass be_class_Leds_pulse; +extern const bclass be_class_Animate_pulse; + +/******************************************************************** +** Solidified function: set_pulse_size +********************************************************************/ +be_local_closure(Animate_pulse_set_pulse_size, /* name */ + be_nested_proto( + 2, /* nstack */ + 2, /* argc */ + 2, /* 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_str_weak(pulse_size), + }), + be_str_weak(set_pulse_size), + &be_const_str_solidified, + ( &(const binstruction[ 2]) { /* code */ + 0x90020001, // 0000 SETMBR R0 K0 R1 + 0x80000000, // 0001 RET 0 + }) + ) +); +/*******************************************************************/ + /******************************************************************** ** Solidified function: set_slew_size ********************************************************************/ -be_local_closure(Leds_pulse_set_slew_size, /* name */ +be_local_closure(Animate_pulse_set_slew_size, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -36,7 +63,7 @@ be_local_closure(Leds_pulse_set_slew_size, /* name */ /******************************************************************** ** Solidified function: set_back_color ********************************************************************/ -be_local_closure(Leds_pulse_set_back_color, /* name */ +be_local_closure(Animate_pulse_set_back_color, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -61,9 +88,9 @@ be_local_closure(Leds_pulse_set_back_color, /* name */ /******************************************************************** -** Solidified function: set_index +** Solidified function: set_pos ********************************************************************/ -be_local_closure(Leds_pulse_set_index, /* name */ +be_local_closure(Animate_pulse_set_pos, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -74,9 +101,9 @@ be_local_closure(Leds_pulse_set_index, /* name */ NULL, /* no sub protos */ 1, /* has constants */ ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_str_weak(index), + /* K0 */ be_nested_str_weak(pos), }), - be_str_weak(set_index), + be_str_weak(set_pos), &be_const_str_solidified, ( &(const binstruction[ 2]) { /* code */ 0x90020001, // 0000 SETMBR R0 K0 R1 @@ -88,9 +115,9 @@ be_local_closure(Leds_pulse_set_index, /* name */ /******************************************************************** -** Solidified function: set_pulse_size +** Solidified function: set_color ********************************************************************/ -be_local_closure(Leds_pulse_set_pulse_size, /* name */ +be_local_closure(Animate_pulse_set_color, /* name */ be_nested_proto( 2, /* nstack */ 2, /* argc */ @@ -101,9 +128,9 @@ be_local_closure(Leds_pulse_set_pulse_size, /* name */ NULL, /* no sub protos */ 1, /* has constants */ ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_str_weak(pulse_size), + /* K0 */ be_nested_str_weak(color), }), - be_str_weak(set_pulse_size), + be_str_weak(set_color), &be_const_str_solidified, ( &(const binstruction[ 2]) { /* code */ 0x90020001, // 0000 SETMBR R0 K0 R1 @@ -117,7 +144,7 @@ be_local_closure(Leds_pulse_set_pulse_size, /* name */ /******************************************************************** ** Solidified function: init ********************************************************************/ -be_local_closure(Leds_pulse_init, /* name */ +be_local_closure(Animate_pulse_init, /* name */ be_nested_proto( 5, /* nstack */ 4, /* argc */ @@ -169,37 +196,10 @@ be_local_closure(Leds_pulse_init, /* name */ /*******************************************************************/ -/******************************************************************** -** Solidified function: set_color -********************************************************************/ -be_local_closure(Leds_pulse_set_color, /* name */ - be_nested_proto( - 2, /* nstack */ - 2, /* argc */ - 2, /* 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_str_weak(color), - }), - be_str_weak(set_color), - &be_const_str_solidified, - ( &(const binstruction[ 2]) { /* code */ - 0x90020001, // 0000 SETMBR R0 K0 R1 - 0x80000000, // 0001 RET 0 - }) - ) -); -/*******************************************************************/ - - /******************************************************************** ** Solidified function: paint ********************************************************************/ -be_local_closure(Leds_pulse_paint, /* name */ +be_local_closure(Animate_pulse_paint, /* name */ be_nested_proto( 22, /* nstack */ 2, /* argc */ @@ -213,7 +213,7 @@ be_local_closure(Leds_pulse_paint, /* name */ /* K0 */ be_nested_str_weak(back_color), /* K1 */ be_const_int(-16777216), /* K2 */ be_nested_str_weak(fill_pixels), - /* K3 */ be_nested_str_weak(index), + /* K3 */ be_nested_str_weak(pos), /* K4 */ be_nested_str_weak(slew_size), /* K5 */ be_nested_str_weak(pulse_size), /* K6 */ be_nested_str_weak(color), @@ -325,33 +325,33 @@ be_local_closure(Leds_pulse_paint, /* name */ /******************************************************************** -** Solidified class: Leds_pulse +** Solidified class: Animate_pulse ********************************************************************/ -be_local_class(Leds_pulse, +be_local_class(Animate_pulse, 5, NULL, be_nested_map(12, ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(paint, 9), be_const_closure(Leds_pulse_paint_closure) }, - { be_const_key_weak(set_slew_size, -1), be_const_closure(Leds_pulse_set_slew_size_closure) }, + { be_const_key_weak(paint, -1), be_const_closure(Animate_pulse_paint_closure) }, + { be_const_key_weak(set_slew_size, -1), be_const_closure(Animate_pulse_set_slew_size_closure) }, { be_const_key_weak(pulse_size, -1), be_const_var(4) }, - { be_const_key_weak(set_back_color, 6), be_const_closure(Leds_pulse_set_back_color_closure) }, - { be_const_key_weak(set_index, 7), be_const_closure(Leds_pulse_set_index_closure) }, - { be_const_key_weak(back_color, -1), be_const_var(1) }, - { be_const_key_weak(set_color, 8), be_const_closure(Leds_pulse_set_color_closure) }, + { be_const_key_weak(set_back_color, 8), be_const_closure(Animate_pulse_set_back_color_closure) }, { be_const_key_weak(color, -1), be_const_var(0) }, - { be_const_key_weak(init, -1), be_const_closure(Leds_pulse_init_closure) }, - { be_const_key_weak(set_pulse_size, -1), be_const_closure(Leds_pulse_set_pulse_size_closure) }, + { be_const_key_weak(back_color, -1), be_const_var(1) }, + { be_const_key_weak(set_pos, -1), be_const_closure(Animate_pulse_set_pos_closure) }, + { be_const_key_weak(set_color, -1), be_const_closure(Animate_pulse_set_color_closure) }, + { be_const_key_weak(init, 7), be_const_closure(Animate_pulse_init_closure) }, + { be_const_key_weak(pos, -1), be_const_var(2) }, { be_const_key_weak(slew_size, 5), be_const_var(3) }, - { be_const_key_weak(index, 0), be_const_var(2) }, + { be_const_key_weak(set_pulse_size, 0), be_const_closure(Animate_pulse_set_pulse_size_closure) }, })), - be_str_weak(Leds_pulse) + be_str_weak(Animate_pulse) ); /*******************************************************************/ -void be_load_Leds_pulse_class(bvm *vm) { - be_pushntvclass(vm, &be_class_Leds_pulse); - be_setglobal(vm, "Leds_pulse"); +void be_load_Animate_pulse_class(bvm *vm) { + be_pushntvclass(vm, &be_class_Animate_pulse); + be_setglobal(vm, "Animate_pulse"); be_pop(vm, 1); } /********************************************************************/ diff --git a/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_module.h b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_9_module.h similarity index 60% rename from lib/libesp32/berry_tasmota/src/solidify/solidified_animate_module.h rename to lib/libesp32/berry_tasmota/src/solidify/solidified_animate_9_module.h index 5d0f45c10d16..a337b5f826d4 100644 --- a/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_module.h +++ b/lib/libesp32/berry_tasmota/src/solidify/solidified_animate_9_module.h @@ -1,17 +1,17 @@ -/* Solidification of animate_module.h */ +/* Solidification of animate_9_module.h */ /********************************************************************\ * Generated code, don't edit * \********************************************************************/ #include "be_constobj.h" -extern const bclass be_class_Animate_palette; +extern const bclass be_class_Animate_animator; /******************************************************************** -** Solidified function: to_css_gradient +** Solidified function: is_running ********************************************************************/ -be_local_closure(Animate_palette_to_css_gradient, /* name */ +be_local_closure(Animate_animator_is_running, /* name */ be_nested_proto( - 15, /* nstack */ + 3, /* nstack */ 1, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -19,62 +19,16 @@ be_local_closure(Animate_palette_to_css_gradient, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[ 9]) { /* constants */ - /* K0 */ be_nested_str_weak(parse_palette), - /* K1 */ be_const_int(0), - /* K2 */ be_nested_str_weak(background_X3Alinear_X2Dgradient_X28to_X20right), - /* K3 */ be_nested_str_weak(palette), - /* K4 */ be_nested_str_weak(get), - /* K5 */ be_nested_str_weak(_X2C_X23_X2502X_X2502X_X2502X_X20_X25_X2E1f_X25_X25), - /* K6 */ be_const_real_hex(0x41200000), - /* K7 */ be_const_int(1), - /* K8 */ be_nested_str_weak(_X29_X3B), + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_str_weak(running), }), - be_str_weak(to_css_gradient), + be_str_weak(is_running), &be_const_str_solidified, - ( &(const binstruction[42]) { /* code */ - 0x8C040100, // 0000 GETMET R1 R0 K0 - 0x580C0001, // 0001 LDCONST R3 K1 - 0x541203E7, // 0002 LDINT R4 1000 - 0x7C040600, // 0003 CALL R1 3 - 0x58080002, // 0004 LDCONST R2 K2 - 0x580C0001, // 0005 LDCONST R3 K1 - 0x6010000C, // 0006 GETGBL R4 G12 - 0x5C140200, // 0007 MOVE R5 R1 - 0x7C100200, // 0008 CALL R4 1 - 0x14100604, // 0009 LT R4 R3 R4 - 0x7812001C, // 000A JMPF R4 #0028 - 0x94100203, // 000B GETIDX R4 R1 R3 - 0x88140103, // 000C GETMBR R5 R0 K3 - 0x8C140B04, // 000D GETMET R5 R5 K4 - 0x541E0003, // 000E LDINT R7 4 - 0x081C0607, // 000F MUL R7 R3 R7 - 0x54220003, // 0010 LDINT R8 4 - 0x7C140600, // 0011 CALL R5 3 - 0x541A0007, // 0012 LDINT R6 8 - 0x3C180A06, // 0013 SHR R6 R5 R6 - 0x541E00FE, // 0014 LDINT R7 255 - 0x2C180C07, // 0015 AND R6 R6 R7 - 0x541E000F, // 0016 LDINT R7 16 - 0x3C1C0A07, // 0017 SHR R7 R5 R7 - 0x542200FE, // 0018 LDINT R8 255 - 0x2C1C0E08, // 0019 AND R7 R7 R8 - 0x54220017, // 001A LDINT R8 24 - 0x3C200A08, // 001B SHR R8 R5 R8 - 0x542600FE, // 001C LDINT R9 255 - 0x2C201009, // 001D AND R8 R8 R9 - 0x60240018, // 001E GETGBL R9 G24 - 0x58280005, // 001F LDCONST R10 K5 - 0x5C2C0C00, // 0020 MOVE R11 R6 - 0x5C300E00, // 0021 MOVE R12 R7 - 0x5C341000, // 0022 MOVE R13 R8 - 0x0C380906, // 0023 DIV R14 R4 K6 - 0x7C240A00, // 0024 CALL R9 5 - 0x00080409, // 0025 ADD R2 R2 R9 - 0x000C0707, // 0026 ADD R3 R3 K7 - 0x7001FFDD, // 0027 JMP #0006 - 0x00080508, // 0028 ADD R2 R2 K8 - 0x80040400, // 0029 RET 1 R2 + ( &(const binstruction[ 4]) { /* code */ + 0x60040017, // 0000 GETGBL R1 G23 + 0x88080100, // 0001 GETMBR R2 R0 K0 + 0x7C040200, // 0002 CALL R1 1 + 0x80040200, // 0003 RET 1 R1 }) ) ); @@ -82,102 +36,23 @@ be_local_closure(Animate_palette_to_css_gradient, /* name */ /******************************************************************** -** Solidified function: parse_palette +** Solidified function: beat ********************************************************************/ -be_local_closure(Animate_palette_parse_palette, /* name */ +be_local_closure(Animate_animator_beat, /* name */ be_nested_proto( - 15, /* nstack */ - 3, /* argc */ + 1, /* nstack */ + 1, /* argc */ 2, /* 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_str_weak(slots), - /* K1 */ be_nested_str_weak(resize), - /* K2 */ be_nested_str_weak(palette), - /* K3 */ be_nested_str_weak(get), - /* K4 */ be_const_int(0), - /* K5 */ be_const_int(1), - /* K6 */ be_nested_str_weak(tasmota), - /* K7 */ be_nested_str_weak(scale_int), - }), - be_str_weak(parse_palette), + 0, /* has constants */ + NULL, /* no const */ + be_str_weak(beat), &be_const_str_solidified, - ( &(const binstruction[71]) { /* code */ - 0x600C0012, // 0000 GETGBL R3 G18 - 0x7C0C0000, // 0001 CALL R3 0 - 0x88100100, // 0002 GETMBR R4 R0 K0 - 0x8C140701, // 0003 GETMET R5 R3 K1 - 0x5C1C0800, // 0004 MOVE R7 R4 - 0x7C140400, // 0005 CALL R5 2 - 0x88140102, // 0006 GETMBR R5 R0 K2 - 0x8C140B03, // 0007 GETMET R5 R5 K3 - 0x581C0004, // 0008 LDCONST R7 K4 - 0x58200005, // 0009 LDCONST R8 K5 - 0x7C140600, // 000A CALL R5 3 - 0x20140B04, // 000B NE R5 R5 K4 - 0x78160024, // 000C JMPF R5 #0032 - 0x58140004, // 000D LDCONST R5 K4 - 0x58180004, // 000E LDCONST R6 K4 - 0x041C0905, // 000F SUB R7 R4 K5 - 0x141C0C07, // 0010 LT R7 R6 R7 - 0x781E0008, // 0011 JMPF R7 #001B - 0x881C0102, // 0012 GETMBR R7 R0 K2 - 0x8C1C0F03, // 0013 GETMET R7 R7 K3 - 0x54260003, // 0014 LDINT R9 4 - 0x08240C09, // 0015 MUL R9 R6 R9 - 0x58280005, // 0016 LDCONST R10 K5 - 0x7C1C0600, // 0017 CALL R7 3 - 0x00140A07, // 0018 ADD R5 R5 R7 - 0x00180D05, // 0019 ADD R6 R6 K5 - 0x7001FFF3, // 001A JMP #000F - 0x581C0004, // 001B LDCONST R7 K4 - 0x58180004, // 001C LDCONST R6 K4 - 0x14200C04, // 001D LT R8 R6 R4 - 0x78220011, // 001E JMPF R8 #0031 - 0xB8220C00, // 001F GETNGBL R8 K6 - 0x8C201107, // 0020 GETMET R8 R8 K7 - 0x5C280E00, // 0021 MOVE R10 R7 - 0x582C0004, // 0022 LDCONST R11 K4 - 0x5C300A00, // 0023 MOVE R12 R5 - 0x5C340200, // 0024 MOVE R13 R1 - 0x5C380400, // 0025 MOVE R14 R2 - 0x7C200C00, // 0026 CALL R8 6 - 0x980C0C08, // 0027 SETIDX R3 R6 R8 - 0x88200102, // 0028 GETMBR R8 R0 K2 - 0x8C201103, // 0029 GETMET R8 R8 K3 - 0x542A0003, // 002A LDINT R10 4 - 0x08280C0A, // 002B MUL R10 R6 R10 - 0x582C0005, // 002C LDCONST R11 K5 - 0x7C200600, // 002D CALL R8 3 - 0x001C0E08, // 002E ADD R7 R7 R8 - 0x00180D05, // 002F ADD R6 R6 K5 - 0x7001FFEB, // 0030 JMP #001D - 0x70020013, // 0031 JMP #0046 - 0x58140004, // 0032 LDCONST R5 K4 - 0x14180A04, // 0033 LT R6 R5 R4 - 0x781A0010, // 0034 JMPF R6 #0046 - 0x88180102, // 0035 GETMBR R6 R0 K2 - 0x8C180D03, // 0036 GETMET R6 R6 K3 - 0x54220003, // 0037 LDINT R8 4 - 0x08200A08, // 0038 MUL R8 R5 R8 - 0x58240005, // 0039 LDCONST R9 K5 - 0x7C180600, // 003A CALL R6 3 - 0xB81E0C00, // 003B GETNGBL R7 K6 - 0x8C1C0F07, // 003C GETMET R7 R7 K7 - 0x5C240C00, // 003D MOVE R9 R6 - 0x58280004, // 003E LDCONST R10 K4 - 0x542E00FE, // 003F LDINT R11 255 - 0x5C300200, // 0040 MOVE R12 R1 - 0x5C340400, // 0041 MOVE R13 R2 - 0x7C1C0C00, // 0042 CALL R7 6 - 0x980C0A07, // 0043 SETIDX R3 R5 R7 - 0x00140B05, // 0044 ADD R5 R5 K5 - 0x7001FFEC, // 0045 JMP #0033 - 0x80040600, // 0046 RET 1 R3 + ( &(const binstruction[ 1]) { /* code */ + 0x80000000, // 0000 RET 0 }) ) ); @@ -187,55 +62,82 @@ be_local_closure(Animate_palette_parse_palette, /* name */ /******************************************************************** ** Solidified function: init ********************************************************************/ -be_local_closure(Animate_palette_init, /* name */ +be_local_closure(Animate_animator_init, /* name */ be_nested_proto( - 7, /* nstack */ - 3, /* argc */ + 2, /* nstack */ + 2, /* argc */ 2, /* 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_str_weak(running), - /* K1 */ be_nested_str_weak(palette), - /* K2 */ be_nested_str_weak(bri), - /* K3 */ be_nested_str_weak(slots), - /* K4 */ be_nested_str_weak(set_duration), - /* K5 */ be_nested_str_weak(color), - /* K6 */ be_nested_str_weak(light_state), - /* K7 */ be_nested_str_weak(RGB), + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_str_weak(duration_ms), }), be_str_weak(init), &be_const_str_solidified, - ( &(const binstruction[26]) { /* code */ - 0x500C0000, // 0000 LDBOOL R3 0 0 - 0x90020003, // 0001 SETMBR R0 K0 R3 - 0x90020201, // 0002 SETMBR R0 K1 R1 - 0x540E0063, // 0003 LDINT R3 100 - 0x90020403, // 0004 SETMBR R0 K2 R3 - 0x600C000C, // 0005 GETGBL R3 G12 - 0x5C100200, // 0006 MOVE R4 R1 - 0x7C0C0200, // 0007 CALL R3 1 - 0x54120003, // 0008 LDINT R4 4 - 0x0C0C0604, // 0009 DIV R3 R3 R4 - 0x90020603, // 000A SETMBR R0 K3 R3 - 0x4C0C0000, // 000B LDNIL R3 - 0x200C0403, // 000C NE R3 R2 R3 - 0x780E0005, // 000D JMPF R3 #0014 - 0x8C0C0104, // 000E GETMET R3 R0 K4 - 0x60140009, // 000F GETGBL R5 G9 - 0x541A03E7, // 0010 LDINT R6 1000 - 0x08180406, // 0011 MUL R6 R2 R6 - 0x7C140200, // 0012 CALL R5 1 - 0x7C0C0400, // 0013 CALL R3 2 - 0xB80E0C00, // 0014 GETNGBL R3 K6 - 0xB8120C00, // 0015 GETNGBL R4 K6 - 0x88100907, // 0016 GETMBR R4 R4 K7 - 0x7C0C0200, // 0017 CALL R3 1 - 0x90020A03, // 0018 SETMBR R0 K5 R3 - 0x80000000, // 0019 RET 0 + ( &(const binstruction[ 2]) { /* code */ + 0x90020001, // 0000 SETMBR R0 K0 R1 + 0x80000000, // 0001 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: stop +********************************************************************/ +be_local_closure(Animate_animator_stop, /* name */ + be_nested_proto( + 2, /* nstack */ + 1, /* argc */ + 2, /* 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_str_weak(origin), + /* K1 */ be_nested_str_weak(running), + }), + be_str_weak(stop), + &be_const_str_solidified, + ( &(const binstruction[ 5]) { /* code */ + 0x4C040000, // 0000 LDNIL R1 + 0x90020001, // 0001 SETMBR R0 K0 R1 + 0x50040000, // 0002 LDBOOL R1 0 0 + 0x90020201, // 0003 SETMBR R0 K1 R1 + 0x80000000, // 0004 RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: set_duration_ms +********************************************************************/ +be_local_closure(Animate_animator_set_duration_ms, /* name */ + be_nested_proto( + 2, /* nstack */ + 2, /* argc */ + 2, /* 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_str_weak(duration_ms), + }), + be_str_weak(set_duration_ms), + &be_const_str_solidified, + ( &(const binstruction[ 2]) { /* code */ + 0x90020001, // 0000 SETMBR R0 K0 R1 + 0x80000000, // 0001 RET 0 }) ) ); @@ -245,7 +147,7 @@ be_local_closure(Animate_palette_init, /* name */ /******************************************************************** ** Solidified function: set_cb ********************************************************************/ -be_local_closure(Animate_palette_set_cb, /* name */ +be_local_closure(Animate_animator_set_cb, /* name */ be_nested_proto( 3, /* nstack */ 3, /* argc */ @@ -256,8 +158,8 @@ be_local_closure(Animate_palette_set_cb, /* name */ NULL, /* no sub protos */ 1, /* has constants */ ( &(const bvalue[ 2]) { /* constants */ - /* K0 */ be_nested_str_weak(animate_obj), - /* K1 */ be_nested_str_weak(animate_mth), + /* K0 */ be_nested_str_weak(obj), + /* K1 */ be_nested_str_weak(mth), }), be_str_weak(set_cb), &be_const_str_solidified, @@ -272,30 +174,150 @@ be_local_closure(Animate_palette_set_cb, /* name */ /******************************************************************** -** Solidified function: stop +** Solidified function: start ********************************************************************/ -be_local_closure(Animate_palette_stop, /* name */ +be_local_closure(Animate_animator_start, /* name */ be_nested_proto( - 2, /* nstack */ - 1, /* argc */ + 4, /* nstack */ + 2, /* argc */ 2, /* 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_str_weak(origin), + ( &(const bvalue[ 5]) { /* constants */ + /* K0 */ be_nested_str_weak(duration_ms), + /* K1 */ be_nested_str_weak(tasmota), + /* K2 */ be_nested_str_weak(millis), + /* K3 */ be_nested_str_weak(origin), + /* K4 */ be_nested_str_weak(running), + }), + be_str_weak(start), + &be_const_str_solidified, + ( &(const binstruction[16]) { /* code */ + 0x88080100, // 0000 GETMBR R2 R0 K0 + 0x4C0C0000, // 0001 LDNIL R3 + 0x1C080403, // 0002 EQ R2 R2 R3 + 0x780A0000, // 0003 JMPF R2 #0005 + 0x80000400, // 0004 RET 0 + 0x4C080000, // 0005 LDNIL R2 + 0x1C080202, // 0006 EQ R2 R1 R2 + 0x780A0003, // 0007 JMPF R2 #000C + 0xB80A0200, // 0008 GETNGBL R2 K1 + 0x8C080502, // 0009 GETMET R2 R2 K2 + 0x7C080200, // 000A CALL R2 1 + 0x5C040400, // 000B MOVE R1 R2 + 0x90020601, // 000C SETMBR R0 K3 R1 + 0x50080200, // 000D LDBOOL R2 1 0 + 0x90020802, // 000E SETMBR R0 K4 R2 + 0x80000000, // 000F RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified class: Animate_animator +********************************************************************/ +be_local_class(Animate_animator, + 5, + NULL, + be_nested_map(12, + ( (struct bmapnode*) &(const bmapnode[]) { + { be_const_key_weak(running, 4), be_const_var(0) }, + { be_const_key_weak(is_running, 2), be_const_closure(Animate_animator_is_running_closure) }, + { be_const_key_weak(beat, -1), be_const_closure(Animate_animator_beat_closure) }, + { be_const_key_weak(init, -1), be_const_closure(Animate_animator_init_closure) }, + { be_const_key_weak(mth, -1), be_const_var(4) }, + { be_const_key_weak(stop, -1), be_const_closure(Animate_animator_stop_closure) }, + { be_const_key_weak(duration_ms, -1), be_const_var(1) }, + { be_const_key_weak(origin, -1), be_const_var(2) }, + { be_const_key_weak(set_cb, -1), be_const_closure(Animate_animator_set_cb_closure) }, + { be_const_key_weak(set_duration_ms, 8), be_const_closure(Animate_animator_set_duration_ms_closure) }, + { be_const_key_weak(obj, -1), be_const_var(3) }, + { be_const_key_weak(start, -1), be_const_closure(Animate_animator_start_closure) }, + })), + be_str_weak(Animate_animator) +); +/*******************************************************************/ + +void be_load_Animate_animator_class(bvm *vm) { + be_pushntvclass(vm, &be_class_Animate_animator); + be_setglobal(vm, "Animate_animator"); + be_pop(vm, 1); +} + +extern const bclass be_class_Animate_palette; + +/******************************************************************** +** Solidified function: init +********************************************************************/ +be_local_closure(Animate_palette_init, /* name */ + be_nested_proto( + 6, /* nstack */ + 3, /* argc */ + 2, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[11]) { /* constants */ + /* K0 */ be_nested_str_weak(init), /* K1 */ be_nested_str_weak(running), + /* K2 */ be_nested_str_weak(ptr), + /* K3 */ be_nested_str_weak(ptr_to_palette), + /* K4 */ be_nested_str_weak(palette), + /* K5 */ be_nested_str_weak(bri), + /* K6 */ be_nested_str_weak(slots), + /* K7 */ be_nested_str_weak(set_duration), + /* K8 */ be_nested_str_weak(color), + /* K9 */ be_nested_str_weak(light_state), + /* K10 */ be_nested_str_weak(RGB), }), - be_str_weak(stop), + be_str_weak(init), &be_const_str_solidified, - ( &(const binstruction[ 5]) { /* code */ - 0x4C040000, // 0000 LDNIL R1 - 0x90020001, // 0001 SETMBR R0 K0 R1 - 0x50040000, // 0002 LDBOOL R1 0 0 - 0x90020201, // 0003 SETMBR R0 K1 R1 - 0x80000000, // 0004 RET 0 + ( &(const binstruction[38]) { /* code */ + 0x600C0003, // 0000 GETGBL R3 G3 + 0x5C100000, // 0001 MOVE R4 R0 + 0x7C0C0200, // 0002 CALL R3 1 + 0x8C0C0700, // 0003 GETMET R3 R3 K0 + 0x5C140400, // 0004 MOVE R5 R2 + 0x7C0C0400, // 0005 CALL R3 2 + 0x500C0000, // 0006 LDBOOL R3 0 0 + 0x90020203, // 0007 SETMBR R0 K1 R3 + 0x600C0004, // 0008 GETGBL R3 G4 + 0x5C100200, // 0009 MOVE R4 R1 + 0x7C0C0200, // 000A CALL R3 1 + 0x1C0C0702, // 000B EQ R3 R3 K2 + 0x780E0003, // 000C JMPF R3 #0011 + 0x8C0C0103, // 000D GETMET R3 R0 K3 + 0x5C140200, // 000E MOVE R5 R1 + 0x7C0C0400, // 000F CALL R3 2 + 0x5C040600, // 0010 MOVE R1 R3 + 0x90020801, // 0011 SETMBR R0 K4 R1 + 0x540E0063, // 0012 LDINT R3 100 + 0x90020A03, // 0013 SETMBR R0 K5 R3 + 0x600C000C, // 0014 GETGBL R3 G12 + 0x5C100200, // 0015 MOVE R4 R1 + 0x7C0C0200, // 0016 CALL R3 1 + 0x54120003, // 0017 LDINT R4 4 + 0x0C0C0604, // 0018 DIV R3 R3 R4 + 0x90020C03, // 0019 SETMBR R0 K6 R3 + 0x4C0C0000, // 001A LDNIL R3 + 0x200C0403, // 001B NE R3 R2 R3 + 0x780E0002, // 001C JMPF R3 #0020 + 0x8C0C0107, // 001D GETMET R3 R0 K7 + 0x5C140400, // 001E MOVE R5 R2 + 0x7C0C0400, // 001F CALL R3 2 + 0xB80E1200, // 0020 GETNGBL R3 K9 + 0xB8121200, // 0021 GETNGBL R4 K9 + 0x8810090A, // 0022 GETMBR R4 R4 K10 + 0x7C0C0200, // 0023 CALL R3 1 + 0x90021003, // 0024 SETMBR R0 K8 R3 + 0x80000000, // 0025 RET 0 }) ) ); @@ -335,8 +357,8 @@ be_local_closure(Animate_palette_animate, /* name */ /* K16 */ be_nested_str_weak(r), /* K17 */ be_nested_str_weak(g), /* K18 */ be_nested_str_weak(b), - /* K19 */ be_nested_str_weak(animate_obj), - /* K20 */ be_nested_str_weak(animate_mth), + /* K19 */ be_nested_str_weak(obj), + /* K20 */ be_nested_str_weak(mth), }), be_str_weak(animate), &be_const_str_solidified, @@ -541,23 +563,96 @@ be_local_closure(Animate_palette_animate, /* name */ /******************************************************************** -** Solidified function: set_range +** Solidified function: ptr_to_palette ********************************************************************/ -be_local_closure(Animate_palette_set_range, /* name */ +be_local_closure(Animate_palette_ptr_to_palette, /* name */ be_nested_proto( - 7, /* nstack */ - 3, /* argc */ - 2, /* varg */ + 8, /* nstack */ + 1, /* argc */ + 4, /* 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_str_weak(value_error), - /* K1 */ be_nested_str_weak(min_X20must_X20be_X20lower_X20than_X20mex), - /* K2 */ be_nested_str_weak(range_min), - /* K3 */ be_nested_str_weak(range_max), + ( &(const bvalue[ 4]) { /* constants */ + /* K0 */ be_const_class(be_class_Animate_palette), + /* K1 */ be_nested_str_weak(ptr), + /* K2 */ be_const_int(1), + /* K3 */ be_const_int(0), + }), + be_str_weak(ptr_to_palette), + &be_const_str_solidified, + ( &(const binstruction[45]) { /* code */ + 0x58040000, // 0000 LDCONST R1 K0 + 0x60080004, // 0001 GETGBL R2 G4 + 0x5C0C0000, // 0002 MOVE R3 R0 + 0x7C080200, // 0003 CALL R2 1 + 0x1C080501, // 0004 EQ R2 R2 K1 + 0x780A0025, // 0005 JMPF R2 #002C + 0x60080015, // 0006 GETGBL R2 G21 + 0x5C0C0000, // 0007 MOVE R3 R0 + 0x541207CF, // 0008 LDINT R4 2000 + 0x7C080400, // 0009 CALL R2 2 + 0x580C0002, // 000A LDCONST R3 K2 + 0x94100503, // 000B GETIDX R4 R2 K3 + 0x20100903, // 000C NE R4 R4 K3 + 0x7812000A, // 000D JMPF R4 #0019 + 0x50100200, // 000E LDBOOL R4 1 0 + 0x78120007, // 000F JMPF R4 #0018 + 0x54120003, // 0010 LDINT R4 4 + 0x08100604, // 0011 MUL R4 R3 R4 + 0x94100404, // 0012 GETIDX R4 R2 R4 + 0x1C100903, // 0013 EQ R4 R4 K3 + 0x78120000, // 0014 JMPF R4 #0016 + 0x70020001, // 0015 JMP #0018 + 0x000C0702, // 0016 ADD R3 R3 K2 + 0x7001FFF5, // 0017 JMP #000E + 0x7002000A, // 0018 JMP #0024 + 0x50100200, // 0019 LDBOOL R4 1 0 + 0x78120008, // 001A JMPF R4 #0024 + 0x54120003, // 001B LDINT R4 4 + 0x08100604, // 001C MUL R4 R3 R4 + 0x94100404, // 001D GETIDX R4 R2 R4 + 0x541600FE, // 001E LDINT R5 255 + 0x1C100805, // 001F EQ R4 R4 R5 + 0x78120000, // 0020 JMPF R4 #0022 + 0x70020001, // 0021 JMP #0024 + 0x000C0702, // 0022 ADD R3 R3 K2 + 0x7001FFF4, // 0023 JMP #0019 + 0x00100702, // 0024 ADD R4 R3 K2 + 0x54160003, // 0025 LDINT R5 4 + 0x08100805, // 0026 MUL R4 R4 R5 + 0x60140015, // 0027 GETGBL R5 G21 + 0x5C180000, // 0028 MOVE R6 R0 + 0x5C1C0800, // 0029 MOVE R7 R4 + 0x7C140400, // 002A CALL R5 2 + 0x80040A00, // 002B RET 1 R5 + 0x80000000, // 002C RET 0 + }) + ) +); +/*******************************************************************/ + + +/******************************************************************** +** Solidified function: set_range +********************************************************************/ +be_local_closure(Animate_palette_set_range, /* name */ + be_nested_proto( + 7, /* nstack */ + 3, /* argc */ + 2, /* 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_str_weak(value_error), + /* K1 */ be_nested_str_weak(min_X20must_X20be_X20lower_X20than_X20mex), + /* K2 */ be_nested_str_weak(range_min), + /* K3 */ be_nested_str_weak(range_max), /* K4 */ be_nested_str_weak(slots_arr), /* K5 */ be_nested_str_weak(parse_palette), }), @@ -582,29 +677,102 @@ be_local_closure(Animate_palette_set_range, /* name */ /******************************************************************** -** Solidified function: set_bri +** Solidified function: parse_palette ********************************************************************/ -be_local_closure(Animate_palette_set_bri, /* name */ +be_local_closure(Animate_palette_parse_palette, /* name */ be_nested_proto( - 4, /* nstack */ - 2, /* argc */ + 15, /* nstack */ + 3, /* argc */ 2, /* 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_str_weak(bri), + ( &(const bvalue[ 8]) { /* constants */ + /* K0 */ be_nested_str_weak(slots), + /* K1 */ be_nested_str_weak(resize), + /* K2 */ be_nested_str_weak(palette), + /* K3 */ be_nested_str_weak(get), + /* K4 */ be_const_int(0), + /* K5 */ be_const_int(1), + /* K6 */ be_nested_str_weak(tasmota), + /* K7 */ be_nested_str_weak(scale_int), }), - be_str_weak(set_bri), + be_str_weak(parse_palette), &be_const_str_solidified, - ( &(const binstruction[ 5]) { /* code */ - 0x60080009, // 0000 GETGBL R2 G9 - 0x5C0C0200, // 0001 MOVE R3 R1 - 0x7C080200, // 0002 CALL R2 1 - 0x90020002, // 0003 SETMBR R0 K0 R2 - 0x80000000, // 0004 RET 0 + ( &(const binstruction[71]) { /* code */ + 0x600C0012, // 0000 GETGBL R3 G18 + 0x7C0C0000, // 0001 CALL R3 0 + 0x88100100, // 0002 GETMBR R4 R0 K0 + 0x8C140701, // 0003 GETMET R5 R3 K1 + 0x5C1C0800, // 0004 MOVE R7 R4 + 0x7C140400, // 0005 CALL R5 2 + 0x88140102, // 0006 GETMBR R5 R0 K2 + 0x8C140B03, // 0007 GETMET R5 R5 K3 + 0x581C0004, // 0008 LDCONST R7 K4 + 0x58200005, // 0009 LDCONST R8 K5 + 0x7C140600, // 000A CALL R5 3 + 0x20140B04, // 000B NE R5 R5 K4 + 0x78160024, // 000C JMPF R5 #0032 + 0x58140004, // 000D LDCONST R5 K4 + 0x58180004, // 000E LDCONST R6 K4 + 0x041C0905, // 000F SUB R7 R4 K5 + 0x141C0C07, // 0010 LT R7 R6 R7 + 0x781E0008, // 0011 JMPF R7 #001B + 0x881C0102, // 0012 GETMBR R7 R0 K2 + 0x8C1C0F03, // 0013 GETMET R7 R7 K3 + 0x54260003, // 0014 LDINT R9 4 + 0x08240C09, // 0015 MUL R9 R6 R9 + 0x58280005, // 0016 LDCONST R10 K5 + 0x7C1C0600, // 0017 CALL R7 3 + 0x00140A07, // 0018 ADD R5 R5 R7 + 0x00180D05, // 0019 ADD R6 R6 K5 + 0x7001FFF3, // 001A JMP #000F + 0x581C0004, // 001B LDCONST R7 K4 + 0x58180004, // 001C LDCONST R6 K4 + 0x14200C04, // 001D LT R8 R6 R4 + 0x78220011, // 001E JMPF R8 #0031 + 0xB8220C00, // 001F GETNGBL R8 K6 + 0x8C201107, // 0020 GETMET R8 R8 K7 + 0x5C280E00, // 0021 MOVE R10 R7 + 0x582C0004, // 0022 LDCONST R11 K4 + 0x5C300A00, // 0023 MOVE R12 R5 + 0x5C340200, // 0024 MOVE R13 R1 + 0x5C380400, // 0025 MOVE R14 R2 + 0x7C200C00, // 0026 CALL R8 6 + 0x980C0C08, // 0027 SETIDX R3 R6 R8 + 0x88200102, // 0028 GETMBR R8 R0 K2 + 0x8C201103, // 0029 GETMET R8 R8 K3 + 0x542A0003, // 002A LDINT R10 4 + 0x08280C0A, // 002B MUL R10 R6 R10 + 0x582C0005, // 002C LDCONST R11 K5 + 0x7C200600, // 002D CALL R8 3 + 0x001C0E08, // 002E ADD R7 R7 R8 + 0x00180D05, // 002F ADD R6 R6 K5 + 0x7001FFEB, // 0030 JMP #001D + 0x70020013, // 0031 JMP #0046 + 0x58140004, // 0032 LDCONST R5 K4 + 0x14180A04, // 0033 LT R6 R5 R4 + 0x781A0010, // 0034 JMPF R6 #0046 + 0x88180102, // 0035 GETMBR R6 R0 K2 + 0x8C180D03, // 0036 GETMET R6 R6 K3 + 0x54220003, // 0037 LDINT R8 4 + 0x08200A08, // 0038 MUL R8 R5 R8 + 0x58240005, // 0039 LDCONST R9 K5 + 0x7C180600, // 003A CALL R6 3 + 0xB81E0C00, // 003B GETNGBL R7 K6 + 0x8C1C0F07, // 003C GETMET R7 R7 K7 + 0x5C240C00, // 003D MOVE R9 R6 + 0x58280004, // 003E LDCONST R10 K4 + 0x542E00FE, // 003F LDINT R11 255 + 0x5C300200, // 0040 MOVE R12 R1 + 0x5C340400, // 0041 MOVE R13 R2 + 0x7C1C0C00, // 0042 CALL R7 6 + 0x980C0A07, // 0043 SETIDX R3 R5 R7 + 0x00140B05, // 0044 ADD R5 R5 K5 + 0x7001FFEC, // 0045 JMP #0033 + 0x80040600, // 0046 RET 1 R3 }) ) ); @@ -612,12 +780,12 @@ be_local_closure(Animate_palette_set_bri, /* name */ /******************************************************************** -** Solidified function: is_running +** Solidified function: set_bri ********************************************************************/ -be_local_closure(Animate_palette_is_running, /* name */ +be_local_closure(Animate_palette_set_bri, /* name */ be_nested_proto( - 3, /* nstack */ - 1, /* argc */ + 4, /* nstack */ + 2, /* argc */ 2, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ @@ -625,15 +793,16 @@ be_local_closure(Animate_palette_is_running, /* name */ NULL, /* no sub protos */ 1, /* has constants */ ( &(const bvalue[ 1]) { /* constants */ - /* K0 */ be_nested_str_weak(running), + /* K0 */ be_nested_str_weak(bri), }), - be_str_weak(is_running), + be_str_weak(set_bri), &be_const_str_solidified, - ( &(const binstruction[ 4]) { /* code */ - 0x60040017, // 0000 GETGBL R1 G23 - 0x88080100, // 0001 GETMBR R2 R0 K0 - 0x7C040200, // 0002 CALL R1 1 - 0x80040200, // 0003 RET 1 R1 + ( &(const binstruction[ 5]) { /* code */ + 0x60080009, // 0000 GETGBL R2 G9 + 0x5C0C0200, // 0001 MOVE R3 R1 + 0x7C080200, // 0002 CALL R2 1 + 0x90020002, // 0003 SETMBR R0 K0 R2 + 0x80000000, // 0004 RET 0 }) ) ); @@ -710,8 +879,8 @@ be_local_closure(Animate_palette_set_value, /* name */ /* K8 */ be_const_int(1), /* K9 */ be_nested_str_weak(palette), /* K10 */ be_nested_str_weak(get), - /* K11 */ be_nested_str_weak(animate_obj), - /* K12 */ be_nested_str_weak(animate_mth), + /* K11 */ be_nested_str_weak(obj), + /* K12 */ be_nested_str_weak(mth), }), be_str_weak(set_value), &be_const_str_solidified, @@ -819,44 +988,79 @@ be_local_closure(Animate_palette_set_value, /* name */ /******************************************************************** -** Solidified function: start +** Solidified function: to_css_gradient ********************************************************************/ -be_local_closure(Animate_palette_start, /* name */ +be_local_closure(Animate_palette_to_css_gradient, /* name */ be_nested_proto( - 4, /* nstack */ - 2, /* argc */ - 2, /* varg */ + 17, /* nstack */ + 1, /* argc */ + 4, /* 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_str_weak(duration_ms), - /* K1 */ be_nested_str_weak(tasmota), - /* K2 */ be_nested_str_weak(millis), - /* K3 */ be_nested_str_weak(origin), - /* K4 */ be_nested_str_weak(running), + ( &(const bvalue[10]) { /* constants */ + /* K0 */ be_const_class(be_class_Animate_palette), + /* K1 */ be_nested_str_weak(parse_palette), + /* K2 */ be_const_int(0), + /* K3 */ be_nested_str_weak(background_X3Alinear_X2Dgradient_X28to_X20right), + /* K4 */ be_nested_str_weak(palette), + /* K5 */ be_nested_str_weak(get), + /* K6 */ be_nested_str_weak(_X2C_X23_X2502X_X2502X_X2502X_X20_X25_X2E1f_X25_X25), + /* K7 */ be_const_real_hex(0x41200000), + /* K8 */ be_const_int(1), + /* K9 */ be_nested_str_weak(_X29_X3B), }), - be_str_weak(start), + be_str_weak(to_css_gradient), &be_const_str_solidified, - ( &(const binstruction[16]) { /* code */ - 0x88080100, // 0000 GETMBR R2 R0 K0 - 0x4C0C0000, // 0001 LDNIL R3 - 0x1C080403, // 0002 EQ R2 R2 R3 - 0x780A0000, // 0003 JMPF R2 #0005 - 0x80000400, // 0004 RET 0 - 0x4C080000, // 0005 LDNIL R2 - 0x1C080202, // 0006 EQ R2 R1 R2 - 0x780A0003, // 0007 JMPF R2 #000C - 0xB80A0200, // 0008 GETNGBL R2 K1 - 0x8C080502, // 0009 GETMET R2 R2 K2 - 0x7C080200, // 000A CALL R2 1 - 0x5C040400, // 000B MOVE R1 R2 - 0x90020601, // 000C SETMBR R0 K3 R1 - 0x50080200, // 000D LDBOOL R2 1 0 - 0x90020802, // 000E SETMBR R0 K4 R2 - 0x80000000, // 000F RET 0 + ( &(const binstruction[46]) { /* code */ + 0x58040000, // 0000 LDCONST R1 K0 + 0x5C080200, // 0001 MOVE R2 R1 + 0x5C0C0000, // 0002 MOVE R3 R0 + 0x7C080200, // 0003 CALL R2 1 + 0x8C0C0501, // 0004 GETMET R3 R2 K1 + 0x58140002, // 0005 LDCONST R5 K2 + 0x541A03E7, // 0006 LDINT R6 1000 + 0x7C0C0600, // 0007 CALL R3 3 + 0x58100003, // 0008 LDCONST R4 K3 + 0x58140002, // 0009 LDCONST R5 K2 + 0x6018000C, // 000A GETGBL R6 G12 + 0x5C1C0600, // 000B MOVE R7 R3 + 0x7C180200, // 000C CALL R6 1 + 0x14180A06, // 000D LT R6 R5 R6 + 0x781A001C, // 000E JMPF R6 #002C + 0x94180605, // 000F GETIDX R6 R3 R5 + 0x881C0504, // 0010 GETMBR R7 R2 K4 + 0x8C1C0F05, // 0011 GETMET R7 R7 K5 + 0x54260003, // 0012 LDINT R9 4 + 0x08240A09, // 0013 MUL R9 R5 R9 + 0x542A0003, // 0014 LDINT R10 4 + 0x7C1C0600, // 0015 CALL R7 3 + 0x54220007, // 0016 LDINT R8 8 + 0x3C200E08, // 0017 SHR R8 R7 R8 + 0x542600FE, // 0018 LDINT R9 255 + 0x2C201009, // 0019 AND R8 R8 R9 + 0x5426000F, // 001A LDINT R9 16 + 0x3C240E09, // 001B SHR R9 R7 R9 + 0x542A00FE, // 001C LDINT R10 255 + 0x2C24120A, // 001D AND R9 R9 R10 + 0x542A0017, // 001E LDINT R10 24 + 0x3C280E0A, // 001F SHR R10 R7 R10 + 0x542E00FE, // 0020 LDINT R11 255 + 0x2C28140B, // 0021 AND R10 R10 R11 + 0x602C0018, // 0022 GETGBL R11 G24 + 0x58300006, // 0023 LDCONST R12 K6 + 0x5C341000, // 0024 MOVE R13 R8 + 0x5C381200, // 0025 MOVE R14 R9 + 0x5C3C1400, // 0026 MOVE R15 R10 + 0x0C400D07, // 0027 DIV R16 R6 K7 + 0x7C2C0A00, // 0028 CALL R11 5 + 0x0010080B, // 0029 ADD R4 R4 R11 + 0x00140B08, // 002A ADD R5 R5 K8 + 0x7001FFDD, // 002B JMP #000A + 0x00100909, // 002C ADD R4 R4 K9 + 0x80040800, // 002D RET 1 R4 }) ) ); @@ -866,95 +1070,62 @@ be_local_closure(Animate_palette_start, /* name */ /******************************************************************** ** Solidified class: Animate_palette ********************************************************************/ +extern const bclass be_class_Animate_animator; be_local_class(Animate_palette, - 12, - NULL, - be_nested_map(24, + 7, + &be_class_Animate_animator, + be_nested_map(16, ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(start, -1), be_const_closure(Animate_palette_start_closure) }, - { be_const_key_weak(to_css_gradient, -1), be_const_closure(Animate_palette_to_css_gradient_closure) }, - { be_const_key_weak(range_min, -1), be_const_var(6) }, - { be_const_key_weak(init, -1), be_const_closure(Animate_palette_init_closure) }, - { be_const_key_weak(set_value, -1), be_const_closure(Animate_palette_set_value_closure) }, - { be_const_key_weak(stop, -1), be_const_closure(Animate_palette_stop_closure) }, - { be_const_key_weak(slots, 15), be_const_var(2) }, - { be_const_key_weak(origin, -1), be_const_var(5) }, - { be_const_key_weak(animate, 19), be_const_closure(Animate_palette_animate_closure) }, - { be_const_key_weak(set_range, 2), be_const_closure(Animate_palette_set_range_closure) }, + { be_const_key_weak(palette, 5), be_const_var(0) }, + { be_const_key_weak(range_min, -1), be_const_var(3) }, { be_const_key_weak(slots_arr, -1), be_const_var(1) }, + { be_const_key_weak(init, -1), be_const_closure(Animate_palette_init_closure) }, + { be_const_key_weak(bri, 14), be_const_var(5) }, + { be_const_key_weak(animate, -1), be_const_closure(Animate_palette_animate_closure) }, + { be_const_key_weak(slots, -1), be_const_var(2) }, + { be_const_key_weak(ptr_to_palette, -1), be_const_static_closure(Animate_palette_ptr_to_palette_closure) }, + { be_const_key_weak(color, -1), be_const_var(6) }, + { be_const_key_weak(set_range, 10), be_const_closure(Animate_palette_set_range_closure) }, + { be_const_key_weak(to_css_gradient, -1), be_const_static_closure(Animate_palette_to_css_gradient_closure) }, { be_const_key_weak(set_bri, -1), be_const_closure(Animate_palette_set_bri_closure) }, - { be_const_key_weak(bri, 17), be_const_var(10) }, - { be_const_key_weak(is_running, -1), be_const_closure(Animate_palette_is_running_closure) }, - { be_const_key_weak(animate_mth, -1), be_const_var(9) }, - { be_const_key_weak(duration_ms, -1), be_const_var(4) }, - { be_const_key_weak(color, -1), be_const_var(11) }, - { be_const_key_weak(set_duration, 22), be_const_closure(Animate_palette_set_duration_closure) }, - { be_const_key_weak(animate_obj, -1), be_const_var(8) }, - { be_const_key_weak(palette, -1), be_const_var(0) }, - { be_const_key_weak(parse_palette, 14), be_const_closure(Animate_palette_parse_palette_closure) }, - { be_const_key_weak(set_cb, 4), be_const_closure(Animate_palette_set_cb_closure) }, - { be_const_key_weak(running, -1), be_const_var(3) }, - { be_const_key_weak(range_max, 0), be_const_var(7) }, + { be_const_key_weak(set_duration, -1), be_const_closure(Animate_palette_set_duration_closure) }, + { be_const_key_weak(set_value, -1), be_const_closure(Animate_palette_set_value_closure) }, + { be_const_key_weak(parse_palette, -1), be_const_closure(Animate_palette_parse_palette_closure) }, + { be_const_key_weak(range_max, -1), be_const_var(4) }, })), be_str_weak(Animate_palette) ); +/*******************************************************************/ -extern const bclass be_class_Animate_rotate; +void be_load_Animate_palette_class(bvm *vm) { + be_pushntvclass(vm, &be_class_Animate_palette); + be_setglobal(vm, "Animate_palette"); + be_pop(vm, 1); +} + +extern const bclass be_class_Animate_oscillator; /******************************************************************** -** Solidified function: init +** Solidified function: set_b ********************************************************************/ -be_local_closure(Animate_rotate_init, /* name */ +be_local_closure(Animate_oscillator_set_b, /* name */ be_nested_proto( - 13, /* nstack */ - 6, /* argc */ + 2, /* nstack */ + 2, /* argc */ 2, /* 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_str_weak(init), - /* K1 */ be_nested_str_weak(set_cb), - /* K2 */ be_nested_str_weak(code), - /* K3 */ be_nested_str_weak(push), - /* K4 */ be_nested_str_weak(animate), - /* K5 */ be_nested_str_weak(ins_ramp), - /* K6 */ be_nested_str_weak(ins_goto), - /* K7 */ be_const_int(0), + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_str_weak(b), }), - be_str_weak(init), + be_str_weak(set_b), &be_const_str_solidified, - ( &(const binstruction[28]) { /* code */ - 0x60180003, // 0000 GETGBL R6 G3 - 0x5C1C0000, // 0001 MOVE R7 R0 - 0x7C180200, // 0002 CALL R6 1 - 0x8C180D00, // 0003 GETMET R6 R6 K0 - 0x7C180200, // 0004 CALL R6 1 - 0x8C180101, // 0005 GETMET R6 R0 K1 - 0x5C200200, // 0006 MOVE R8 R1 - 0x5C240400, // 0007 MOVE R9 R2 - 0x7C180600, // 0008 CALL R6 3 - 0x88180102, // 0009 GETMBR R6 R0 K2 - 0x8C180D03, // 000A GETMET R6 R6 K3 - 0xB8220800, // 000B GETNGBL R8 K4 - 0x8C201105, // 000C GETMET R8 R8 K5 - 0x5C280600, // 000D MOVE R10 R3 - 0x5C2C0800, // 000E MOVE R11 R4 - 0x5C300A00, // 000F MOVE R12 R5 - 0x7C200800, // 0010 CALL R8 4 - 0x7C180400, // 0011 CALL R6 2 - 0x88180102, // 0012 GETMBR R6 R0 K2 - 0x8C180D03, // 0013 GETMET R6 R6 K3 - 0xB8220800, // 0014 GETNGBL R8 K4 - 0x8C201106, // 0015 GETMET R8 R8 K6 - 0x58280007, // 0016 LDCONST R10 K7 - 0x582C0007, // 0017 LDCONST R11 K7 - 0x58300007, // 0018 LDCONST R12 K7 - 0x7C200800, // 0019 CALL R8 4 - 0x7C180400, // 001A CALL R6 2 - 0x80000000, // 001B RET 0 + ( &(const binstruction[ 2]) { /* code */ + 0x90020001, // 0000 SETMBR R0 K0 R1 + 0x80000000, // 0001 RET 0 }) ) ); @@ -962,125 +1133,84 @@ be_local_closure(Animate_rotate_init, /* name */ /******************************************************************** -** Solidified class: Animate_rotate +** Solidified function: set_a ********************************************************************/ -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_const_key_weak(init, -1), be_const_closure(Animate_rotate_init_closure) }, - })), - be_str_weak(Animate_rotate) -); - -extern const bclass be_class_Animate_ins_goto; - -/******************************************************************** -** Solidified function: init -********************************************************************/ -be_local_closure(Animate_ins_goto_init, /* name */ +be_local_closure(Animate_oscillator_set_a, /* name */ be_nested_proto( - 4, /* nstack */ - 4, /* argc */ + 2, /* nstack */ + 2, /* argc */ 2, /* 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_str_weak(pc_rel), - /* K1 */ be_nested_str_weak(pc_abs), - /* K2 */ be_nested_str_weak(duration), + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_str_weak(a), }), - be_str_weak(init), + be_str_weak(set_a), &be_const_str_solidified, - ( &(const binstruction[ 4]) { /* code */ + ( &(const binstruction[ 2]) { /* code */ 0x90020001, // 0000 SETMBR R0 K0 R1 - 0x90020202, // 0001 SETMBR R0 K1 R2 - 0x90020403, // 0002 SETMBR R0 K2 R3 - 0x80000000, // 0003 RET 0 + 0x80000000, // 0001 RET 0 }) ) ); /*******************************************************************/ -/******************************************************************** -** Solidified class: Animate_ins_goto -********************************************************************/ -be_local_class(Animate_ins_goto, - 3, - NULL, - be_nested_map(4, - ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(pc_rel, -1), be_const_var(0) }, - { be_const_key_weak(duration, -1), be_const_var(2) }, - { be_const_key_weak(init, -1), be_const_closure(Animate_ins_goto_init_closure) }, - { be_const_key_weak(pc_abs, 2), be_const_var(1) }, - })), - be_str_weak(Animate_ins_goto) -); - -extern const bclass be_class_Animate_ins_ramp; - /******************************************************************** ** Solidified function: init ********************************************************************/ -be_local_closure(Animate_ins_ramp_init, /* name */ +be_local_closure(Animate_oscillator_init, /* name */ be_nested_proto( - 4, /* nstack */ - 4, /* argc */ + 6, /* nstack */ + 5, /* argc */ 2, /* 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_str_weak(a), - /* K1 */ be_nested_str_weak(b), - /* K2 */ be_nested_str_weak(duration), + ( &(const bvalue[ 9]) { /* constants */ + /* K0 */ be_nested_str_weak(phase), + /* K1 */ be_const_int(0), + /* K2 */ be_nested_str_weak(duty_cycle), + /* K3 */ be_nested_str_weak(a), + /* K4 */ be_nested_str_weak(b), + /* K5 */ be_nested_str_weak(duration_ms), + /* K6 */ be_nested_str_weak(value), + /* K7 */ be_const_int(1), + /* K8 */ be_nested_str_weak(form), }), be_str_weak(init), &be_const_str_solidified, - ( &(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 + ( &(const binstruction[13]) { /* code */ + 0x90020101, // 0000 SETMBR R0 K0 K1 + 0x54160031, // 0001 LDINT R5 50 + 0x90020405, // 0002 SETMBR R0 K2 R5 + 0x90020601, // 0003 SETMBR R0 K3 R1 + 0x90020802, // 0004 SETMBR R0 K4 R2 + 0x90020A03, // 0005 SETMBR R0 K5 R3 + 0x90020C01, // 0006 SETMBR R0 K6 R1 + 0x4C140000, // 0007 LDNIL R5 + 0x1C140805, // 0008 EQ R5 R4 R5 + 0x78160000, // 0009 JMPF R5 #000B + 0x58100007, // 000A LDCONST R4 K7 + 0x90021004, // 000B SETMBR R0 K8 R4 + 0x80000000, // 000C RET 0 }) ) ); /*******************************************************************/ -/******************************************************************** -** Solidified class: Animate_ins_ramp -********************************************************************/ -be_local_class(Animate_ins_ramp, - 3, - NULL, - be_nested_map(4, - ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(a, -1), be_const_var(0) }, - { be_const_key_weak(b, 2), be_const_var(1) }, - { be_const_key_weak(duration, -1), be_const_var(2) }, - { be_const_key_weak(init, -1), be_const_closure(Animate_ins_ramp_init_closure) }, - })), - be_str_weak(Animate_ins_ramp) -); - -extern const bclass be_class_Animate_engine; - /******************************************************************** ** Solidified function: animate ********************************************************************/ -be_local_closure(Animate_engine_animate, /* name */ +be_local_closure(Animate_oscillator_animate, /* name */ be_nested_proto( - 14, /* nstack */ + 18, /* nstack */ 2, /* argc */ 2, /* varg */ 0, /* has upvals */ @@ -1088,240 +1218,182 @@ be_local_closure(Animate_engine_animate, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[24]) { /* constants */ - /* K0 */ be_nested_str_weak(running), + ( &(const bvalue[21]) { /* constants */ + /* K0 */ be_nested_str_weak(duration_ms), /* K1 */ be_nested_str_weak(tasmota), /* K2 */ be_nested_str_weak(millis), - /* K3 */ be_nested_str_weak(ins_time), - /* K4 */ be_nested_str_weak(pc), - /* K5 */ be_nested_str_weak(code), - /* K6 */ be_const_int(0), - /* K7 */ be_nested_str_weak(internal_error), - /* K8 */ be_nested_str_weak(Animate_X20pc_X20is_X20out_X20of_X20range), - /* K9 */ be_nested_str_weak(animate), - /* K10 */ be_nested_str_weak(ins_ramp), - /* K11 */ be_nested_str_weak(closure), - /* K12 */ be_nested_str_weak(animate_obj), - /* K13 */ be_nested_str_weak(animate_mth), - /* K14 */ be_nested_str_weak(duration), - /* K15 */ be_nested_str_weak(value), - /* K16 */ be_nested_str_weak(scale_uint), - /* K17 */ be_nested_str_weak(a), - /* K18 */ be_nested_str_weak(b), - /* K19 */ be_const_int(1), - /* K20 */ be_nested_str_weak(ins_goto), - /* K21 */ be_nested_str_weak(pc_rel), - /* K22 */ be_nested_str_weak(pc_abs), - /* K23 */ be_nested_str_weak(unknown_X20instruction), + /* K3 */ be_nested_str_weak(origin), + /* K4 */ be_const_int(0), + /* K5 */ be_nested_str_weak(originally), + /* K6 */ be_nested_str_weak(scale_uint), + /* K7 */ be_nested_str_weak(duty_cycle), + /* K8 */ be_nested_str_weak(beat), + /* K9 */ be_nested_str_weak(a), + /* K10 */ be_nested_str_weak(b), + /* K11 */ be_nested_str_weak(value), + /* K12 */ be_nested_str_weak(phase), + /* K13 */ be_nested_str_weak(form), + /* K14 */ be_const_int(1), + /* K15 */ be_nested_str_weak(scale_int), + /* K16 */ be_const_int(2), + /* K17 */ be_const_int(3), + /* K18 */ be_nested_str_weak(sine_int), + /* K19 */ be_nested_str_weak(obj), + /* K20 */ be_nested_str_weak(mth), }), be_str_weak(animate), &be_const_str_solidified, - ( &(const binstruction[113]) { /* code */ + ( &(const binstruction[150]) { /* 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 - 0x780A0062, // 000B JMPF R2 #006F + 0x4C0C0000, // 0001 LDNIL R3 + 0x1C080403, // 0002 EQ R2 R2 R3 + 0x780A0000, // 0003 JMPF R2 #0005 + 0x80000400, // 0004 RET 0 + 0x4C080000, // 0005 LDNIL R2 + 0x1C080202, // 0006 EQ R2 R1 R2 + 0x780A0003, // 0007 JMPF R2 #000C + 0xB80A0200, // 0008 GETNGBL R2 K1 + 0x8C080502, // 0009 GETMET R2 R2 K2 + 0x7C080200, // 000A CALL R2 1 + 0x5C040400, // 000B MOVE R1 R2 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 - 0x70020057, // 0016 JMP #006F - 0x880C0104, // 0017 GETMBR R3 R0 K4 - 0x140C0706, // 0018 LT R3 R3 K6 - 0x780E0000, // 0019 JMPF R3 #001B - 0xB0060F08, // 001A RAISE 1 K7 K8 - 0x880C0105, // 001B GETMBR R3 R0 K5 - 0x88100104, // 001C GETMBR R4 R0 K4 - 0x940C0604, // 001D GETIDX R3 R3 R4 - 0x6010000F, // 001E GETGBL R4 G15 - 0x5C140600, // 001F MOVE R5 R3 - 0xB81A1200, // 0020 GETNGBL R6 K9 - 0x88180D0A, // 0021 GETMBR R6 R6 K10 - 0x7C100400, // 0022 CALL R4 2 - 0x7812002E, // 0023 JMPF R4 #0053 - 0x8810010B, // 0024 GETMBR R4 R0 K11 - 0x8814010C, // 0025 GETMBR R5 R0 K12 - 0x8818010D, // 0026 GETMBR R6 R0 K13 - 0x881C070E, // 0027 GETMBR R7 R3 K14 - 0x141C0407, // 0028 LT R7 R2 R7 - 0x781E0014, // 0029 JMPF R7 #003F - 0xB81E0200, // 002A GETNGBL R7 K1 - 0x8C1C0F10, // 002B GETMET R7 R7 K16 - 0x5C240400, // 002C MOVE R9 R2 - 0x58280006, // 002D LDCONST R10 K6 - 0x882C070E, // 002E GETMBR R11 R3 K14 - 0x88300711, // 002F GETMBR R12 R3 K17 - 0x88340712, // 0030 GETMBR R13 R3 K18 - 0x7C1C0C00, // 0031 CALL R7 6 - 0x90021E07, // 0032 SETMBR R0 K15 R7 - 0x78160004, // 0033 JMPF R5 #0039 - 0x781A0003, // 0034 JMPF R6 #0039 - 0x5C1C0C00, // 0035 MOVE R7 R6 - 0x5C200A00, // 0036 MOVE R8 R5 - 0x8824010F, // 0037 GETMBR R9 R0 K15 - 0x7C1C0400, // 0038 CALL R7 2 - 0x78120002, // 0039 JMPF R4 #003D - 0x5C1C0800, // 003A MOVE R7 R4 - 0x8820010F, // 003B GETMBR R8 R0 K15 - 0x7C1C0200, // 003C CALL R7 1 - 0x70020030, // 003D JMP #006F - 0x70020012, // 003E JMP #0052 - 0x881C0712, // 003F GETMBR R7 R3 K18 - 0x90021E07, // 0040 SETMBR R0 K15 R7 - 0x78160004, // 0041 JMPF R5 #0047 - 0x781A0003, // 0042 JMPF R6 #0047 - 0x5C1C0C00, // 0043 MOVE R7 R6 - 0x5C200A00, // 0044 MOVE R8 R5 - 0x8824010F, // 0045 GETMBR R9 R0 K15 - 0x7C1C0400, // 0046 CALL R7 2 - 0x78120002, // 0047 JMPF R4 #004B - 0x5C1C0800, // 0048 MOVE R7 R4 - 0x8820010F, // 0049 GETMBR R8 R0 K15 - 0x7C1C0200, // 004A CALL R7 1 - 0x881C0104, // 004B GETMBR R7 R0 K4 - 0x001C0F13, // 004C ADD R7 R7 K19 - 0x90020807, // 004D SETMBR R0 K4 R7 - 0x881C070E, // 004E GETMBR R7 R3 K14 - 0x041C0407, // 004F SUB R7 R2 R7 - 0x041C0207, // 0050 SUB R7 R1 R7 - 0x90020607, // 0051 SETMBR R0 K3 R7 - 0x7002001A, // 0052 JMP #006E - 0x6010000F, // 0053 GETGBL R4 G15 - 0x5C140600, // 0054 MOVE R5 R3 - 0xB81A1200, // 0055 GETNGBL R6 K9 - 0x88180D14, // 0056 GETMBR R6 R6 K20 - 0x7C100400, // 0057 CALL R4 2 - 0x78120013, // 0058 JMPF R4 #006D - 0x8810070E, // 0059 GETMBR R4 R3 K14 - 0x14100404, // 005A LT R4 R2 R4 - 0x78120001, // 005B JMPF R4 #005E - 0x70020011, // 005C JMP #006F - 0x7002000D, // 005D JMP #006C - 0x88100715, // 005E GETMBR R4 R3 K21 - 0x20100906, // 005F NE R4 R4 K6 - 0x78120004, // 0060 JMPF R4 #0066 - 0x88100104, // 0061 GETMBR R4 R0 K4 - 0x88140715, // 0062 GETMBR R5 R3 K21 - 0x00100805, // 0063 ADD R4 R4 R5 - 0x90020804, // 0064 SETMBR R0 K4 R4 - 0x70020001, // 0065 JMP #0068 - 0x88100716, // 0066 GETMBR R4 R3 K22 - 0x90020804, // 0067 SETMBR R0 K4 R4 - 0x8810070E, // 0068 GETMBR R4 R3 K14 - 0x04100404, // 0069 SUB R4 R2 R4 - 0x04100204, // 006A SUB R4 R1 R4 - 0x90020604, // 006B SETMBR R0 K3 R4 - 0x70020000, // 006C JMP #006E - 0xB0060F17, // 006D RAISE 1 K7 K23 - 0x7001FF9A, // 006E JMP #000A - 0x8808010F, // 006F GETMBR R2 R0 K15 - 0x80040400, // 0070 RET 1 R2 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: init -********************************************************************/ -be_local_closure(Animate_engine_init, /* name */ - be_nested_proto( - 2, /* nstack */ - 1, /* argc */ - 2, /* 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_str_weak(code), - /* K1 */ be_nested_str_weak(pc), - /* K2 */ be_const_int(0), - /* K3 */ be_nested_str_weak(ins_time), - /* K4 */ be_nested_str_weak(running), - }), - be_str_weak(init), - &be_const_str_solidified, - ( &(const binstruction[ 8]) { /* code */ - 0x60040012, // 0000 GETGBL R1 G18 - 0x7C040000, // 0001 CALL R1 0 - 0x90020001, // 0002 SETMBR R0 K0 R1 - 0x90020302, // 0003 SETMBR R0 K1 K2 - 0x90020702, // 0004 SETMBR R0 K3 K2 - 0x50040000, // 0005 LDBOOL R1 0 0 - 0x90020801, // 0006 SETMBR R0 K4 R1 - 0x80000000, // 0007 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: stop -********************************************************************/ -be_local_closure(Animate_engine_stop, /* name */ - be_nested_proto( - 2, /* nstack */ - 1, /* argc */ - 2, /* 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_str_weak(running), - }), - be_str_weak(stop), - &be_const_str_solidified, - ( &(const binstruction[ 3]) { /* code */ - 0x50040000, // 0000 LDBOOL R1 0 0 - 0x90020001, // 0001 SETMBR R0 K0 R1 - 0x80000000, // 0002 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: is_running -********************************************************************/ -be_local_closure(Animate_engine_is_running, /* name */ - be_nested_proto( - 2, /* nstack */ - 1, /* argc */ - 2, /* 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_str_weak(running), - }), - be_str_weak(is_running), - &be_const_str_solidified, - ( &(const binstruction[ 2]) { /* code */ - 0x88040100, // 0000 GETMBR R1 R0 K0 - 0x80040200, // 0001 RET 1 R1 + 0x140C0504, // 000E LT R3 R2 K4 + 0x780E0001, // 000F JMPF R3 #0012 + 0x58080004, // 0010 LDCONST R2 K4 + 0x88040105, // 0011 GETMBR R1 R0 K5 + 0x880C0100, // 0012 GETMBR R3 R0 K0 + 0x4C100000, // 0013 LDNIL R4 + 0xB8160200, // 0014 GETNGBL R5 K1 + 0x8C140B06, // 0015 GETMET R5 R5 K6 + 0x881C0107, // 0016 GETMBR R7 R0 K7 + 0x58200004, // 0017 LDCONST R8 K4 + 0x54260063, // 0018 LDINT R9 100 + 0x58280004, // 0019 LDCONST R10 K4 + 0x5C2C0600, // 001A MOVE R11 R3 + 0x7C140C00, // 001B CALL R5 6 + 0x5C100A00, // 001C MOVE R4 R5 + 0x28140403, // 001D GE R5 R2 R3 + 0x78160007, // 001E JMPF R5 #0027 + 0x0C180403, // 001F DIV R6 R2 R3 + 0x08180C03, // 0020 MUL R6 R6 R3 + 0x88140103, // 0021 GETMBR R5 R0 K3 + 0x00140A06, // 0022 ADD R5 R5 R6 + 0x90020605, // 0023 SETMBR R0 K3 R5 + 0x10080403, // 0024 MOD R2 R2 R3 + 0x8C140108, // 0025 GETMET R5 R0 K8 + 0x7C140200, // 0026 CALL R5 1 + 0x88140109, // 0027 GETMBR R5 R0 K9 + 0x8818010A, // 0028 GETMBR R6 R0 K10 + 0x881C010B, // 0029 GETMBR R7 R0 K11 + 0x5C200400, // 002A MOVE R8 R2 + 0x8824010C, // 002B GETMBR R9 R0 K12 + 0x24241304, // 002C GT R9 R9 K4 + 0x7826000B, // 002D JMPF R9 #003A + 0xB8260200, // 002E GETNGBL R9 K1 + 0x8C241306, // 002F GETMET R9 R9 K6 + 0x882C010C, // 0030 GETMBR R11 R0 K12 + 0x58300004, // 0031 LDCONST R12 K4 + 0x54360063, // 0032 LDINT R13 100 + 0x58380004, // 0033 LDCONST R14 K4 + 0x5C3C0600, // 0034 MOVE R15 R3 + 0x7C240C00, // 0035 CALL R9 6 + 0x00201009, // 0036 ADD R8 R8 R9 + 0x24241003, // 0037 GT R9 R8 R3 + 0x78260000, // 0038 JMPF R9 #003A + 0x04201003, // 0039 SUB R8 R8 R3 + 0x8824010D, // 003A GETMBR R9 R0 K13 + 0x1C24130E, // 003B EQ R9 R9 K14 + 0x78260009, // 003C JMPF R9 #0047 + 0xB8260200, // 003D GETNGBL R9 K1 + 0x8C24130F, // 003E GETMET R9 R9 K15 + 0x5C2C1000, // 003F MOVE R11 R8 + 0x58300004, // 0040 LDCONST R12 K4 + 0x0434070E, // 0041 SUB R13 R3 K14 + 0x5C380A00, // 0042 MOVE R14 R5 + 0x5C3C0C00, // 0043 MOVE R15 R6 + 0x7C240C00, // 0044 CALL R9 6 + 0x5C1C1200, // 0045 MOVE R7 R9 + 0x70020044, // 0046 JMP #008C + 0x8824010D, // 0047 GETMBR R9 R0 K13 + 0x1C241310, // 0048 EQ R9 R9 K16 + 0x78260015, // 0049 JMPF R9 #0060 + 0x14241004, // 004A LT R9 R8 R4 + 0x78260009, // 004B JMPF R9 #0056 + 0xB8260200, // 004C GETNGBL R9 K1 + 0x8C24130F, // 004D GETMET R9 R9 K15 + 0x5C2C1000, // 004E MOVE R11 R8 + 0x58300004, // 004F LDCONST R12 K4 + 0x0434090E, // 0050 SUB R13 R4 K14 + 0x5C380A00, // 0051 MOVE R14 R5 + 0x5C3C0C00, // 0052 MOVE R15 R6 + 0x7C240C00, // 0053 CALL R9 6 + 0x5C1C1200, // 0054 MOVE R7 R9 + 0x70020008, // 0055 JMP #005F + 0xB8260200, // 0056 GETNGBL R9 K1 + 0x8C24130F, // 0057 GETMET R9 R9 K15 + 0x5C2C1000, // 0058 MOVE R11 R8 + 0x5C300800, // 0059 MOVE R12 R4 + 0x0434070E, // 005A SUB R13 R3 K14 + 0x5C380C00, // 005B MOVE R14 R6 + 0x5C3C0A00, // 005C MOVE R15 R5 + 0x7C240C00, // 005D CALL R9 6 + 0x5C1C1200, // 005E MOVE R7 R9 + 0x7002002B, // 005F JMP #008C + 0x8824010D, // 0060 GETMBR R9 R0 K13 + 0x1C241311, // 0061 EQ R9 R9 K17 + 0x78260005, // 0062 JMPF R9 #0069 + 0x14241004, // 0063 LT R9 R8 R4 + 0x78260001, // 0064 JMPF R9 #0067 + 0x5C1C0A00, // 0065 MOVE R7 R5 + 0x70020000, // 0066 JMP #0068 + 0x5C1C0C00, // 0067 MOVE R7 R6 + 0x70020022, // 0068 JMP #008C + 0x8824010D, // 0069 GETMBR R9 R0 K13 + 0x542A0003, // 006A LDINT R10 4 + 0x1C24120A, // 006B EQ R9 R9 R10 + 0x74260003, // 006C JMPT R9 #0071 + 0x8824010D, // 006D GETMBR R9 R0 K13 + 0x542A0004, // 006E LDINT R10 5 + 0x1C24120A, // 006F EQ R9 R9 R10 + 0x7826001A, // 0070 JMPF R9 #008C + 0xB8260200, // 0071 GETNGBL R9 K1 + 0x8C24130F, // 0072 GETMET R9 R9 K15 + 0x5C2C1000, // 0073 MOVE R11 R8 + 0x58300004, // 0074 LDCONST R12 K4 + 0x0434070E, // 0075 SUB R13 R3 K14 + 0x58380004, // 0076 LDCONST R14 K4 + 0x543E7FFE, // 0077 LDINT R15 32767 + 0x7C240C00, // 0078 CALL R9 6 + 0x8828010D, // 0079 GETMBR R10 R0 K13 + 0x542E0003, // 007A LDINT R11 4 + 0x1C28140B, // 007B EQ R10 R10 R11 + 0x782A0001, // 007C JMPF R10 #007F + 0x542A1FFF, // 007D LDINT R10 8192 + 0x0424120A, // 007E SUB R9 R9 R10 + 0xB82A0200, // 007F GETNGBL R10 K1 + 0x8C281512, // 0080 GETMET R10 R10 K18 + 0x5C301200, // 0081 MOVE R12 R9 + 0x7C280400, // 0082 CALL R10 2 + 0xB82E0200, // 0083 GETNGBL R11 K1 + 0x8C2C170F, // 0084 GETMET R11 R11 K15 + 0x5C341400, // 0085 MOVE R13 R10 + 0x5439EFFF, // 0086 LDINT R14 -4096 + 0x543E0FFF, // 0087 LDINT R15 4096 + 0x5C400A00, // 0088 MOVE R16 R5 + 0x5C440C00, // 0089 MOVE R17 R6 + 0x7C2C0C00, // 008A CALL R11 6 + 0x5C1C1600, // 008B MOVE R7 R11 + 0x90021607, // 008C SETMBR R0 K11 R7 + 0x88240113, // 008D GETMBR R9 R0 K19 + 0x88280114, // 008E GETMBR R10 R0 K20 + 0x78260004, // 008F JMPF R9 #0095 + 0x782A0003, // 0090 JMPF R10 #0095 + 0x5C2C1400, // 0091 MOVE R11 R10 + 0x5C301200, // 0092 MOVE R12 R9 + 0x5C340E00, // 0093 MOVE R13 R7 + 0x7C2C0400, // 0094 CALL R11 2 + 0x80040E00, // 0095 RET 1 R7 }) ) ); @@ -1329,12 +1401,12 @@ be_local_closure(Animate_engine_is_running, /* name */ /******************************************************************** -** Solidified function: set_cb +** Solidified function: set_duty_cycle ********************************************************************/ -be_local_closure(Animate_engine_set_cb, /* name */ +be_local_closure(Animate_oscillator_set_duty_cycle, /* name */ be_nested_proto( 3, /* nstack */ - 3, /* argc */ + 2, /* argc */ 2, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ @@ -1342,59 +1414,21 @@ be_local_closure(Animate_engine_set_cb, /* name */ NULL, /* no sub protos */ 1, /* has constants */ ( &(const bvalue[ 2]) { /* constants */ - /* K0 */ be_nested_str_weak(animate_obj), - /* K1 */ be_nested_str_weak(animate_mth), - }), - be_str_weak(set_cb), - &be_const_str_solidified, - ( &(const binstruction[ 3]) { /* code */ - 0x90020001, // 0000 SETMBR R0 K0 R1 - 0x90020202, // 0001 SETMBR R0 K1 R2 - 0x80000000, // 0002 RET 0 - }) - ) -); -/*******************************************************************/ - - -/******************************************************************** -** Solidified function: start -********************************************************************/ -be_local_closure(Animate_engine_start, /* name */ - be_nested_proto( - 5, /* nstack */ - 3, /* argc */ - 2, /* 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_str_weak(tasmota), - /* K1 */ be_nested_str_weak(millis), - /* K2 */ be_nested_str_weak(value), - /* K3 */ be_nested_str_weak(ins_time), - /* K4 */ be_nested_str_weak(running), + /* K0 */ be_const_int(0), + /* K1 */ be_nested_str_weak(duty_cycle), }), - be_str_weak(start), + be_str_weak(set_duty_cycle), &be_const_str_solidified, - ( &(const binstruction[15]) { /* code */ - 0x4C0C0000, // 0000 LDNIL R3 - 0x1C0C0203, // 0001 EQ R3 R1 R3 - 0x780E0003, // 0002 JMPF R3 #0007 - 0xB80E0000, // 0003 GETNGBL R3 K0 - 0x8C0C0701, // 0004 GETMET R3 R3 K1 - 0x7C0C0200, // 0005 CALL R3 1 - 0x5C040600, // 0006 MOVE R1 R3 - 0x4C0C0000, // 0007 LDNIL R3 - 0x200C0403, // 0008 NE R3 R2 R3 - 0x780E0000, // 0009 JMPF R3 #000B - 0x90020402, // 000A SETMBR R0 K2 R2 - 0x90020601, // 000B SETMBR R0 K3 R1 - 0x500C0200, // 000C LDBOOL R3 1 0 - 0x90020803, // 000D SETMBR R0 K4 R3 - 0x80000000, // 000E RET 0 + ( &(const binstruction[ 9]) { /* code */ + 0x14080300, // 0000 LT R2 R1 K0 + 0x780A0000, // 0001 JMPF R2 #0003 + 0x58040000, // 0002 LDCONST R1 K0 + 0x540A0063, // 0003 LDINT R2 100 + 0x24080202, // 0004 GT R2 R1 R2 + 0x780A0000, // 0005 JMPF R2 #0007 + 0x54060063, // 0006 LDINT R1 100 + 0x90020201, // 0007 SETMBR R0 K1 R1 + 0x80000000, // 0008 RET 0 }) ) ); @@ -1402,96 +1436,34 @@ be_local_closure(Animate_engine_start, /* name */ /******************************************************************** -** Solidified class: Animate_engine +** Solidified function: set_phase ********************************************************************/ -be_local_class(Animate_engine, - 8, - NULL, - be_nested_map(14, - ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(animate, -1), be_const_closure(Animate_engine_animate_closure) }, - { be_const_key_weak(ins_time, -1), be_const_var(5) }, - { be_const_key_weak(running, 10), be_const_var(6) }, - { be_const_key_weak(stop, 7), be_const_closure(Animate_engine_stop_closure) }, - { be_const_key_weak(closure, -1), be_const_var(1) }, - { be_const_key_weak(init, 1), be_const_closure(Animate_engine_init_closure) }, - { be_const_key_weak(animate_mth, -1), be_const_var(3) }, - { be_const_key_weak(set_cb, -1), be_const_closure(Animate_engine_set_cb_closure) }, - { be_const_key_weak(code, -1), be_const_var(0) }, - { be_const_key_weak(is_running, -1), be_const_closure(Animate_engine_is_running_closure) }, - { be_const_key_weak(animate_obj, 11), be_const_var(2) }, - { be_const_key_weak(pc, -1), be_const_var(4) }, - { be_const_key_weak(value, 6), be_const_var(7) }, - { be_const_key_weak(start, -1), be_const_closure(Animate_engine_start_closure) }, - })), - be_str_weak(Animate_engine) -); - -extern const bclass be_class_Animate_back_forth; - -/******************************************************************** -** Solidified function: init -********************************************************************/ -be_local_closure(Animate_back_forth_init, /* name */ +be_local_closure(Animate_oscillator_set_phase, /* name */ be_nested_proto( - 13, /* nstack */ - 6, /* argc */ + 3, /* nstack */ + 2, /* argc */ 2, /* 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_str_weak(init), - /* K1 */ be_nested_str_weak(set_cb), - /* K2 */ be_nested_str_weak(code), - /* K3 */ be_nested_str_weak(push), - /* K4 */ be_nested_str_weak(animate), - /* K5 */ be_nested_str_weak(ins_ramp), - /* K6 */ be_nested_str_weak(ins_goto), - /* K7 */ be_const_int(0), + ( &(const bvalue[ 2]) { /* constants */ + /* K0 */ be_const_int(0), + /* K1 */ be_nested_str_weak(phase), }), - be_str_weak(init), + be_str_weak(set_phase), &be_const_str_solidified, - ( &(const binstruction[37]) { /* code */ - 0x60180003, // 0000 GETGBL R6 G3 - 0x5C1C0000, // 0001 MOVE R7 R0 - 0x7C180200, // 0002 CALL R6 1 - 0x8C180D00, // 0003 GETMET R6 R6 K0 - 0x7C180200, // 0004 CALL R6 1 - 0x8C180101, // 0005 GETMET R6 R0 K1 - 0x5C200200, // 0006 MOVE R8 R1 - 0x5C240400, // 0007 MOVE R9 R2 - 0x7C180600, // 0008 CALL R6 3 - 0x88180102, // 0009 GETMBR R6 R0 K2 - 0x8C180D03, // 000A GETMET R6 R6 K3 - 0xB8220800, // 000B GETNGBL R8 K4 - 0x8C201105, // 000C GETMET R8 R8 K5 - 0x5C280600, // 000D MOVE R10 R3 - 0x5C2C0800, // 000E MOVE R11 R4 - 0x5C300A00, // 000F MOVE R12 R5 - 0x7C200800, // 0010 CALL R8 4 - 0x7C180400, // 0011 CALL R6 2 - 0x88180102, // 0012 GETMBR R6 R0 K2 - 0x8C180D03, // 0013 GETMET R6 R6 K3 - 0xB8220800, // 0014 GETNGBL R8 K4 - 0x8C201105, // 0015 GETMET R8 R8 K5 - 0x5C280800, // 0016 MOVE R10 R4 - 0x5C2C0600, // 0017 MOVE R11 R3 - 0x5C300A00, // 0018 MOVE R12 R5 - 0x7C200800, // 0019 CALL R8 4 - 0x7C180400, // 001A CALL R6 2 - 0x88180102, // 001B GETMBR R6 R0 K2 - 0x8C180D03, // 001C GETMET R6 R6 K3 - 0xB8220800, // 001D GETNGBL R8 K4 - 0x8C201106, // 001E GETMET R8 R8 K6 - 0x58280007, // 001F LDCONST R10 K7 - 0x582C0007, // 0020 LDCONST R11 K7 - 0x58300007, // 0021 LDCONST R12 K7 - 0x7C200800, // 0022 CALL R8 4 - 0x7C180400, // 0023 CALL R6 2 - 0x80000000, // 0024 RET 0 + ( &(const binstruction[ 9]) { /* code */ + 0x14080300, // 0000 LT R2 R1 K0 + 0x780A0000, // 0001 JMPF R2 #0003 + 0x58040000, // 0002 LDCONST R1 K0 + 0x540A0063, // 0003 LDINT R2 100 + 0x24080202, // 0004 GT R2 R1 R2 + 0x780A0000, // 0005 JMPF R2 #0007 + 0x54060063, // 0006 LDINT R1 100 + 0x90020201, // 0007 SETMBR R0 K1 R1 + 0x80000000, // 0008 RET 0 }) ) ); @@ -1499,101 +1471,35 @@ be_local_closure(Animate_back_forth_init, /* name */ /******************************************************************** -** Solidified class: Animate_back_forth +** Solidified class: Animate_oscillator ********************************************************************/ -extern const bclass be_class_Animate_engine; -be_local_class(Animate_back_forth, - 0, - &be_class_Animate_engine, - be_nested_map(1, +extern const bclass be_class_Animate_animator; +be_local_class(Animate_oscillator, + 6, + &be_class_Animate_animator, + be_nested_map(12, ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(init, -1), be_const_closure(Animate_back_forth_init_closure) }, + { be_const_key_weak(phase, -1), be_const_var(0) }, + { be_const_key_weak(b, -1), be_const_var(3) }, + { be_const_key_weak(set_b, -1), be_const_closure(Animate_oscillator_set_b_closure) }, + { be_const_key_weak(set_a, 10), be_const_closure(Animate_oscillator_set_a_closure) }, + { be_const_key_weak(a, -1), be_const_var(2) }, + { be_const_key_weak(set_phase, -1), be_const_closure(Animate_oscillator_set_phase_closure) }, + { be_const_key_weak(value, -1), be_const_var(5) }, + { be_const_key_weak(duty_cycle, -1), be_const_var(1) }, + { be_const_key_weak(animate, 7), be_const_closure(Animate_oscillator_animate_closure) }, + { be_const_key_weak(set_duty_cycle, -1), be_const_closure(Animate_oscillator_set_duty_cycle_closure) }, + { be_const_key_weak(init, -1), be_const_closure(Animate_oscillator_init_closure) }, + { be_const_key_weak(form, 5), be_const_var(4) }, })), - be_str_weak(Animate_back_forth) -); - -extern const bclass be_class_Animate_from_to; - -/******************************************************************** -** Solidified function: init -********************************************************************/ -be_local_closure(Animate_from_to_init, /* name */ - be_nested_proto( - 13, /* nstack */ - 6, /* argc */ - 2, /* 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_str_weak(init), - /* K1 */ be_nested_str_weak(set_cb), - /* K2 */ be_nested_str_weak(code), - /* K3 */ be_nested_str_weak(push), - /* K4 */ be_nested_str_weak(animate), - /* K5 */ be_nested_str_weak(ins_ramp), - }), - be_str_weak(init), - &be_const_str_solidified, - ( &(const binstruction[19]) { /* code */ - 0x60180003, // 0000 GETGBL R6 G3 - 0x5C1C0000, // 0001 MOVE R7 R0 - 0x7C180200, // 0002 CALL R6 1 - 0x8C180D00, // 0003 GETMET R6 R6 K0 - 0x7C180200, // 0004 CALL R6 1 - 0x8C180101, // 0005 GETMET R6 R0 K1 - 0x5C200200, // 0006 MOVE R8 R1 - 0x5C240400, // 0007 MOVE R9 R2 - 0x7C180600, // 0008 CALL R6 3 - 0x88180102, // 0009 GETMBR R6 R0 K2 - 0x8C180D03, // 000A GETMET R6 R6 K3 - 0xB8220800, // 000B GETNGBL R8 K4 - 0x8C201105, // 000C GETMET R8 R8 K5 - 0x5C280600, // 000D MOVE R10 R3 - 0x5C2C0800, // 000E MOVE R11 R4 - 0x5C300A00, // 000F MOVE R12 R5 - 0x7C200800, // 0010 CALL R8 4 - 0x7C180400, // 0011 CALL R6 2 - 0x80000000, // 0012 RET 0 - }) - ) + be_str_weak(Animate_oscillator) ); /*******************************************************************/ - -/******************************************************************** -** 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_const_key_weak(init, -1), be_const_closure(Animate_from_to_init_closure) }, - })), - be_str_weak(Animate_from_to) -); - -/******************************************************************** -** Solidified module: animate -********************************************************************/ -be_local_module(animate, - "animate", - be_nested_map(7, - ( (struct bmapnode*) &(const bmapnode[]) { - { be_const_key_weak(ins_ramp, -1), be_const_class(be_class_Animate_ins_ramp) }, - { be_const_key_weak(from_to, -1), be_const_class(be_class_Animate_from_to) }, - { be_const_key_weak(palette, 3), be_const_class(be_class_Animate_palette) }, - { be_const_key_weak(engine, 5), be_const_class(be_class_Animate_engine) }, - { be_const_key_weak(back_forth, -1), be_const_class(be_class_Animate_back_forth) }, - { be_const_key_weak(rotate, -1), be_const_class(be_class_Animate_rotate) }, - { be_const_key_weak(ins_goto, -1), be_const_class(be_class_Animate_ins_goto) }, - })) -); -BE_EXPORT_VARIABLE be_define_const_native_module(animate); -/********************************************************************/ +void be_load_Animate_oscillator_class(bvm *vm) { + be_pushntvclass(vm, &be_class_Animate_oscillator); + be_setglobal(vm, "Animate_oscillator"); + be_pop(vm, 1); +} /********************************************************************/ /* End of solidification */ diff --git a/tasmota/berry/animate_demo/animate_demo_palette_background.be b/tasmota/berry/animate_demo/animate_demo_palette_background.be new file mode 100644 index 000000000000..03648b419de1 --- /dev/null +++ b/tasmota/berry/animate_demo/animate_demo_palette_background.be @@ -0,0 +1,11 @@ +# +# Example for M5Stack Led Matrix +# 5 x 5 WS2812 +# +import animate + +var duration = 10000 +var strip = Leds(5 * 5, gpio.pin(gpio.WS2812, 0)) +var anim = animate(strip) +anim.add_background_animator(animate.palette(animate.PALETTE_RAINBOW_WHITE, duration)) +anim.start() diff --git a/tasmota/berry/animate_demo/animate_demo_pulse.be b/tasmota/berry/animate_demo/animate_demo_pulse.be new file mode 100644 index 000000000000..0a2b6dd40d1e --- /dev/null +++ b/tasmota/berry/animate_demo/animate_demo_pulse.be @@ -0,0 +1,23 @@ +# +# Example for M5Stack Led Matrix +# 5 x 5 WS2812 +# +import animate + +var duration = 10000 +var strip = Leds(5 * 5, gpio.pin(gpio.WS2812, 0)) +var anim = animate(strip) +anim.set_back_color(0x2222AA) +var pulse = animate.pulse(0xFF4444, 2, 1) +var osc1 = animate.oscillator(-3, 26, 5000, animate.COSINE) +osc1.set_cb(pulse, pulse.set_pos) + +anim.add_animator(osc1) +anim.add_painter(pulse) + +# animate color of pulse +var palette = animate.palette(animate.PALETTE_RAINBOW_WHITE, 30000) +palette.set_cb(pulse, pulse.set_color) +anim.add_animator(palette) + +anim.start() diff --git a/tasmota/berry/animate_demo/leds_animation.be b/tasmota/berry/animate_demo/leds_animation.be new file mode 100644 index 000000000000..96f4d47ea827 --- /dev/null +++ b/tasmota/berry/animate_demo/leds_animation.be @@ -0,0 +1,173 @@ +################################################################################# +# Web UI for Leds animation +# +################################################################################# + +var leds_animation = module('leds_animation') + +################################################################################# +# Leds_animation_UI +# +# WebUI for the Leds animation +################################################################################# +class Leds_animation_UI + + def init() + tasmota.add_driver(self) + end + + # create a method for adding a button to the main menu + # the button 'Leds animation' redirects to '/leds_anim?' + def web_add_button() + import webserver + webserver.content_send( + "

") + end + + #- ---------------------------------------------------------------------- -# + #- Show page to migrate to factory layout + single OTA + #- ---------------------------------------------------------------------- -# + def show_migrate_to_factory(p) + # display ota partitions + import webserver + import string + + if !self.factory_migrate_eligible(p) return end + + webserver.content_send("
 Migrate to safeboot partition layout 

") + + webserver.content_send("

The `safeboot` layout allows for increased size
of firmware or file-system.

") + webserver.content_send("

Please see Safeboot layout documentation

") + webserver.content_send("

 

") + + webserver.content_send(string.format("

Step 1: %s

", self.display_step_state(self.test_step_1(p), "boot on `app1`"))) + webserver.content_send(string.format("

Step 2: %s

", self.display_step_state(self.test_step_2(p), "flash `safeboot` to `app0`"))) + webserver.content_send(string.format("

Step 3: %s

", self.display_step_state(self.test_step_3(p), "change partition map"))) + webserver.content_send(string.format("

Step 4: %s

", self.display_step_state(self.test_step_4(p), "flash final firmware"))) + + webserver.content_send("
") + var ota_url = tasmota.cmd("OtaUrl").find("OtaUrl", "") + webserver.content_send(string.format("
OTA Url

", + ota_url)) + + import persist + var safeboot_url = persist.find("safeboot_url", self.default_safeboot_URL()) + webserver.content_send(string.format("
SAFEBOOT Url (don't change)
", + safeboot_url)) + + webserver.content_send("

") + + webserver.content_send("

") + end + + ####################################################################### + # Show background colors + ####################################################################### + def show_background_color() + import webserver + var back_color = 0xFF8800 + var back_anim_time = 5.0 + + + webserver.content_send("
 Background  " + "
") + + # webserver.content_send(f"") + # webserver.content_send("
") + webserver.content_send("") + webserver.content_send(f"") + webserver.content_send("

") + + webserver.content_send("") + webserver.content_send("") + webserver.content_send(f"" + "" + "" + "") + webserver.content_send("" + "" + "" + "") + webserver.content_send("" + "" + "" + "") + webserver.content_send("" + "" + "" + "") + webserver.content_send("
Static
Palette1
Palette1
Palette1
") + webserver.content_send("

" + "

") + end + + ####################################################################### + # Show main config + ####################################################################### + def show_main_config() + import webserver + var leds_anim_enabled = true + var leds_size = 25 + + webserver.content_send("
 Leds configuration  " + "

Check the Leds animation documentation.

" + "
") + + # checkbox for Matter enable + var leds_anim_enabled_checked = leds_anim_enabled ? 'checked' : '' + webserver.content_send(f"

") + webserver.content_send("

") + + webserver.content_send("") + webserver.content_send(f"") + + webserver.content_send("

" + "

") + end + + ####################################################################### + # Display the complete page + ####################################################################### + def page_view() + import webserver + if !webserver.check_privileged_access() return nil end + + webserver.content_start("Leds animation") #- title of the web page -# + webserver.content_send_style() #- send standard Tasmota styles -# + + self.show_main_config() + self.show_background_color() + webserver.content_button(webserver.BUTTON_MANAGEMENT) #- button back to management page -# + + webserver.content_stop() #- end of web page -# + end + + #- ---------------------------------------------------------------------- -# + # respond to web_add_handler() event to register web listeners + #- ---------------------------------------------------------------------- -# + #- this is called at Tasmota start-up, as soon as Wifi/Eth is up and web server running -# + def web_add_handler() + import webserver + #- we need to register a closure, not just a function, that captures the current instance -# + webserver.on("/leds_anim", / -> self.page_view(), webserver.HTTP_GET) + webserver.on("/leds_anim", / -> self.page_ctl(), webserver.HTTP_POST) + end +end +leds_animation.Leds_animation_UI = Leds_animation_UI + + +#- create and register driver in Tasmota -# +if tasmota + var ui = leds_animation.Leds_animation_UI() + ## can be removed if put in 'autoexec.bat' + ui.web_add_handler() +end + +return leds_animation + +#- Example + +import leds_animation + +-# diff --git a/tasmota/berry/animate_demo/leds_blend_demo.be b/tasmota/berry/animate_demo/leds_blend_demo.be new file mode 100644 index 000000000000..88596e27614d --- /dev/null +++ b/tasmota/berry/animate_demo/leds_blend_demo.be @@ -0,0 +1,37 @@ +# test blending + +import animate + +var LEDS_LENGTH = 25 +var strip +var front, back +var bri + +strip = Leds(LEDS_LENGTH, gpio.pin(gpio.WS2812,0)) +bri = 70 + +back = bytes().resize(LEDS_LENGTH * 4) +front = bytes().resize(LEDS_LENGTH * 4) +strip.clear_to(0x442211) +strip.show() + +var back = animate.frame(LEDS_LENGTH) +var front = animate.frame(LEDS_LENGTH) +back.fill_pixels(0xFF2200, 80) +for i:0..24 + front.set_pixel(i, 0, 255, 0, (i*255)/24) +end +back.blend_pixels(back, front) + +print("front=", front.tohex()) +print("back =", back.tohex()) +var pixels_buffer = strip.pixels_buffer() +print("pixs =", pixels_buffer.tohex()) +back.paste_pixels(pixels_buffer, bri, true) +strip.dirty() +strip.show() + +## Output: +# front= 00FF000000FF000A00FF001500FF001F00FF002A00FF003500FF003F00FF004A00FF005500FF005F00FF006A00FF007400FF007F00FF008A00FF009400FF009F00FF00AA00FF00B400FF00BF00FF00C900FF00D400FF00DF00FF00E900FF00F400FF00FF +# back = 0022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF000022FF00 +# pixs = 020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701020701 diff --git a/tasmota/berry/emulator/Leds_frame.be b/tasmota/berry/emulator/Leds_frame.be new file mode 100644 index 000000000000..eb3f520eeba9 --- /dev/null +++ b/tasmota/berry/emulator/Leds_frame.be @@ -0,0 +1,42 @@ +# Leds_frame + +class Leds_frame + var pixel_size + + def init() + end + + def blend(color_a, color_b, alpha) + var r = (color_a >> 16) & 0xFF + var g = (color_a >> 8) & 0xFF + var b = (color_a ) & 0xFF + var r2 = (color_b >> 16) & 0xFF + var g2 = (color_b >> 8) & 0xFF + var b2 = (color_b ) & 0xFF + var r3 = tasmota.scale_uint(alpha, 0, 255, r2, r) + var g3 = tasmota.scale_uint(alpha, 0, 255, g2, g) + var b3 = tasmota.scale_uint(alpha, 0, 255, b2, b) + var rgb = (r3 << 16) | (g3 << 8) | b3 + return rgb + end + +end + +return Leds_frame + +# /* @const_object_info_begin +# class be_class_Leds_frame (scope: global, name: Leds_frame, super:be_class_bytes, strings: weak) { +# pixel_size, var + +# init, closure(Leds_frame_be_init_closure) + +# item, closure(Leds_frame_be_item_closure) +# setitem, closure(Leds_frame_be_setitem_closure) +# set_pixel, closure(Leds_frame_be_set_pixel_closure) + +# // the following are on buffers +# blend, static_func(be_leds_blend) +# fill_pixels, func(be_leds_fill_pixels) +# blend_pixels, func(be_leds_blend_pixels) +# paste_pixels, func(be_leds_paste_pixels) +# } \ No newline at end of file diff --git a/tasmota/berry/leds/leds_animate_demo_palette_background.be b/tasmota/berry/leds/leds_animate_demo_palette_background.be deleted file mode 100644 index 1e1681000529..000000000000 --- a/tasmota/berry/leds/leds_animate_demo_palette_background.be +++ /dev/null @@ -1,51 +0,0 @@ -# -# Example for M5Stack Led Matrix -# 5 x 5 WS2812 -# -import animate -class Background_demo : Leds_animator - static var PALETTE_STANDARD_TAG = bytes( - "40" "FF0000" # red - "40" "FFA500" # orange - "40" "FFFF00" # yellow - "40" "00EE00" # green - "40" "0000FF" # blue - "40" "4B00FF" # indigo - "40" "FF82FF" # violet - "00" "FF0000" # red - ) - - static var PALETTE_RAINBOW_WHITE = bytes( - "50" "FF0000" # red - "30" "FF0000" # red - "50" "FFA500" # orange - "30" "FFA500" # orange - "50" "FFFF00" # yellow - "30" "FFFF00" # yellow - "50" "00FF00" # green - "30" "00FF00" # green - "50" "0000FF" # blue - "30" "0000FF" # blue - "50" "FF00FF" # indigo - "30" "FF00FF" # indigo - "50" "FFFFFF" # white - "30" "FFFFFF" # white - "00" "FF0000" # red - ) - - # duration in seconds - def init(strip, duration) - import animate - super(self).init(strip) - # var pal = animate.palette(self.PALETTE_STANDARD_TAG, duration) - var pal = animate.palette(self.PALETTE_RAINBOW_WHITE, duration) - self.add_background_animator(pal) - end - - def animate() - end -end - -var strip = Leds(5 * 5, gpio.pin(gpio.WS2812, 0)) -var r = Background_demo(strip, 20) -r.start() diff --git a/tasmota/berry/leds/rainbow.be b/tasmota/berry/leds/rainbow.be deleted file mode 100644 index d29720c93f3c..000000000000 --- a/tasmota/berry/leds/rainbow.be +++ /dev/null @@ -1,185 +0,0 @@ -# simple Rainbow animator - -#- -# Ex: if WS2812 configured to WS2812 - channel 2 - -var strip = neopixelbus(25, gpio.pin(gpio.WS2812, 1)) -rainbow = Rainbow(strip) -rainbow.start() - --# - -import animate - -class Rainbow : Leds_animator - var cur_offset # current offset in the palette - static palette = [ 0xFF0000, #- red -# - 0xFFA500, #- orange -# - 0xFFFF00, #- yellow -# - 0x008800, #- green -# - 0x0000FF, #- blue -# - 0x4B0082, #- indigo -# - 0xEE82EE, #- violet -# - ] - - def init(strip, duration) - import animate - 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() - # move instance variables to registers to avoid GETMBR inside the loop - var cur_offset = self.cur_offset - var modulus = size(self.palette) - var palette = self.palette - var strip = self.strip - 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() - end - -end - -#- - -var strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1)) -var r = Rainbow(strip, 1.0) -r.start() - --# - -class Rainbow_stripes : Leds_animator - var cur_offset # current offset in the palette - static palette = [ 0xFF0000, #- red -# - 0xFFA500, #- orange -# - 0xFFFF00, #- yellow -# - 0x008800, #- green -# - 0x0000FF, #- blue -# - 0x4B0082, #- indigo -# - 0xEE82EE, #- violet -# - ] - - def init(strip, duration) - import animate - 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() - # move instance variables to registers to avoid GETMBR inside the loop - var cur_offset = self.cur_offset - var modulus = size(self.palette) - var palette = self.palette - var strip = self.strip - var bri = self.bri - var set_matrix_pixel_color = strip.set_matrix_pixel_color - var h = self.strip.h - var w = self.strip.w - - var y = 0 - while y < h - var x = 0 - var col = palette[(cur_offset + y) % modulus] - while x < w - set_matrix_pixel_color(strip, x, y, col, bri) # simulate the method call without GETMET - x += 1 - end - y += 1 - end - strip.show() - end - -end - -#- - -var strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1)) -var r = Rainbow_stripes(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, glow_duration, color_duration) - import animate - super(self).init(strip) - self.cur_val = 5 << 8 - 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() - # move instance variables to registers to avoid GETMBR inside the loop - var strip = self.strip - var bri = self.bri - var set_matrix_pixel_color = strip.set_matrix_pixel_color - var h = self.strip.h - 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 = col_ref - var dist = self.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 - x += 1 - end - y += 1 - end - strip.show() - end - - # https://stackoverflow.com/questions/34187171/fast-integer-square-root-approximation - static def fast_sqrt_int(val) - var a, b - - if val < 2 return val end - - a = 1255 # starting point is relatively unimportant - - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - if (val < 20000) - b = val / a; a = (a+b) /2; - b = val / a; a = (a+b) /2; - end - - return a - end -end - -#- - -var strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1)) -var r = Round(strip, 2, 30) -r.start() - --# diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino index 320023b346db..c4df2e318b9b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_tasmota.ino @@ -427,6 +427,61 @@ extern "C" { be_raise(vm, kTypeError, nullptr); } + /* + Implements the 5-order polynomial approximation to sin(x). + @param i angle (with 2^15 units/circle) + @return 16 bit fixed point Sine value (4.12) (ie: +4096 = +1 & -4096 = -1) + + The result is accurate to within +- 1 count. ie: +/-2.44e-4. + */ + int16_t fpsin(int16_t i) + { + /* Convert (signed) input to a value between 0 and 8192. (8192 is pi/2, which is the region of the curve fit). */ + /* ------------------------------------------------------------------- */ + i <<= 1; + uint8_t c = i<0; //set carry for output pos/neg + + if(i == (i|0x4000)) // flip input value to corresponding value in range [0..8192) + i = (1<<15) - i; + i = (i & 0x7FFF) >> 1; + /* ------------------------------------------------------------------- */ + + /* The following section implements the formula: + = y * 2^-n * ( A1 - 2^(q-p)* y * 2^-n * y * 2^-n * [B1 - 2^-r * y * 2^-n * C1 * y]) * 2^(a-q) + Where the constants are defined as follows: + */ + // enum {A1=3370945099UL, B1=2746362156UL, C1=292421UL}; + // enum {n=13, p=32, q=31, r=3, a=12}; + + uint32_t y = (292421UL*((uint32_t)i))>>13; + y = 2746362156UL - (((uint32_t)i*y)>>3); + y = (uint32_t)i * (y>>13); + y = (uint32_t)i * (y>>13); + y = 3370945099UL - (y>>(32-31)); + y = (uint32_t)i * (y>>13); + y = (y+(1UL<<(31-12-1)))>>(31-12); // Rounding + + return c ? -y : y; + } + + // Berry: tasmota.sine_int(int) -> int + // + // Input: 8192 is pi/2 + // Output: -4096 is -1, 4096 is +1 + // + // https://www.nullhardware.com/blog/fixed-point-sine-and-cosine-for-embedded-systems/ + int32_t l_sineint(struct bvm *vm); + int32_t l_sineint(struct bvm *vm) { + int32_t top = be_top(vm); // Get the number of arguments + if (top == 1 && be_isint(vm, 1)) { + int32_t val = be_toint(vm, 1); + + be_pushint(vm, fpsin(val)); + be_return(vm); + } + be_raise(vm, kTypeError, nullptr); + } + int32_t l_respCmnd(bvm *vm); int32_t l_respCmnd(bvm *vm) { int32_t top = be_top(vm); // Get the number of arguments