Leds animation refactoring stage 1 (#20197)

This commit is contained in:
s-hadinger 2023-12-08 21:13:44 +01:00 committed by GitHub
parent 73268e4bb6
commit d61adb0b0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 4942 additions and 2251 deletions

View File

@ -529,7 +529,9 @@ public:
// ESP_LOGI(TAG, "Enable RMT TX channel");
ret += rmt_enable(_channel.RmtChannelNumber);
AddLog(2,"RMT:initialized with error code: %u on pin: %u",ret, _pin);
// if (ret) {
// AddLog(2,"RMT: initialized with error code: %u on pin: %u",ret, _pin);
// }
}
void Update(bool maintainBufferConsistency)

View File

@ -328,8 +328,9 @@ public:
_spi_strip->bytes_per_pixel = bytes_per_pixel;
_spi_strip->strip_len = _pixelCount;
AddLog(2,"SPI:initialized with error code: %u on pin: %u",ret, _pin);
// if (ret) {
// AddLog(2,"SPI: initialized with error code: %u on pin: %u",ret, _pin);
// }
return;
err:
if (_spi_strip) {
@ -341,7 +342,9 @@ public:
}
free(_spi_strip);
}
AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin);
// if (ret) {
// AddLog(2,"SPI-Error:initialized with error code: %u on pin: %u",ret, _pin);
// }
return;
}

View File

@ -206,8 +206,10 @@ 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);
@ -276,7 +278,9 @@ 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),

View File

@ -0,0 +1,39 @@
/********************************************************************
* Berry class `neopixelbus_ntv`
*
*******************************************************************/
#include "be_constobj.h"
#ifdef USE_WS2812
extern int be_leds_blend(bvm *vm);
extern int be_leds_blend_pixels(bvm *vm);
extern int be_leds_fill_pixels(bvm *vm);
extern int be_leds_paste_pixels(bvm *vm);
BE_EXPORT_VARIABLE extern const bclass be_class_bytes;
#include "solidify/solidified_leds_frame_be_methods.h"
/* @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)
}
@const_object_info_end */
#include "be_fixed_be_class_Leds_frame.h"
#endif // USE_WS2812

View File

@ -1,50 +1,31 @@
/********************************************************************
* Berry class `neopixelbus_ntv`
* Berry class `Leds_ntv`
*
*******************************************************************/
/*
class Leds_ntv
var _p # pointer to internal object of type `NeoPixelBus<FEATURE, METHOD>(uint16_t countPixels, uint8_t pin)`
var _t # type of led strip
static WS2812_GRB = 1
static SK6812_GRBW = 2
# skeleton for native call
def call_native() end
end
*/
#include "be_constobj.h"
#ifdef USE_WS2812
extern int be_neopixelbus_call_native(bvm *vm);
extern int be_leds_blend_color(bvm *vm);
extern int be_leds_apply_bri_gamma(bvm *vm);
/* @const_object_info_begin
class be_class_Leds_ntv (scope: global, name: Leds_ntv, strings: weak) {
_p, var
_t, var
/********************************************************************
** Solidified class: Leds_ntv
********************************************************************/
be_local_class(Leds_ntv,
2,
NULL,
be_nested_map(5,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key(call_native, -1), be_const_func(be_neopixelbus_call_native) },
{ be_const_key(_t, -1), be_const_var(1) },
{ be_const_key(_p, 3), be_const_var(0) },
{ be_const_key(SK6812_GRBW, 4), be_const_int(2) },
{ be_const_key(WS2812_GRB, -1), be_const_int(1) },
})),
be_str_weak(Leds_ntv)
);
/*******************************************************************/
WS2812_GRB, int(1)
SK6812_GRBW, int(2)
void be_load_Leds_ntv_class(bvm *vm) {
be_pushntvclass(vm, &be_class_Leds_ntv);
be_setglobal(vm, "Leds_ntv");
be_pop(vm, 1);
call_native, func(be_neopixelbus_call_native)
blend_color, static_func(be_leds_blend_color)
apply_bri_gamma, static_func(be_leds_apply_bri_gamma)
}
@const_object_info_end */
#include "be_fixed_be_class_Leds_ntv.h"
// be_const_func(be_neopixelbus_call_native)
#endif // USE_WS2812

View File

@ -0,0 +1,9 @@
/********************************************************************
* Berry class `Leds_pulse`
*
*******************************************************************/
#ifdef USE_WS2812
#include "solidify/solidified_leds_animate_effects.h"
#endif // USE_WS2812

View File

@ -4,6 +4,7 @@
# Animation framework
#
#@ solidify:animate,weak
animate = module("animate")
# state-machine: from val a to b
@ -20,6 +21,381 @@ class Animate_ins_ramp
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
@ -37,6 +413,8 @@ 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
@ -50,37 +428,35 @@ class Animate_engine
#
end
# run but needs external calls to `animate()`
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 run(cur_time, val)
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
tasmota.add_driver(self)
end
# runs autonomously in the Tasmota event loop
def autorun(cur_time, val)
self.run(cur_time, val)
tasmota.add_driver(self)
end
# # runs autonomously in the Tasmota event loop
# def autorun(cur_time, val)
# self.run(cur_time, val)
# end
def stop()
self.running = false
tasmota.remove_driver(self)
end
def is_running()
return self.running
end
def every_50ms()
self.animate()
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
@ -99,16 +475,23 @@ class Animate_engine
# Instruction Ramp
if isinstance(ins, animate.ins_ramp)
var f = self.closure # assign to a local variable to not call a method
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 f f(self.value) end # call closure, need try? TODO
if (closure) closure(self.value) end # call closure, need try? TODO
break
else
self.value = ins.b
if f f(self.value) end # set to last value
# 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
@ -139,25 +522,26 @@ animate.engine = Animate_engine
class Animate_from_to : Animate_engine
def init(closure, from, to, duration)
def init(obj, mth, from, to, duration)
super(self).init()
self.closure = closure
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)
a.autorun()
-#
###
#
# a=Animate_from_to(nil, 0, 100, 5000)
#
###
class Animate_rotate : Animate_engine
def init(closure, from, to, duration)
def init(obj, mth, from, to, duration)
super(self).init()
self.closure = closure
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
@ -172,17 +556,16 @@ a.autorun()
class Animate_back_forth : Animate_engine
def init(closure, from, to, duration)
def init(obj, mth, from, to, duration)
super(self).init()
self.closure = closure
self.code.push(animate.ins_ramp(from, to, duration / 2))
self.code.push(animate.ins_ramp(to, from, duration / 2))
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
#@ solidify:animate
#-
a=Animate_back_forth(nil, 0, 100, 5000)

View File

@ -132,6 +132,9 @@ class Leds : Leds_ntv
def pixel_count()
return self.call_native(8)
end
def pixel_offset()
return 0
end
def clear_to(col, bri)
self.call_native(9, self.to_gamma(col, bri))
end
@ -155,20 +158,8 @@ class Leds : Leds_ntv
# end
# apply gamma and bri
def to_gamma(rgbw, bri)
bri = (bri != nil) ? bri : 100
var r = tasmota.scale_uint(bri, 0, 100, 0, (rgbw & 0xFF0000) >> 16)
var g = tasmota.scale_uint(bri, 0, 100, 0, (rgbw & 0x00FF00) >> 8)
var b = tasmota.scale_uint(bri, 0, 100, 0, (rgbw & 0x0000FF))
if self.gamma
return light.gamma8(r) << 16 |
light.gamma8(g) << 8 |
light.gamma8(b)
else
return r << 16 |
g << 8 |
b
end
def to_gamma(rgb, bri)
return self.apply_bri_gamma(rgb, bri, self.gamma)
end
# `segment`
@ -218,15 +209,19 @@ class Leds : Leds_ntv
def pixel_size()
return self.strip.pixel_size()
end
def pixel_offset()
return self.offset
end
def pixel_count()
return self.leds
end
def clear_to(col, bri)
var i = 0
while i < self.leds
self.strip.set_pixel_color(i + self.offset, col, bri)
i += 1
end
self.strip.call_native(9, self.strip.to_gamma(col, bri), self.offset, self.leds)
# var i = 0
# while i < self.leds
# self.strip.set_pixel_color(i + self.offset, col, bri)
# i += 1
# end
end
def set_pixel_color(idx, col, bri)
self.strip.set_pixel_color(idx + self.offset, col, bri)
@ -302,12 +297,11 @@ class Leds : Leds_ntv
def pixel_count()
return self.w * self.h
end
def clear_to(col, bri)
var i = 0
while i < self.w * self.h
self.strip.set_pixel_color(i + self.offset, col, bri)
i += 1
def pixel_offset()
return self.offset
end
def clear_to(col, bri)
self.strip.call_native(9, self.strip.to_gamma(col, bri), self.offset, self.w * self.h)
end
def set_pixel_color(idx, col, bri)
self.strip.set_pixel_color(idx + self.offset, col, bri)

View File

@ -0,0 +1,162 @@
# class Leds_pulse
#@ solidify:Leds_pulse,weak
##########################################################################################
#
# class Leds_pulse
#
# Display a color pulse
#
# index (1)
# |
# v
# _______
# / \
# _______/ \____________
# | | | |
# |2| 3 |2|
#
# 1: `index`, 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
var color
var back_color
var index
var slew_size
var pulse_size
def init(color, pulse_size, slew_size)
if (color == nil) color = 0xFFFFFF end # white by default
if (pulse_size == nil) pulse_size = 1 end
if (slew_size == nil) slew_size = 0 end
self.color = color
self.back_color = 0xFF000000 # default to transparent
if pulse_size < 0 pulse_size = 0 end
self.pulse_size = pulse_size
if slew_size < 0 slew_size = 0 end
self.slew_size = slew_size
end
##
## Setters - to be used as cb for animators
##
def set_color(color)
self.color = color
end
def set_back_color(c)
self.back_color = c
end
def set_index(index)
self.index = index
end
def set_slew_size(slew_size)
self.slew_size = slew_size
end
def set_pulse_size(pulse_size)
self.pulse_size = pulse_size
end
# return true if buffer was filled successfully
def paint(frame)
var back_color = self.back_color
if (back_color != 0xFF000000)
frame.fill_pixels(back_color) # fill with transparent color
end
var index = self.index
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 pulse_min, pulse_max
pulse_min = index
pulse_max = index + pulse_size
if (pulse_min < 0) pulse_min = 0 end
if (pulse_max >= pixel_size) pulse_max = pixel_size end
var i = pulse_min
while (i < pulse_max)
frame[i] = color
i += 1
end
if (slew_size > 0)
# check first slew, from `min_index` to `index - 1`
# Slew 1
pulse_min = index - slew_size
pulse_max = index
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))
# blend
i += 1
end
# Slew 2
pulse_min = index + pulse_size
pulse_max = index + 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))
i += 1
end
end
return true
end
end
#
# Unit tests
#
if false
var frame = Leds_frame(10)
assert(frame.tohex() == '00000000000000000000000000000000000000000000000000000000000000000000000000000000')
var pulse = Leds_pulse(0x00FF00, 3, 2)
pulse.set_index(5)
pulse.paint(frame)
assert(frame.tohex() == '0000000000000000000000000055000000AA000000FF000000FF000000FF000000AA000000550000')
pulse.set_back_color(0x111111)
pulse.set_slew_size(1)
pulse.paint(frame)
assert(frame.tohex() == '111111001111110011111100111111000988090000FF000000FF000000FF00000988090011111100')
pulse.set_back_color(0x00000000)
pulse.paint(frame)
assert(frame.tohex() == '00000000000000000000000000000000007F000000FF000000FF000000FF0000007F000000000000')
pulse.set_pulse_size(0)
pulse.paint(frame)
assert(frame.tohex() == '00000000000000000000000000000000007F0000007F000000000000000000000000000000000000')
pulse.set_slew_size(3)
pulse.paint(frame)
assert(frame.tohex() == '000000000000000000400000007F000000BF000000BF0000007F0000004000000000000000000000')
pulse.set_slew_size(0)
pulse.paint(frame)
assert(frame.tohex() == '00000000000000000000000000000000000000000000000000000000000000000000000000000000')
end

View File

@ -1,29 +1,72 @@
# class Leds_animator
#@ solidify:Leds_animator,weak
# for solidification
class Leds_frame end
##########################################################################################
#
# class Leds_animator
#
# Simple framework to orchestrate all the animations for a led strip or led matrix
#
# You should pass a Leds or Leds_segment to push pixels at each tick
# This version uses `fast_loop` for up to 5ms animation time (200 Hz)
#
##########################################################################################
class Leds_animator
var strip # neopixelbus object
var pixel_count # number of pixels in the strip
var bri # brightness of the animation, 0..100, default 50
var running # is the animation running
var animators # animators list
var painters # list of objects that paint layers on top of background (with transparency)
var fast_loop_cb # closure used for fast_loop
static var FAST_LOOP_MIN = 20
var fast_loop_next # next time-stamp for fast_loop
# cb for animation
var animate_object # object called at each tick
var animate_method # method of object called at each tick
# frame ojects
var frame # Leds_frame frame object
var layer # Leds_frame for layer on top of frame
# background color management (only for uniform background)
var back_color # background color RRGGBB
def init(strip)
def init(strip, bri)
self.strip = strip
self.bri = 50 # percentage of brightness 0..100
if (bri == nil) bri = 50 end
self.bri = bri # percentage of brightness 0..100
self.running = false
self.pixel_count = strip.pixel_count()
self.animators = []
self.painters = []
#
self.clear() # clear all leds first
self.frame = Leds_frame(self.pixel_count)
self.layer = Leds_frame(self.pixel_count)
#
tasmota.add_fast_loop(/-> self.fast_loop())
# it may be useful to reduce Sleep time here
self.fast_loop_cb = def() self.fast_loop() end
self.back_color = 0x000000
end
def add_anim(anim)
# cb
def set_back_color(col)
self.back_color = col
end
def add_background_animator(anim)
anim.set_cb(self, self.set_back_color)
self.add_animator(anim)
end
def add_animator(anim)
self.animators.push(anim)
anim.run() # start the animator
end
def add_painter(painter)
self.painters.push(painter)
end
def clear()
@ -32,9 +75,25 @@ class Leds_animator
end
def start()
self.running = true
var animators = self.animators
var idx = 0
while idx < size(animators)
animators[idx].start()
idx += 1
end
self.fast_loop_next = 0 # run immediately
tasmota.add_fast_loop(self.fast_loop_cb)
end
def stop()
self.running = false
var animators = self.animators
var idx = 0
while idx < size(animators)
animators[idx].stop()
idx += 1
end
tasmota.remove_fast_loop(self.fast_loop_cb)
end
def set_bri(bri)
@ -44,21 +103,52 @@ class Leds_animator
return self.bri
end
def set_cb(obj, method)
self.animate_object = obj
self.animate_method = method
end
def fast_loop()
if self.running
if self.running && tasmota.time_reached(self.fast_loop_next) && self.strip.can_show()
# prepare environnement
self.frame.fill_pixels(self.back_color)
# run animators first
var i = 0
var now = tasmota.millis()
self.fast_loop_next = now + self.FAST_LOOP_MIN
while i < size(self.animators)
var anim = self.animators[i]
if anim.is_running()
anim.animate()
self.animators[i].animate(now)
i += 1
else
self.animators.remove(i) # remove any finished animator
# var anim = self.animators[i]
# if anim.is_running()
# anim.animate(now)
# i += 1
# else
# self.animators.remove(i) # remove any finished animator
# end
end
# apply painters
i = 0
var frame = self.frame
var layer = self.layer
while i < size(self.painters)
layer.fill_pixels(0xFF000000) # fill with transparent color
if (self.painters[i].paint(layer))
frame.blend_pixels(layer)
end
i += 1
end
# tirgger animate and display
var obj = self.animate_object
var mth = self.animate_method
if (obj && mth)
mth(obj)
end
self.animate()
# now display the frame
self.frame.paste_pixels(self.strip.pixels_buffer(), self.bri, self.strip.gamma)
self.strip.dirty()
self.strip.show()
end
end
@ -67,6 +157,7 @@ class Leds_animator
end
def remove()
tasmota.remove_driver(self)
self.clear()
tasmota.remove_fast_loop(self.fast_loop_cb)
end
end

View File

@ -0,0 +1,28 @@
#- Native code used for code solidification -#
#- Do not use it -#
tasmota = nil
#@ solidify:Leds_frame_be
class Leds_frame_be
def init(pixels)
if (pixels < 0) pixels = -pixels end
self.pixel_size = pixels
super(self).init(pixels * (-4))
end
def item(i)
return self.get(i * 4, 4)
end
def setitem(i, v)
self.set(i * 4, v, 4)
end
def set_pixel(i, r, g, b, alpha)
if (alpha == nil) alpha = 0 end
var color = ((alpha & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF)
self.setitem(i, color)
end
end

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,358 @@
/* Solidification of leds_animate_effects.h */
/********************************************************************\
* Generated code, don't edit *
\********************************************************************/
#include "be_constobj.h"
extern const bclass be_class_Leds_pulse;
/********************************************************************
** Solidified function: set_slew_size
********************************************************************/
be_local_closure(Leds_pulse_set_slew_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(slew_size),
}),
be_str_weak(set_slew_size),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_back_color
********************************************************************/
be_local_closure(Leds_pulse_set_back_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(back_color),
}),
be_str_weak(set_back_color),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_index
********************************************************************/
be_local_closure(Leds_pulse_set_index, /* 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(index),
}),
be_str_weak(set_index),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_pulse_size
********************************************************************/
be_local_closure(Leds_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: init
********************************************************************/
be_local_closure(Leds_pulse_init, /* name */
be_nested_proto(
5, /* nstack */
4, /* 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_const_int(16777215),
/* K1 */ be_const_int(1),
/* K2 */ be_const_int(0),
/* K3 */ be_nested_str_weak(color),
/* K4 */ be_nested_str_weak(back_color),
/* K5 */ be_const_int(-16777216),
/* K6 */ be_nested_str_weak(pulse_size),
/* K7 */ be_nested_str_weak(slew_size),
}),
be_str_weak(init),
&be_const_str_solidified,
( &(const binstruction[23]) { /* code */
0x4C100000, // 0000 LDNIL R4
0x1C100204, // 0001 EQ R4 R1 R4
0x78120000, // 0002 JMPF R4 #0004
0x58040000, // 0003 LDCONST R1 K0
0x4C100000, // 0004 LDNIL R4
0x1C100404, // 0005 EQ R4 R2 R4
0x78120000, // 0006 JMPF R4 #0008
0x58080001, // 0007 LDCONST R2 K1
0x4C100000, // 0008 LDNIL R4
0x1C100604, // 0009 EQ R4 R3 R4
0x78120000, // 000A JMPF R4 #000C
0x580C0002, // 000B LDCONST R3 K2
0x90020601, // 000C SETMBR R0 K3 R1
0x90020905, // 000D SETMBR R0 K4 K5
0x14100502, // 000E LT R4 R2 K2
0x78120000, // 000F JMPF R4 #0011
0x58080002, // 0010 LDCONST R2 K2
0x90020C02, // 0011 SETMBR R0 K6 R2
0x14100702, // 0012 LT R4 R3 K2
0x78120000, // 0013 JMPF R4 #0015
0x580C0002, // 0014 LDCONST R3 K2
0x90020E03, // 0015 SETMBR R0 K7 R3
0x80000000, // 0016 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** 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_nested_proto(
22, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[13]) { /* constants */
/* 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),
/* K4 */ be_nested_str_weak(slew_size),
/* K5 */ be_nested_str_weak(pulse_size),
/* K6 */ be_nested_str_weak(color),
/* K7 */ be_nested_str_weak(pixel_size),
/* K8 */ be_const_int(0),
/* K9 */ be_const_int(1),
/* K10 */ be_nested_str_weak(blend),
/* K11 */ be_nested_str_weak(tasmota),
/* K12 */ be_nested_str_weak(scale_int),
}),
be_str_weak(paint),
&be_const_str_solidified,
( &(const binstruction[91]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x200C0501, // 0001 NE R3 R2 K1
0x780E0002, // 0002 JMPF R3 #0006
0x8C0C0302, // 0003 GETMET R3 R1 K2
0x5C140400, // 0004 MOVE R5 R2
0x7C0C0400, // 0005 CALL R3 2
0x880C0103, // 0006 GETMBR R3 R0 K3
0x88100104, // 0007 GETMBR R4 R0 K4
0x88140105, // 0008 GETMBR R5 R0 K5
0x88180106, // 0009 GETMBR R6 R0 K6
0x881C0307, // 000A GETMBR R7 R1 K7
0x4C200000, // 000B LDNIL R8
0x4C240000, // 000C LDNIL R9
0x5C200600, // 000D MOVE R8 R3
0x00280605, // 000E ADD R10 R3 R5
0x5C241400, // 000F MOVE R9 R10
0x14281108, // 0010 LT R10 R8 K8
0x782A0000, // 0011 JMPF R10 #0013
0x58200008, // 0012 LDCONST R8 K8
0x28281207, // 0013 GE R10 R9 R7
0x782A0000, // 0014 JMPF R10 #0016
0x5C240E00, // 0015 MOVE R9 R7
0x5C281000, // 0016 MOVE R10 R8
0x142C1409, // 0017 LT R11 R10 R9
0x782E0002, // 0018 JMPF R11 #001C
0x98041406, // 0019 SETIDX R1 R10 R6
0x00281509, // 001A ADD R10 R10 K9
0x7001FFFA, // 001B JMP #0017
0x242C0908, // 001C GT R11 R4 K8
0x782E003A, // 001D JMPF R11 #0059
0x042C0604, // 001E SUB R11 R3 R4
0x5C201600, // 001F MOVE R8 R11
0x5C240600, // 0020 MOVE R9 R3
0x142C1108, // 0021 LT R11 R8 K8
0x782E0000, // 0022 JMPF R11 #0024
0x58200008, // 0023 LDCONST R8 K8
0x282C1207, // 0024 GE R11 R9 R7
0x782E0000, // 0025 JMPF R11 #0027
0x5C240E00, // 0026 MOVE R9 R7
0x5C281000, // 0027 MOVE R10 R8
0x142C1409, // 0028 LT R11 R10 R9
0x782E000F, // 0029 JMPF R11 #003A
0x8C2C030A, // 002A GETMET R11 R1 K10
0x5C340400, // 002B MOVE R13 R2
0x5C380C00, // 002C MOVE R14 R6
0xB83E1600, // 002D GETNGBL R15 K11
0x8C3C1F0C, // 002E GETMET R15 R15 K12
0x5C441400, // 002F MOVE R17 R10
0x04480604, // 0030 SUB R18 R3 R4
0x04482509, // 0031 SUB R18 R18 K9
0x5C4C0600, // 0032 MOVE R19 R3
0x545200FE, // 0033 LDINT R20 255
0x58540008, // 0034 LDCONST R21 K8
0x7C3C0C00, // 0035 CALL R15 6
0x7C2C0800, // 0036 CALL R11 4
0x9804140B, // 0037 SETIDX R1 R10 R11
0x00281509, // 0038 ADD R10 R10 K9
0x7001FFED, // 0039 JMP #0028
0x002C0605, // 003A ADD R11 R3 R5
0x5C201600, // 003B MOVE R8 R11
0x002C0605, // 003C ADD R11 R3 R5
0x002C1604, // 003D ADD R11 R11 R4
0x5C241600, // 003E MOVE R9 R11
0x142C1108, // 003F LT R11 R8 K8
0x782E0000, // 0040 JMPF R11 #0042
0x58200008, // 0041 LDCONST R8 K8
0x282C1207, // 0042 GE R11 R9 R7
0x782E0000, // 0043 JMPF R11 #0045
0x5C240E00, // 0044 MOVE R9 R7
0x5C281000, // 0045 MOVE R10 R8
0x142C1409, // 0046 LT R11 R10 R9
0x782E0010, // 0047 JMPF R11 #0059
0x8C2C030A, // 0048 GETMET R11 R1 K10
0x5C340400, // 0049 MOVE R13 R2
0x5C380C00, // 004A MOVE R14 R6
0xB83E1600, // 004B GETNGBL R15 K11
0x8C3C1F0C, // 004C GETMET R15 R15 K12
0x5C441400, // 004D MOVE R17 R10
0x00480605, // 004E ADD R18 R3 R5
0x04482509, // 004F SUB R18 R18 K9
0x004C0605, // 0050 ADD R19 R3 R5
0x004C2604, // 0051 ADD R19 R19 R4
0x58500008, // 0052 LDCONST R20 K8
0x545600FE, // 0053 LDINT R21 255
0x7C3C0C00, // 0054 CALL R15 6
0x7C2C0800, // 0055 CALL R11 4
0x9804140B, // 0056 SETIDX R1 R10 R11
0x00281509, // 0057 ADD R10 R10 K9
0x7001FFEC, // 0058 JMP #0046
0x502C0200, // 0059 LDBOOL R11 1 0
0x80041600, // 005A RET 1 R11
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Leds_pulse
********************************************************************/
be_local_class(Leds_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(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(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(slew_size, 5), be_const_var(3) },
{ be_const_key_weak(index, 0), be_const_var(2) },
})),
be_str_weak(Leds_pulse)
);
/*******************************************************************/
void be_load_Leds_pulse_class(bvm *vm) {
be_pushntvclass(vm, &be_class_Leds_pulse);
be_setglobal(vm, "Leds_pulse");
be_pop(vm, 1);
}
/********************************************************************/
/* End of solidification */

View File

@ -6,223 +6,6 @@
extern const bclass be_class_Leds_animator;
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Leds_animator_init, /* name */
be_nested_proto(
5, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
1, /* has sup protos */
( &(const struct bproto*[ 1]) {
be_nested_proto(
2, /* nstack */
0, /* argc */
0, /* varg */
1, /* has upvals */
( &(const bupvaldesc[ 1]) { /* upvals */
be_local_const_upval(1, 0),
}),
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_str_weak(fast_loop),
}),
be_str_weak(_X3Clambda_X3E),
&be_const_str_solidified,
( &(const binstruction[ 4]) { /* code */
0x68000000, // 0000 GETUPV R0 U0
0x8C000100, // 0001 GETMET R0 R0 K0
0x7C000200, // 0002 CALL R0 1
0x80040000, // 0003 RET 1 R0
})
),
}),
1, /* has constants */
( &(const bvalue[ 8]) { /* 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(clear),
/* K6 */ be_nested_str_weak(tasmota),
/* K7 */ be_nested_str_weak(add_fast_loop),
}),
be_str_weak(init),
&be_const_str_solidified,
( &(const binstruction[19]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x540A0031, // 0001 LDINT R2 50
0x90020202, // 0002 SETMBR R0 K1 R2
0x50080000, // 0003 LDBOOL R2 0 0
0x90020402, // 0004 SETMBR R0 K2 R2
0x8C080303, // 0005 GETMET R2 R1 K3
0x7C080200, // 0006 CALL R2 1
0x90020602, // 0007 SETMBR R0 K3 R2
0x60080012, // 0008 GETGBL R2 G18
0x7C080000, // 0009 CALL R2 0
0x90020802, // 000A SETMBR R0 K4 R2
0x8C080105, // 000B GETMET R2 R0 K5
0x7C080200, // 000C CALL R2 1
0xB80A0C00, // 000D GETNGBL R2 K6
0x8C080507, // 000E GETMET R2 R2 K7
0x84100000, // 000F CLOSURE R4 P0
0x7C080400, // 0010 CALL R2 2
0xA0000000, // 0011 CLOSE R0
0x80000000, // 0012 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: add_anim
********************************************************************/
be_local_closure(Leds_animator_add_anim, /* name */
be_nested_proto(
5, /* 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(animators),
/* K1 */ be_nested_str_weak(push),
/* K2 */ be_nested_str_weak(run),
}),
be_str_weak(add_anim),
&be_const_str_solidified,
( &(const binstruction[ 7]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x7C080400, // 0003 CALL R2 2
0x8C080302, // 0004 GETMET R2 R1 K2
0x7C080200, // 0005 CALL R2 1
0x80000000, // 0006 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: stop
********************************************************************/
be_local_closure(Leds_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[ 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: fast_loop
********************************************************************/
be_local_closure(Leds_animator_fast_loop, /* name */
be_nested_proto(
6, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 7]) { /* constants */
/* K0 */ be_nested_str_weak(running),
/* K1 */ be_const_int(0),
/* K2 */ be_nested_str_weak(animators),
/* K3 */ be_nested_str_weak(is_running),
/* K4 */ be_nested_str_weak(animate),
/* K5 */ be_const_int(1),
/* K6 */ be_nested_str_weak(remove),
}),
be_str_weak(fast_loop),
&be_const_str_solidified,
( &(const binstruction[25]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x78060015, // 0001 JMPF R1 #0018
0x58040001, // 0002 LDCONST R1 K1
0x6008000C, // 0003 GETGBL R2 G12
0x880C0102, // 0004 GETMBR R3 R0 K2
0x7C080200, // 0005 CALL R2 1
0x14080202, // 0006 LT R2 R1 R2
0x780A000D, // 0007 JMPF R2 #0016
0x88080102, // 0008 GETMBR R2 R0 K2
0x94080401, // 0009 GETIDX R2 R2 R1
0x8C0C0503, // 000A GETMET R3 R2 K3
0x7C0C0200, // 000B CALL R3 1
0x780E0003, // 000C JMPF R3 #0011
0x8C0C0504, // 000D GETMET R3 R2 K4
0x7C0C0200, // 000E CALL R3 1
0x00040305, // 000F ADD R1 R1 K5
0x70020003, // 0010 JMP #0015
0x880C0102, // 0011 GETMBR R3 R0 K2
0x8C0C0706, // 0012 GETMET R3 R3 K6
0x5C140200, // 0013 MOVE R5 R1
0x7C0C0400, // 0014 CALL R3 2
0x7001FFEC, // 0015 JMP #0003
0x8C080104, // 0016 GETMET R2 R0 K4
0x7C080200, // 0017 CALL R2 1
0x80000000, // 0018 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: animate
********************************************************************/
be_local_closure(Leds_animator_animate, /* name */
be_nested_proto(
1, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
0, /* has constants */
NULL, /* no const */
be_str_weak(animate),
&be_const_str_solidified,
( &(const binstruction[ 1]) { /* code */
0x80000000, // 0000 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: remove
********************************************************************/
@ -236,18 +19,22 @@ be_local_closure(Leds_animator_remove, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str_weak(tasmota),
/* K1 */ be_nested_str_weak(remove_driver),
( &(const bvalue[ 4]) { /* constants */
/* K0 */ be_nested_str_weak(clear),
/* K1 */ be_nested_str_weak(tasmota),
/* K2 */ be_nested_str_weak(remove_fast_loop),
/* K3 */ be_nested_str_weak(fast_loop_cb),
}),
be_str_weak(remove),
&be_const_str_solidified,
( &(const binstruction[ 5]) { /* code */
0xB8060000, // 0000 GETNGBL R1 K0
0x8C040301, // 0001 GETMET R1 R1 K1
0x5C0C0000, // 0002 MOVE R3 R0
0x7C040400, // 0003 CALL R1 2
0x80000000, // 0004 RET 0
( &(const binstruction[ 7]) { /* code */
0x8C040100, // 0000 GETMET R1 R0 K0
0x7C040200, // 0001 CALL R1 1
0xB8060200, // 0002 GETNGBL R1 K1
0x8C040302, // 0003 GETMET R1 R1 K2
0x880C0103, // 0004 GETMBR R3 R0 K3
0x7C040400, // 0005 CALL R1 2
0x80000000, // 0006 RET 0
})
)
);
@ -255,11 +42,11 @@ be_local_closure(Leds_animator_remove, /* name */
/********************************************************************
** Solidified function: set_bri
** Solidified function: add_background_animator
********************************************************************/
be_local_closure(Leds_animator_set_bri, /* name */
be_local_closure(Leds_animator_add_background_animator, /* name */
be_nested_proto(
2, /* nstack */
6, /* nstack */
2, /* argc */
2, /* varg */
0, /* has upvals */
@ -267,69 +54,22 @@ be_local_closure(Leds_animator_set_bri, /* name */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_str_weak(bri),
( &(const bvalue[ 3]) { /* constants */
/* K0 */ be_nested_str_weak(set_cb),
/* K1 */ be_nested_str_weak(set_back_color),
/* K2 */ be_nested_str_weak(add_animator),
}),
be_str_weak(set_bri),
be_str_weak(add_background_animator),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_bri
********************************************************************/
be_local_closure(Leds_animator_get_bri, /* name */
be_nested_proto(
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[ 1]) { /* constants */
/* K0 */ be_nested_str_weak(bri),
}),
be_str_weak(get_bri),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x80040400, // 0001 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: start
********************************************************************/
be_local_closure(Leds_animator_start, /* 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(start),
&be_const_str_solidified,
( &(const binstruction[ 3]) { /* code */
0x50040200, // 0000 LDBOOL R1 1 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x80000000, // 0002 RET 0
( &(const binstruction[ 8]) { /* code */
0x8C080300, // 0000 GETMET R2 R1 K0
0x5C100000, // 0001 MOVE R4 R0
0x88140101, // 0002 GETMBR R5 R0 K1
0x7C080600, // 0003 CALL R2 3
0x8C080102, // 0004 GETMET R2 R0 K2
0x5C100200, // 0005 MOVE R4 R1
0x7C080400, // 0006 CALL R2 2
0x80000000, // 0007 RET 0
})
)
);
@ -369,29 +109,568 @@ be_local_closure(Leds_animator_clear, /* name */
/*******************************************************************/
/********************************************************************
** Solidified function: add_animator
********************************************************************/
be_local_closure(Leds_animator_add_animator, /* name */
be_nested_proto(
5, /* 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(animators),
/* K1 */ be_nested_str_weak(push),
}),
be_str_weak(add_animator),
&be_const_str_solidified,
( &(const binstruction[ 5]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x7C080400, // 0003 CALL R2 2
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: animate
********************************************************************/
be_local_closure(Leds_animator_animate, /* name */
be_nested_proto(
1, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
0, /* has constants */
NULL, /* no const */
be_str_weak(animate),
&be_const_str_solidified,
( &(const binstruction[ 1]) { /* code */
0x80000000, // 0000 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: get_bri
********************************************************************/
be_local_closure(Leds_animator_get_bri, /* name */
be_nested_proto(
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[ 1]) { /* constants */
/* K0 */ be_nested_str_weak(bri),
}),
be_str_weak(get_bri),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x80040400, // 0001 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_bri
********************************************************************/
be_local_closure(Leds_animator_set_bri, /* 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(bri),
}),
be_str_weak(set_bri),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_back_color
********************************************************************/
be_local_closure(Leds_animator_set_back_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(back_color),
}),
be_str_weak(set_back_color),
&be_const_str_solidified,
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: stop
********************************************************************/
be_local_closure(Leds_animator_stop, /* name */
be_nested_proto(
6, /* 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(running),
/* K1 */ be_nested_str_weak(animators),
/* K2 */ be_const_int(0),
/* K3 */ be_nested_str_weak(stop),
/* K4 */ be_const_int(1),
/* K5 */ be_nested_str_weak(tasmota),
/* K6 */ be_nested_str_weak(remove_fast_loop),
/* K7 */ be_nested_str_weak(fast_loop_cb),
}),
be_str_weak(stop),
&be_const_str_solidified,
( &(const binstruction[19]) { /* code */
0x50040000, // 0000 LDBOOL R1 0 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x88040101, // 0002 GETMBR R1 R0 K1
0x58080002, // 0003 LDCONST R2 K2
0x600C000C, // 0004 GETGBL R3 G12
0x5C100200, // 0005 MOVE R4 R1
0x7C0C0200, // 0006 CALL R3 1
0x140C0403, // 0007 LT R3 R2 R3
0x780E0004, // 0008 JMPF R3 #000E
0x940C0202, // 0009 GETIDX R3 R1 R2
0x8C0C0703, // 000A GETMET R3 R3 K3
0x7C0C0200, // 000B CALL R3 1
0x00080504, // 000C ADD R2 R2 K4
0x7001FFF5, // 000D JMP #0004
0xB80E0A00, // 000E GETNGBL R3 K5
0x8C0C0706, // 000F GETMET R3 R3 K6
0x88140107, // 0010 GETMBR R5 R0 K7
0x7C0C0400, // 0011 CALL R3 2
0x80000000, // 0012 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_cb
********************************************************************/
be_local_closure(Leds_animator_set_cb, /* name */
be_nested_proto(
3, /* nstack */
3, /* 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(animate_object),
/* K1 */ be_nested_str_weak(animate_method),
}),
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: init
********************************************************************/
be_local_closure(Leds_animator_init, /* name */
be_nested_proto(
5, /* nstack */
3, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
1, /* has sup protos */
( &(const struct bproto*[ 1]) {
be_nested_proto(
2, /* nstack */
0, /* argc */
0, /* varg */
1, /* has upvals */
( &(const bupvaldesc[ 1]) { /* upvals */
be_local_const_upval(1, 0),
}),
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 1]) { /* constants */
/* K0 */ be_nested_str_weak(fast_loop),
}),
be_str_weak(_anonymous_),
&be_const_str_solidified,
( &(const binstruction[ 4]) { /* code */
0x68000000, // 0000 GETUPV R0 U0
0x8C000100, // 0001 GETMET R0 R0 K0
0x7C000200, // 0002 CALL R0 1
0x80000000, // 0003 RET 0
})
),
}),
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),
/* K9 */ be_nested_str_weak(layer),
/* K10 */ be_nested_str_weak(fast_loop_cb),
/* K11 */ be_nested_str_weak(back_color),
/* K12 */ be_const_int(0),
}),
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
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: add_painter
********************************************************************/
be_local_closure(Leds_animator_add_painter, /* name */
be_nested_proto(
5, /* 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(painters),
/* K1 */ be_nested_str_weak(push),
}),
be_str_weak(add_painter),
&be_const_str_solidified,
( &(const binstruction[ 5]) { /* code */
0x88080100, // 0000 GETMBR R2 R0 K0
0x8C080501, // 0001 GETMET R2 R2 K1
0x5C100200, // 0002 MOVE R4 R1
0x7C080400, // 0003 CALL R2 2
0x80000000, // 0004 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: fast_loop
********************************************************************/
be_local_closure(Leds_animator_fast_loop, /* name */
be_nested_proto(
12, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[28]) { /* constants */
/* K0 */ be_nested_str_weak(running),
/* K1 */ be_nested_str_weak(tasmota),
/* K2 */ be_nested_str_weak(time_reached),
/* K3 */ be_nested_str_weak(fast_loop_next),
/* K4 */ be_nested_str_weak(strip),
/* K5 */ be_nested_str_weak(can_show),
/* K6 */ be_nested_str_weak(frame),
/* K7 */ be_nested_str_weak(fill_pixels),
/* K8 */ be_nested_str_weak(back_color),
/* K9 */ be_const_int(0),
/* K10 */ be_nested_str_weak(millis),
/* K11 */ be_nested_str_weak(FAST_LOOP_MIN),
/* K12 */ be_nested_str_weak(animators),
/* K13 */ be_nested_str_weak(animate),
/* K14 */ be_const_int(1),
/* K15 */ be_nested_str_weak(layer),
/* K16 */ be_nested_str_weak(painters),
/* K17 */ be_const_int(-16777216),
/* K18 */ be_nested_str_weak(paint),
/* K19 */ be_nested_str_weak(blend_pixels),
/* K20 */ be_nested_str_weak(animate_object),
/* K21 */ be_nested_str_weak(animate_method),
/* K22 */ be_nested_str_weak(paste_pixels),
/* K23 */ be_nested_str_weak(pixels_buffer),
/* K24 */ be_nested_str_weak(bri),
/* K25 */ be_nested_str_weak(gamma),
/* K26 */ be_nested_str_weak(dirty),
/* K27 */ be_nested_str_weak(show),
}),
be_str_weak(fast_loop),
&be_const_str_solidified,
( &(const binstruction[81]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x7806004D, // 0001 JMPF R1 #0050
0xB8060200, // 0002 GETNGBL R1 K1
0x8C040302, // 0003 GETMET R1 R1 K2
0x880C0103, // 0004 GETMBR R3 R0 K3
0x7C040400, // 0005 CALL R1 2
0x78060048, // 0006 JMPF R1 #0050
0x88040104, // 0007 GETMBR R1 R0 K4
0x8C040305, // 0008 GETMET R1 R1 K5
0x7C040200, // 0009 CALL R1 1
0x78060044, // 000A JMPF R1 #0050
0x88040106, // 000B GETMBR R1 R0 K6
0x8C040307, // 000C GETMET R1 R1 K7
0x880C0108, // 000D GETMBR R3 R0 K8
0x7C040400, // 000E CALL R1 2
0x58040009, // 000F LDCONST R1 K9
0xB80A0200, // 0010 GETNGBL R2 K1
0x8C08050A, // 0011 GETMET R2 R2 K10
0x7C080200, // 0012 CALL R2 1
0x880C010B, // 0013 GETMBR R3 R0 K11
0x000C0403, // 0014 ADD R3 R2 R3
0x90020603, // 0015 SETMBR R0 K3 R3
0x600C000C, // 0016 GETGBL R3 G12
0x8810010C, // 0017 GETMBR R4 R0 K12
0x7C0C0200, // 0018 CALL R3 1
0x140C0203, // 0019 LT R3 R1 R3
0x780E0006, // 001A JMPF R3 #0022
0x880C010C, // 001B GETMBR R3 R0 K12
0x940C0601, // 001C GETIDX R3 R3 R1
0x8C0C070D, // 001D GETMET R3 R3 K13
0x5C140400, // 001E MOVE R5 R2
0x7C0C0400, // 001F CALL R3 2
0x0004030E, // 0020 ADD R1 R1 K14
0x7001FFF3, // 0021 JMP #0016
0x58040009, // 0022 LDCONST R1 K9
0x880C0106, // 0023 GETMBR R3 R0 K6
0x8810010F, // 0024 GETMBR R4 R0 K15
0x6014000C, // 0025 GETGBL R5 G12
0x88180110, // 0026 GETMBR R6 R0 K16
0x7C140200, // 0027 CALL R5 1
0x14140205, // 0028 LT R5 R1 R5
0x7816000D, // 0029 JMPF R5 #0038
0x8C140907, // 002A GETMET R5 R4 K7
0x581C0011, // 002B LDCONST R7 K17
0x7C140400, // 002C CALL R5 2
0x88140110, // 002D GETMBR R5 R0 K16
0x94140A01, // 002E GETIDX R5 R5 R1
0x8C140B12, // 002F GETMET R5 R5 K18
0x5C1C0800, // 0030 MOVE R7 R4
0x7C140400, // 0031 CALL R5 2
0x78160002, // 0032 JMPF R5 #0036
0x8C140713, // 0033 GETMET R5 R3 K19
0x5C1C0800, // 0034 MOVE R7 R4
0x7C140400, // 0035 CALL R5 2
0x0004030E, // 0036 ADD R1 R1 K14
0x7001FFEC, // 0037 JMP #0025
0x88140114, // 0038 GETMBR R5 R0 K20
0x88180115, // 0039 GETMBR R6 R0 K21
0x78160003, // 003A JMPF R5 #003F
0x781A0002, // 003B JMPF R6 #003F
0x5C1C0C00, // 003C MOVE R7 R6
0x5C200A00, // 003D MOVE R8 R5
0x7C1C0200, // 003E CALL R7 1
0x8C1C010D, // 003F GETMET R7 R0 K13
0x7C1C0200, // 0040 CALL R7 1
0x881C0106, // 0041 GETMBR R7 R0 K6
0x8C1C0F16, // 0042 GETMET R7 R7 K22
0x88240104, // 0043 GETMBR R9 R0 K4
0x8C241317, // 0044 GETMET R9 R9 K23
0x7C240200, // 0045 CALL R9 1
0x88280118, // 0046 GETMBR R10 R0 K24
0x882C0104, // 0047 GETMBR R11 R0 K4
0x882C1719, // 0048 GETMBR R11 R11 K25
0x7C1C0800, // 0049 CALL R7 4
0x881C0104, // 004A GETMBR R7 R0 K4
0x8C1C0F1A, // 004B GETMET R7 R7 K26
0x7C1C0200, // 004C CALL R7 1
0x881C0104, // 004D GETMBR R7 R0 K4
0x8C1C0F1B, // 004E GETMET R7 R7 K27
0x7C1C0200, // 004F CALL R7 1
0x80000000, // 0050 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: start
********************************************************************/
be_local_closure(Leds_animator_start, /* name */
be_nested_proto(
6, /* nstack */
1, /* argc */
2, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 9]) { /* constants */
/* K0 */ be_nested_str_weak(running),
/* K1 */ be_nested_str_weak(animators),
/* K2 */ be_const_int(0),
/* K3 */ be_nested_str_weak(start),
/* K4 */ be_const_int(1),
/* K5 */ be_nested_str_weak(fast_loop_next),
/* K6 */ be_nested_str_weak(tasmota),
/* K7 */ be_nested_str_weak(add_fast_loop),
/* K8 */ be_nested_str_weak(fast_loop_cb),
}),
be_str_weak(start),
&be_const_str_solidified,
( &(const binstruction[20]) { /* code */
0x50040200, // 0000 LDBOOL R1 1 0
0x90020001, // 0001 SETMBR R0 K0 R1
0x88040101, // 0002 GETMBR R1 R0 K1
0x58080002, // 0003 LDCONST R2 K2
0x600C000C, // 0004 GETGBL R3 G12
0x5C100200, // 0005 MOVE R4 R1
0x7C0C0200, // 0006 CALL R3 1
0x140C0403, // 0007 LT R3 R2 R3
0x780E0004, // 0008 JMPF R3 #000E
0x940C0202, // 0009 GETIDX R3 R1 R2
0x8C0C0703, // 000A GETMET R3 R3 K3
0x7C0C0200, // 000B CALL R3 1
0x00080504, // 000C ADD R2 R2 K4
0x7001FFF5, // 000D JMP #0004
0x90020B02, // 000E SETMBR R0 K5 K2
0xB80E0C00, // 000F GETNGBL R3 K6
0x8C0C0707, // 0010 GETMET R3 R3 K7
0x88140108, // 0011 GETMBR R5 R0 K8
0x7C0C0400, // 0012 CALL R3 2
0x80000000, // 0013 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Leds_animator
********************************************************************/
be_local_class(Leds_animator,
5,
13,
NULL,
be_nested_map(15,
be_nested_map(28,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key_weak(init, 12), be_const_closure(Leds_animator_init_closure) },
{ be_const_key_weak(clear, -1), be_const_closure(Leds_animator_clear_closure) },
{ be_const_key_weak(stop, 13), be_const_closure(Leds_animator_stop_closure) },
{ be_const_key_weak(add_anim, 4), be_const_closure(Leds_animator_add_anim_closure) },
{ be_const_key_weak(pixel_count, 6), be_const_var(1) },
{ be_const_key_weak(animate, -1), be_const_closure(Leds_animator_animate_closure) },
{ be_const_key_weak(animators, 7), be_const_var(4) },
{ be_const_key_weak(strip, -1), be_const_var(0) },
{ be_const_key_weak(bri, -1), be_const_var(2) },
{ be_const_key_weak(remove, 8), be_const_closure(Leds_animator_remove_closure) },
{ be_const_key_weak(get_bri, -1), be_const_closure(Leds_animator_get_bri_closure) },
{ be_const_key_weak(start, -1), be_const_closure(Leds_animator_start_closure) },
{ be_const_key_weak(running, -1), be_const_var(3) },
{ 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(set_bri, 1), be_const_closure(Leds_animator_set_bri_closure) },
{ be_const_key_weak(add_animator, -1), be_const_closure(Leds_animator_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(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(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(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(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_str_weak(Leds_animator)
);

View File

@ -0,0 +1,186 @@
/* Solidification of leds_frame_be_methods.h */
/********************************************************************\
* Generated code, don't edit *
\********************************************************************/
#include "be_constobj.h"
extern const bclass be_class_Leds_frame_be;
/********************************************************************
** Solidified function: setitem
********************************************************************/
be_local_closure(Leds_frame_be_setitem, /* name */
be_nested_proto(
8, /* 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(set),
}),
&be_const_str_setitem,
&be_const_str_solidified,
( &(const binstruction[ 7]) { /* code */
0x8C0C0100, // 0000 GETMET R3 R0 K0
0x54160003, // 0001 LDINT R5 4
0x08140205, // 0002 MUL R5 R1 R5
0x5C180400, // 0003 MOVE R6 R2
0x541E0003, // 0004 LDINT R7 4
0x7C0C0800, // 0005 CALL R3 4
0x80000000, // 0006 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_pixel
********************************************************************/
be_local_closure(Leds_frame_be_set_pixel, /* name */
be_nested_proto(
11, /* nstack */
6, /* 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_const_int(0),
/* K1 */ be_nested_str(setitem),
}),
&be_const_str_set_pixel,
&be_const_str_solidified,
( &(const binstruction[26]) { /* code */
0x4C180000, // 0000 LDNIL R6
0x1C180A06, // 0001 EQ R6 R5 R6
0x781A0000, // 0002 JMPF R6 #0004
0x58140000, // 0003 LDCONST R5 K0
0x541A00FE, // 0004 LDINT R6 255
0x2C180A06, // 0005 AND R6 R5 R6
0x541E0017, // 0006 LDINT R7 24
0x38180C07, // 0007 SHL R6 R6 R7
0x541E00FE, // 0008 LDINT R7 255
0x2C1C0407, // 0009 AND R7 R2 R7
0x5422000F, // 000A LDINT R8 16
0x381C0E08, // 000B SHL R7 R7 R8
0x30180C07, // 000C OR R6 R6 R7
0x541E00FE, // 000D LDINT R7 255
0x2C1C0607, // 000E AND R7 R3 R7
0x54220007, // 000F LDINT R8 8
0x381C0E08, // 0010 SHL R7 R7 R8
0x30180C07, // 0011 OR R6 R6 R7
0x541E00FE, // 0012 LDINT R7 255
0x2C1C0807, // 0013 AND R7 R4 R7
0x30180C07, // 0014 OR R6 R6 R7
0x8C1C0101, // 0015 GETMET R7 R0 K1
0x5C240200, // 0016 MOVE R9 R1
0x5C280C00, // 0017 MOVE R10 R6
0x7C1C0600, // 0018 CALL R7 3
0x80000000, // 0019 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: item
********************************************************************/
be_local_closure(Leds_frame_be_item, /* name */
be_nested_proto(
6, /* 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(get),
}),
&be_const_str_item,
&be_const_str_solidified,
( &(const binstruction[ 6]) { /* code */
0x8C080100, // 0000 GETMET R2 R0 K0
0x54120003, // 0001 LDINT R4 4
0x08100204, // 0002 MUL R4 R1 R4
0x54160003, // 0003 LDINT R5 4
0x7C080600, // 0004 CALL R2 3
0x80040400, // 0005 RET 1 R2
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Leds_frame_be_init, /* name */
be_nested_proto(
5, /* 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_const_int(0),
/* K1 */ be_nested_str(pixel_size),
/* K2 */ be_nested_str(init),
}),
&be_const_str_init,
&be_const_str_solidified,
( &(const binstruction[12]) { /* code */
0x14080300, // 0000 LT R2 R1 K0
0x780A0000, // 0001 JMPF R2 #0003
0x44040200, // 0002 NEG R1 R1
0x90020201, // 0003 SETMBR R0 K1 R1
0x60080003, // 0004 GETGBL R2 G3
0x5C0C0000, // 0005 MOVE R3 R0
0x7C080200, // 0006 CALL R2 1
0x8C080502, // 0007 GETMET R2 R2 K2
0x5411FFFB, // 0008 LDINT R4 -4
0x08100204, // 0009 MUL R4 R1 R4
0x7C080400, // 000A CALL R2 2
0x80000000, // 000B RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Leds_frame_be
********************************************************************/
be_local_class(Leds_frame_be,
0,
NULL,
be_nested_map(4,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_const_key(setitem, 1), be_const_closure(Leds_frame_be_setitem_closure) },
{ be_const_key(set_pixel, -1), be_const_closure(Leds_frame_be_set_pixel_closure) },
{ be_const_key(item, -1), be_const_closure(Leds_frame_be_item_closure) },
{ be_const_key(init, -1), be_const_closure(Leds_frame_be_init_closure) },
})),
(bstring*) &be_const_str_Leds_frame_be
);
/*******************************************************************/
void be_load_Leds_frame_be_class(bvm *vm) {
be_pushntvclass(vm, &be_class_Leds_frame_be);
be_setglobal(vm, "Leds_frame_be");
be_pop(vm, 1);
}
/********************************************************************/
/* End of solidification */

View File

@ -0,0 +1,51 @@
#
# 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()

View File

@ -199,22 +199,29 @@ extern "C" {
case 9: // # 09 : ClearTo (color:??) -> void
{
uint32_t rgbw = be_toint(vm, 3);
uint8_t w = (rgbw & 0xFF000000) >> 24;
uint8_t r = (rgbw & 0xFF0000) >> 16;
uint8_t g = (rgbw & 0xFF00) >> 8;
uint8_t b = (rgbw & 0xFF);
uint8_t w = (rgbw >> 24) & 0xFF;
uint8_t r = (rgbw >> 16) & 0xFF;
uint8_t g = (rgbw >> 8) & 0xFF;
uint8_t b = (rgbw ) & 0xFF;
if (argc >= 5 && be_isint(vm, 4) && be_isint(vm, 5)) {
uint32_t from = be_toint(vm, 4);
uint32_t len = be_toint(vm, 5);
if (s_ws2812_grb) s_ws2812_grb->ClearTo(RgbColor(r, g, b), from, from + len - 1);
if (s_sk6812_grbw) s_sk6812_grbw->ClearTo(RgbwColor(r, g, b, w), from, from + len - 1);
} else {
if (s_ws2812_grb) s_ws2812_grb->ClearTo(RgbColor(r, g, b));
if (s_sk6812_grbw) s_sk6812_grbw->ClearTo(RgbwColor(r, g, b, w));
}
}
break;
case 10: // # 10 : SetPixelColor (idx:int, color:??) -> void
{
int32_t idx = be_toint(vm, 3);
uint32_t rgbw = be_toint(vm, 4);
uint8_t w = (rgbw & 0xFF000000) >> 24;
uint8_t r = (rgbw & 0xFF0000) >> 16;
uint8_t g = (rgbw & 0xFF00) >> 8;
uint8_t b = (rgbw & 0xFF);
uint8_t w = (rgbw >> 24) & 0xFF;
uint8_t r = (rgbw >> 16) & 0xFF;
uint8_t g = (rgbw >> 8) & 0xFF;
uint8_t b = (rgbw ) & 0xFF;
if (s_ws2812_grb) s_ws2812_grb->SetPixelColor(idx, RgbColor(r, g, b));
if (s_sk6812_grbw) s_sk6812_grbw->SetPixelColor(idx, RgbwColor(r, g, b, w));
}
@ -242,6 +249,234 @@ extern "C" {
}
be_raise(vm, kTypeError, nullptr);
}
}
extern "C" {
// Leds.blend_color(color_a:int, color_b:int [, alpha:int]) -> color:int
//
// color_a is 0x..RRGGBB
// color_b is 0xAARRGGBB, AA is transparency (00: opaque, FF: transparent)
// Note: the default is 00 considered opaque, so Transparency = 255 - alpha
// alpha is 0..255, and optional. If present it overrides `AA` from color_b
// Note: alpha `00` is transparent, `FF` is opaque
int32_t be_leds_blend_color(bvm *vm);
int32_t be_leds_blend_color(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 2 && be_isint(vm, 1) && be_isint(vm, 2)) {
uint32_t color_a = be_toint(vm, 1);
uint32_t color_b = be_toint(vm, 2);
uint32_t transpency = (color_b >> 24) & 0xFF;
if (top >= 3 && be_isint(vm, 3)) {
transpency = 255 - be_toint(vm, 3);
}
// remove any transparency
color_a = color_a & 0xFFFFFF;
color_b = color_b & 0xFFFFFF;
if (transpency == 0) { // color_b is opaque, return color_b
be_pushint(vm, color_b);
be_return(vm);
}
if (transpency >= 255) { // color_b is transparent, return color_a
be_pushint(vm, color_a);
be_return(vm);
}
int32_t r = changeUIntScale(transpency, 0, 255, (color_b >> 16) & 0xFF, (color_a >> 16) & 0xFF);
int32_t g = changeUIntScale(transpency, 0, 255, (color_b >> 8) & 0xFF, (color_a >> 8) & 0xFF);
int32_t b = changeUIntScale(transpency, 0, 255, (color_b ) & 0xFF, (color_a ) & 0xFF);
uint32_t rgb = (r << 16) | (g << 8) | b;
be_pushint(vm, rgb);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
static uint32_t ApplyBriGamma(uint32_t color_a /* 0xRRGGBB */, uint32_t bri /* 0..100 */, bool gamma) {
if (bri == 0) { return 0x000000; } // if bri is zero, short-cut
uint32_t r = (color_a >> 16) & 0xFF;
uint32_t g = (color_a >> 8) & 0xFF;
uint32_t b = (color_a ) & 0xFF;
if (bri < 100) { // apply bri
r = changeUIntScale(bri, 0, 100, 0, r);
g = changeUIntScale(bri, 0, 100, 0, g);
b = changeUIntScale(bri, 0, 100, 0, b);
}
if (gamma) { // apply gamma
r = ledGamma(r);
g = ledGamma(g);
b = ledGamma(b);
}
uint32_t rgb = (r << 16) | (g << 8) | b;
return rgb;
}
// Leds.apply_bri_gamma(color_rgb:int (0xRRGGBB) [bri:int (0..100), gamma:bool]) -> color:int (0xRRGGBB)
//
int32_t be_leds_apply_bri_gamma(bvm *vm);
int32_t be_leds_apply_bri_gamma(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 1 && be_isint(vm, 1)) {
uint32_t color_a = be_toint(vm, 1);
uint32_t bri = 100;
if (top >= 2 && be_isint(vm, 2)) {
bri = be_toint(vm, 2);
}
bool gamma = false;
if (top >= 3) {
gamma = be_tobool(vm, 3);
}
uint32_t rgb = ApplyBriGamma(color_a, bri, gamma);
be_pushint(vm, rgb);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Leds_frame.blend(color1:int, color2:int, alpha:int) -> int
//
int32_t be_leds_blend(bvm *vm);
int32_t be_leds_blend(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 3 && be_isint(vm, 1) && be_isint(vm, 2) && be_isint(vm, 3)) {
uint32_t color_a = be_toint(vm, 1);
uint32_t color_b = be_toint(vm, 2);
uint32_t alpha = be_toint(vm, 3);
uint32_t r = (color_a >> 16) & 0xFF;
uint32_t g = (color_a >> 8) & 0xFF;
uint32_t b = (color_a ) & 0xFF;
uint32_t r2 = (color_b >> 16) & 0xFF;
uint32_t g2 = (color_b >> 8) & 0xFF;
uint32_t b2 = (color_b ) & 0xFF;
uint32_t r3 = changeUIntScale(alpha, 0, 255, r2, r);
uint32_t g3 = changeUIntScale(alpha, 0, 255, g2, g);
uint32_t b3 = changeUIntScale(alpha, 0, 255, b2, b);
uint32_t rgb = (r3 << 16) | (g3 << 8) | b3;
be_pushint(vm, rgb);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Leds_frame.blend_pixels(dest:bytes(), foreground:bytes) -> nil
// Destination can be the same as foreground or background
//
// All calculation are done in `0xAARRGGBB` format, AA=0 if opaque (i.e. ignored)
// Background has always alpha = 0 (any other value is ignored) - for simplification
// Size is truncated to smallest of all 3 buffers
int32_t be_leds_blend_pixels(bvm *vm);
int32_t be_leds_blend_pixels(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 2 && be_isbytes(vm, 2)) {
size_t dest_len = 0;
uint32_t * dest_buf = (uint32_t*) be_tobytes(vm, 1, &dest_len);
// back = dest for now, could be changed in the future
size_t back_len = 0;
const uint32_t * back_buf = (const uint32_t*) be_tobytes(vm, 1, &back_len);
size_t fore_len = 0;
const uint32_t * fore_buf = (const uint32_t*) be_tobytes(vm, 2, &fore_len);
if (fore_len < dest_len) { dest_len = fore_len; }
if (back_len < dest_len) { dest_len = back_len; }
size_t pixels_count = dest_len / 4;
if (pixels_count > 0) {
uint32_t * dest = (uint32_t *)dest_buf;
uint32_t * back = (uint32_t *)back_buf;
uint32_t * fore = (uint32_t *)fore_buf;
for (size_t i = 0; i < pixels_count; i++) {
uint32_t back_argb = back[i];
uint32_t fore_argb = fore[i];
uint32_t fore_alpha = (fore_argb >> 24) & 0xFF;
uint32_t dest_rgb_new = back_argb;
if (fore_alpha == 0) { // opaque layer, copy value from fore
dest_rgb_new = fore_argb;
} else if (fore_alpha == 255) { // fore is transparent, use back
// nothing to do, dest_rgb_new = back_argb above
} else {
uint32_t back_r = (back_argb >> 16) & 0xFF;
uint32_t fore_r = (fore_argb >> 16) & 0xFF;
uint32_t back_g = (back_argb >> 8) & 0xFF;
uint32_t fore_g = (fore_argb >> 8) & 0xFF;
uint32_t back_b = (back_argb ) & 0xFF;
uint32_t fore_b = (fore_argb ) & 0xFF;
uint32_t dest_r_new = changeUIntScale(fore_alpha, 0, 255, fore_r, back_r);
uint32_t dest_g_new = changeUIntScale(fore_alpha, 0, 255, fore_g, back_g);
uint32_t dest_b_new = changeUIntScale(fore_alpha, 0, 255, fore_b, back_b);
dest_rgb_new = (dest_r_new << 16) | (dest_g_new << 8) | dest_b_new;
}
dest[i] = dest_rgb_new;
}
}
be_return_nil(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Leds_frame.fill_pixels(dest:bytes(), color:int) -> nil
//
// Fill buffer with same color
int32_t be_leds_fill_pixels(bvm *vm);
int32_t be_leds_fill_pixels(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 2 && be_isint(vm, 2)) {
size_t dest_len = 0;
uint32_t * dest_buf = (uint32_t*) be_tobytes(vm, 1, &dest_len);
uint32_t color = be_toint(vm, 2);
size_t pixels_count = dest_len / 4;
if (pixels_count > 0) {
uint32_t * dest = (uint32_t *)dest_buf;
for (size_t i = 0; i < pixels_count; i++) {
dest[i] = color;
}
}
be_return_nil(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Leds_frame.paste_pixels(neopixel:bytes(), led_buffer:bytes(), bri:int 0..100, gamma:bool)
//
// Copy from ARGB buffer to GRB
int32_t be_leds_paste_pixels(bvm *vm);
int32_t be_leds_paste_pixels(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 2 && be_isbytes(vm, 2)) {
size_t src_len = 0;
uint32_t * src_buf = (uint32_t*) be_tobytes(vm, 1, &src_len);
size_t dest_len = 0;
uint8_t * dest_buf = (uint8_t*) be_tobytes(vm, 2, &dest_len);
uint32_t bri = 100;
if (top >= 3 && be_isint(vm, 3)) {
bri = be_toint(vm, 3);
}
bool gamma = false;
if (top >= 4 && be_isbool(vm, 4)) {
gamma = be_tobool(vm, 4);
}
size_t pixels_count = src_len / 4;
if (pixels_count > dest_len / 3) { pixels_count = dest_len / 3; }
if (pixels_count > 0) {
for (size_t i = 0; i < pixels_count; i++) {
uint32_t src_argb = ApplyBriGamma(src_buf[i], bri, gamma);
uint32_t src_r = (src_argb >> 16) & 0xFF;
uint32_t src_g = (src_argb >> 8) & 0xFF;
uint32_t src_b = (src_argb ) & 0xFF;
dest_buf[i * 3 + 0] = src_g;
dest_buf[i * 3 + 1] = src_r;
dest_buf[i * 3 + 2] = src_b;
}
}
be_return_nil(vm);
}
be_raise(vm, kTypeError, nullptr);
}
}