Merge pull request #13890 from s-hadinger/leds3

Berry leds improvements
This commit is contained in:
s-hadinger 2021-12-01 22:59:55 +01:00 committed by GitHub
commit a3f5d0df58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1535 additions and 449 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +0,0 @@
/********************************************************************
* Berry class `Leds_matrix`
*
*******************************************************************/
#include "be_constobj.h"
#ifdef USE_WS2812
/********************************************************************
** Solidified function: get_alternate
********************************************************************/
be_local_closure(Leds_matrix_get_alternate, /* name */
be_nested_proto(
2, /* nstack */
1, /* argc */
0, /* 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_literal("alternate"),
}),
(be_nested_const_str("get_alternate", 1450148894, 13)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 2]) { /* code */
0x88040100, // 0000 GETMBR R1 R0 K0
0x80040200, // 0001 RET 1 R1
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_alternate
********************************************************************/
be_local_closure(Leds_matrix_set_alternate, /* name */
be_nested_proto(
2, /* nstack */
2, /* argc */
0, /* 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_literal("alternate"),
}),
(be_nested_const_str("set_alternate", 1709680562, 13)),
((bstring*) &be_const_str_input),
( &(const binstruction[ 2]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x80000000, // 0001 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: set_matrix_pixel_color
********************************************************************/
be_local_closure(Leds_matrix_set_matrix_pixel_color, /* name */
be_nested_proto(
10, /* nstack */
5, /* argc */
0, /* 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_literal("alternate"),
/* K1 */ be_const_int(2),
/* K2 */ be_nested_str_literal("set_pixel_color"),
/* K3 */ be_nested_str_literal("w"),
/* K4 */ be_nested_str_literal("h"),
/* K5 */ be_const_int(1),
}),
(be_nested_const_str("set_matrix_pixel_color", 1197149462, 22)),
((bstring*) &be_const_str_input),
( &(const binstruction[23]) { /* code */
0x88140100, // 0000 GETMBR R5 R0 K0
0x7816000C, // 0001 JMPF R5 #000F
0x10140301, // 0002 MOD R5 R1 K1
0x7816000A, // 0003 JMPF R5 #000F
0x8C140102, // 0004 GETMET R5 R0 K2
0x881C0103, // 0005 GETMBR R7 R0 K3
0x081C0207, // 0006 MUL R7 R1 R7
0x88200104, // 0007 GETMBR R8 R0 K4
0x001C0E08, // 0008 ADD R7 R7 R8
0x041C0E02, // 0009 SUB R7 R7 R2
0x041C0F05, // 000A SUB R7 R7 K5
0x5C200600, // 000B MOVE R8 R3
0x5C240800, // 000C MOVE R9 R4
0x7C140800, // 000D CALL R5 4
0x70020006, // 000E JMP #0016
0x8C140102, // 000F GETMET R5 R0 K2
0x881C0103, // 0010 GETMBR R7 R0 K3
0x081C0207, // 0011 MUL R7 R1 R7
0x001C0E02, // 0012 ADD R7 R7 R2
0x5C200600, // 0013 MOVE R8 R3
0x5C240800, // 0014 MOVE R9 R4
0x7C140800, // 0015 CALL R5 4
0x80000000, // 0016 RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified function: init
********************************************************************/
be_local_closure(Leds_matrix_init, /* name */
be_nested_proto(
10, /* nstack */
5, /* argc */
0, /* varg */
0, /* has upvals */
NULL, /* no upvals */
0, /* has sup protos */
NULL, /* no sub protos */
1, /* has constants */
( &(const bvalue[ 4]) { /* constants */
/* K0 */ be_nested_str_literal("w"),
/* K1 */ be_nested_str_literal("h"),
/* K2 */ be_nested_str_literal("alternate"),
/* K3 */ be_nested_str_literal("init"),
}),
(be_nested_const_str("init", 380752755, 4)),
((bstring*) &be_const_str_input),
( &(const binstruction[13]) { /* code */
0x90020001, // 0000 SETMBR R0 K0 R1
0x90020202, // 0001 SETMBR R0 K1 R2
0x50140000, // 0002 LDBOOL R5 0 0
0x90020405, // 0003 SETMBR R0 K2 R5
0x60140003, // 0004 GETGBL R5 G3
0x5C180000, // 0005 MOVE R6 R0
0x7C140200, // 0006 CALL R5 1
0x8C140B03, // 0007 GETMET R5 R5 K3
0x081C0202, // 0008 MUL R7 R1 R2
0x5C200600, // 0009 MOVE R8 R3
0x5C240800, // 000A MOVE R9 R4
0x7C140800, // 000B CALL R5 4
0x80000000, // 000C RET 0
})
)
);
/*******************************************************************/
/********************************************************************
** Solidified class: Leds_matrix
********************************************************************/
extern const bclass be_class_Leds;
be_local_class(Leds_matrix,
3,
&be_class_Leds,
be_nested_map(7,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("init", 380752755, 4, 3), be_const_closure(Leds_matrix_init_closure) },
{ be_nested_key("h", -317966505, 1, -1), be_const_var(0) },
{ be_nested_key("set_alternate", 1709680562, 13, 6), be_const_closure(Leds_matrix_set_alternate_closure) },
{ be_nested_key("set_matrix_pixel_color", 1197149462, 22, 4), be_const_closure(Leds_matrix_set_matrix_pixel_color_closure) },
{ be_nested_key("w", -234078410, 1, -1), be_const_var(1) },
{ be_nested_key("get_alternate", 1450148894, 13, 0), be_const_closure(Leds_matrix_get_alternate_closure) },
{ be_nested_key("alternate", 1140253277, 9, -1), be_const_var(2) },
})),
be_str_literal("Leds_matrix")
);
/*******************************************************************/
void be_load_Leds_matrix_class(bvm *vm) {
be_pushntvclass(vm, &be_class_Leds_matrix);
be_setglobal(vm, "Leds_matrix");
be_pop(vm, 1);
}
#endif // USE_WS2812

View File

@ -8,9 +8,7 @@ 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 WS2812_GRBW = 2
static SK6812_GRB = 3
static SK6812_GRBW = 4
static SK6812_GRBW = 2
# skeleton for native call
def call_native() end
@ -30,15 +28,13 @@ extern int be_neopixelbus_call_native(bvm *vm);
be_local_class(Leds_ntv,
2,
NULL,
be_nested_map(7,
be_nested_map(5,
( (struct bmapnode*) &(const bmapnode[]) {
{ be_nested_key("WS2812_GRB", 1736405692, 10, 5), be_const_int(1) },
{ be_nested_key("_p", 1594591802, 2, -1), be_const_var(0) },
{ be_nested_key("WS2812_GRBW", -660477967, 11, 3), be_const_int(2) },
{ be_nested_key("call_native", 1389147405, 11, -1), be_const_func(be_neopixelbus_call_native) },
{ be_nested_key("SK6812_GRBW", 81157857, 11, -1), be_const_int(4) },
{ be_nested_key("_t", 1527481326, 2, -1), be_const_var(1) },
{ be_nested_key("SK6812_GRB", 1159411308, 10, 1), be_const_int(3) },
{ be_nested_key("_p", 1594591802, 2, 3), be_const_var(0) },
{ be_nested_key("SK6812_GRBW", 81157857, 11, 4), be_const_int(2) },
{ be_nested_key("WS2812_GRB", 1736405692, 10, -1), be_const_int(1) },
})),
be_str_literal("Leds_ntv")
);

View File

@ -138,7 +138,6 @@ extern void be_load_webclient_lib(bvm *vm);
extern void be_load_crypto_lib(bvm *vm);
extern void be_load_Leds_ntv_class(bvm *vm);
extern void be_load_Leds_class(bvm *vm);
extern void be_load_Leds_matrix_class(bvm *vm);
extern void be_load_Leds_animator_class(bvm *vm);
extern void be_load_ctypes_lib(bvm *vm);
@ -197,7 +196,6 @@ BERRY_API void be_load_custom_libs(bvm *vm)
#ifdef USE_WS2812
be_load_Leds_ntv_class(vm);
be_load_Leds_class(vm);
be_load_Leds_matrix_class(vm);
be_load_Leds_animator_class(vm);
#endif // USE_WS2812
#ifdef USE_I2S_AUDIO_BERRY

View File

@ -24,12 +24,14 @@
class Leds : Leds_ntv
var gamma # if true, apply gamma (true is default)
var leds # number of leds
# leds:int = number of leds of the strip
# gpio:int (optional) = GPIO for NeoPixel. If not specified, takes the WS2812 gpio
# type:int (optional) = Type of LED, defaults to WS2812 RGB
# rmt:int (optional) = RMT hardware channel to use, leave default unless you have a good reason
def init(leds, gpio, type, rmt) # rmt is optional
self.gamma = true # gamma is enabled by default, it should be disabled explicitly if needed
self.leds = int(leds)
if gpio == nil && gpio.pin(gpio.WS2812) >= 0
gpio = gpio.pin(gpio.WS2812)
@ -41,7 +43,7 @@ class Leds : Leds_ntv
end
# initialize the structure
self.ctor(leds, gpio, type, rmt)
self.ctor(self.leds, gpio, type, rmt)
if self._p == nil raise "internal_error", "couldn't not initialize noepixelbus" end
@ -124,8 +126,176 @@ class Leds : Leds_ntv
b
end
end
# `segment`
# create a new `strip` object that maps a part of the current strip
def create_segment(offset, leds)
if int(offset) + int(leds) > self.leds || offset < 0 || leds < 0
raise "value_error", "out of range"
end
# inner class
class Leds_segment
var strip
var offset, leds
def init(strip, offset, leds)
self.strip = strip
self.offset = int(offset)
self.leds = int(leds)
end
def clear()
self.clear_to(0x000000)
self.show()
end
def begin()
# do nothing, already being handled by physical strip
end
def show(force)
# don't trigger on segment, you will need to trigger on full strip instead
if bool(force) || (self.offset == 0 && self.leds == self.strip.leds)
self.strip.show()
end
end
def can_show()
return self.strip.can_show()
end
def is_dirty()
return self.strip.is_dirty()
end
def dirty()
self.strip.dirty()
end
def pixels_buffer()
return nil
end
def pixel_size()
return self.strip.pixel_size()
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
end
def set_pixel_color(idx, col, bri)
self.strip.set_pixel_color(idx + self.offset, col, bri)
end
def get_pixel_color(idx)
return self.strip.get_pixel_color(idx + self.offseta)
end
end
return Leds_segment(self, offset, leds)
end
def create_matrix(w, h, offset)
offset = int(offset)
w = int(w)
h = int(h)
if offset == nil offset = 0 end
if w * h + offset > self.leds || h < 0 || w < 0 || offset < 0
raise "value_error", "out of range"
end
# inner class
class Leds_matrix
var strip
var offset
var h, w
var alternate # are rows in alternate mode (even/odd are reversed)
def init(strip, w, h, offset)
self.strip = strip
self.offset = offset
self.h = h
self.w = w
self.alternate = false
end
def clear()
self.clear_to(0x000000)
self.show()
end
def begin()
# do nothing, already being handled by physical strip
end
def show(force)
# don't trigger on segment, you will need to trigger on full strip instead
if bool(force) || (self.offset == 0 && self.w * self.h == self.strip.leds)
self.strip.show()
end
end
def can_show()
return self.strip.can_show()
end
def is_dirty()
return self.strip.is_dirty()
end
def dirty()
self.strip.dirty()
end
def pixels_buffer()
return nil
end
def pixel_size()
return self.strip.pixel_size()
end
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
end
end
def set_pixel_color(idx, col, bri)
self.strip.set_pixel_color(idx + self.offset, col, bri)
end
def get_pixel_color(idx)
return self.strip.get_pixel_color(idx + self.offseta)
end
# Leds_matrix specific
def set_alternate(alt)
self.alternate = alt
end
def get_alternate()
return self.alternate
end
def set_matrix_pixel_color(x, y, col, bri)
if self.alternate && x % 2
# reversed line
self.strip.set_pixel_color(x * self.w + self.h - y - 1 + self.offset, col, bri)
else
self.strip.set_pixel_color(x * self.w + y + self.offset, col, bri)
end
end
end
return Leds_matrix(self, w, h, offset)
end
static def matrix(w, h, gpio, rmt)
var strip = Leds(w * h, gpio, rmt)
var matrix = strip.create_matrix(w, h, 0)
return matrix
end
end
#-
var s = Leds(25, gpio.pin(gpio.WS2812, 1))
@ -144,34 +314,6 @@ anim()
-#
class Leds_matrix : Leds
var h, w
var alternate # are rows in alternate mode (even/odd are reversed)
def init(w, h, gpio, rmt)
self.w = w
self.h = h
self.alternate = false
super(self).init(w * h, gpio, rmt)
end
def set_alternate(alt)
self.alternate = alt
end
def get_alternate()
return self.alternate
end
def set_matrix_pixel_color(x, y, col, bri)
if self.alternate && x % 2
# reversed line
self.set_pixel_color(x * self.w + self.h - y - 1, col, bri)
else
self.set_pixel_color(x * self.w + y, col, bri)
end
end
end
#-
var s = Leds_matrix(5, 5, gpio.pin(gpio.WS2812, 1))

View File

@ -11,28 +11,6 @@ rainbow.start()
import animate
# https://stackoverflow.com/questions/34187171/fast-integer-square-root-approximation
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
class Rainbow : Leds_animator
var cur_offset # current offset in the palette
static palette = [ 0xFF0000, #- red -#
@ -45,6 +23,7 @@ class Rainbow : Leds_animator
]
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
@ -73,7 +52,7 @@ end
#-
var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1))
var strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Rainbow(strip, 1.0)
r.start()
@ -91,6 +70,7 @@ class Rainbow_stripes : Leds_animator
]
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
@ -125,7 +105,7 @@ end
#-
var strip = Leds_matrix(5,5, gpio.pin(gpio.WS2812, 1))
var strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Rainbow_Matrix(strip, 0.5)
r.start()
@ -138,6 +118,7 @@ class Round : Leds_animator
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)
@ -162,7 +143,7 @@ class Round : Leds_animator
var x = 0
while x < w
var col = col_ref
var dist = fast_sqrt_int( ((y - ch)*(y - ch) + (x - cw)*(x - cw)) << 16)
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
@ -172,11 +153,32 @@ class Round : Leds_animator
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 strip = Leds.matrix(5,5, gpio.pin(gpio.WS2812, 1))
var r = Round(strip, 2, 30)
r.start()

View File

@ -28,16 +28,12 @@
enum {
ws2812_grb = 1,
ws2812_grbw = 2,
sk6812_grb = 3,
sk6812_grbw = 4,
sk6812_grbw = 2,
neopixel_type_end
};
typedef NeoPixelBus<NeoGrbFeature, NeoEsp32RmtN800KbpsMethod> neopixel_ws2812_grb_t;
typedef NeoPixelBus<NeoGrbwFeature, NeoEsp32RmtN800KbpsMethod> neopixel_ws2812_grbw_t;
typedef NeoPixelBus<NeoGrbFeature, NeoEsp32RmtNSk6812Method> neopixel_sk6812_grb_t;
typedef NeoPixelBus<NeoGrbwFeature, NeoEsp32RmtNSk6812Method> neopixel_sk6812_grbw_t;
@ -124,10 +120,6 @@ extern "C" {
switch (neopixel_type) {
case ws2812_grb: strip = new neopixel_ws2812_grb_t(leds, gpio, (NeoBusChannel) rmt);
break;
case ws2812_grbw: strip = new neopixel_ws2812_grbw_t(leds, gpio, (NeoBusChannel) rmt);
break;
case sk6812_grb: strip = new neopixel_sk6812_grb_t(leds, gpio, (NeoBusChannel) rmt);
break;
case sk6812_grbw: strip = new neopixel_sk6812_grbw_t(leds, gpio, (NeoBusChannel) rmt);
break;
}
@ -141,8 +133,6 @@ extern "C" {
const void * s = be_get_neopixelbus(vm); // raises an exception if pointer is invalid
// initialize all possible variants
neopixel_ws2812_grb_t * s_ws2812_grb = (leds_type == ws2812_grb) ? (neopixel_ws2812_grb_t*) s : nullptr;
neopixel_ws2812_grbw_t * s_ws2812_grbw = (leds_type == ws2812_grbw) ? (neopixel_ws2812_grbw_t*) s : nullptr;
neopixel_sk6812_grb_t * s_sk6812_grb = (leds_type == sk6812_grb) ? (neopixel_sk6812_grb_t*) s : nullptr;
neopixel_sk6812_grbw_t * s_sk6812_grbw = (leds_type == sk6812_grbw) ? (neopixel_sk6812_grbw_t*) s : nullptr;
be_pushnil(vm); // push a default `nil` return value
@ -150,46 +140,32 @@ extern "C" {
switch (cmd) {
case 1: // # 01 : begin void -> void
if (s_ws2812_grb) s_ws2812_grb->Begin();
if (s_ws2812_grbw) s_ws2812_grbw->Begin();
if (s_sk6812_grb) s_sk6812_grb->Begin();
if (s_sk6812_grbw) s_sk6812_grbw->Begin();
break;
case 2: // # 02 : show void -> void
if (s_ws2812_grb) s_ws2812_grb->Show();
if (s_ws2812_grbw) s_ws2812_grbw->Show();
if (s_sk6812_grb) s_sk6812_grb->Show();
if (s_sk6812_grbw) s_sk6812_grbw->Show();
break;
case 3: // # 03 : CanShow void -> bool
if (s_ws2812_grb) be_pushbool(vm, s_ws2812_grb->CanShow());
if (s_ws2812_grbw) be_pushbool(vm, s_ws2812_grbw->CanShow());
if (s_sk6812_grb) be_pushbool(vm, s_sk6812_grb->CanShow());
if (s_sk6812_grbw) be_pushbool(vm, s_sk6812_grbw->CanShow());
break;
case 4: // # 04 : IsDirty void -> bool
if (s_ws2812_grb) be_pushbool(vm, s_ws2812_grb->IsDirty());
if (s_ws2812_grbw) be_pushbool(vm, s_ws2812_grbw->IsDirty());
if (s_sk6812_grb) be_pushbool(vm, s_sk6812_grb->IsDirty());
if (s_sk6812_grbw) be_pushbool(vm, s_sk6812_grbw->IsDirty());
break;
case 5: // # 05 : Dirty void -> void
if (s_ws2812_grb) s_ws2812_grb->Dirty();
if (s_ws2812_grbw) s_ws2812_grbw->Dirty();
if (s_sk6812_grb) s_sk6812_grb->Dirty();
if (s_sk6812_grbw) s_sk6812_grbw->Dirty();
break;
case 6: // # 06 : Pixels void -> bytes() (mapped to the buffer)
{
size_t pixels_bytes;
if (s_ws2812_grb) pixels_bytes = s_ws2812_grb->PixelsSize();
if (s_ws2812_grbw) pixels_bytes = s_ws2812_grbw->PixelsSize();
if (s_sk6812_grb) pixels_bytes = s_sk6812_grb->PixelsSize();
if (s_sk6812_grbw) pixels_bytes = s_sk6812_grbw->PixelsSize();
uint8_t * pixels;
if (s_ws2812_grb) pixels = s_ws2812_grb->Pixels();
if (s_ws2812_grbw) pixels = s_ws2812_grbw->Pixels();
if (s_sk6812_grb) pixels = s_sk6812_grb->Pixels();
if (s_sk6812_grbw) pixels = s_sk6812_grbw->Pixels();
be_getbuiltin(vm, "bytes");
@ -201,14 +177,10 @@ extern "C" {
break;
case 7: // # 07 : PixelSize void -> int
if (s_ws2812_grb) be_pushint(vm, s_ws2812_grb->PixelSize());
if (s_ws2812_grbw) be_pushint(vm, s_ws2812_grbw->PixelSize());
if (s_sk6812_grb) be_pushint(vm, s_sk6812_grb->PixelSize());
if (s_sk6812_grbw) be_pushint(vm, s_sk6812_grbw->PixelSize());
break;
case 8: // # 08 : PixelCount void -> int
if (s_ws2812_grb) be_pushint(vm, s_ws2812_grb->PixelCount());
if (s_ws2812_grbw) be_pushint(vm, s_ws2812_grbw->PixelCount());
if (s_sk6812_grb) be_pushint(vm, s_sk6812_grb->PixelCount());
if (s_sk6812_grbw) be_pushint(vm, s_sk6812_grbw->PixelCount());
break;
case 9: // # 09 : ClearTo (color:??) -> void
@ -219,8 +191,6 @@ extern "C" {
uint8_t g = (rgbw & 0xFF00) >> 8;
uint8_t b = (rgbw & 0xFF);
if (s_ws2812_grb) s_ws2812_grb->ClearTo(RgbColor(r, g, b));
if (s_ws2812_grbw) s_ws2812_grbw->ClearTo(RgbwColor(r, g, b, 0));
if (s_sk6812_grb) s_sk6812_grb->ClearTo(RgbColor(r, g, b));
if (s_sk6812_grbw) s_sk6812_grbw->ClearTo(RgbwColor(r, g, b, 0));
}
break;
@ -233,8 +203,6 @@ extern "C" {
uint8_t g = (rgbw & 0xFF00) >> 8;
uint8_t b = (rgbw & 0xFF);
if (s_ws2812_grb) s_ws2812_grb->SetPixelColor(idx, RgbColor(r, g, b));
if (s_ws2812_grbw) s_ws2812_grbw->SetPixelColor(idx, RgbwColor(r, g, b, 0));
if (s_sk6812_grb) s_sk6812_grb->SetPixelColor(idx, RgbColor(r, g, b));
if (s_sk6812_grbw) s_sk6812_grbw->SetPixelColor(idx, RgbwColor(r, g, b, 0));
}
break;
@ -247,43 +215,12 @@ extern "C" {
RgbColor rgb = s_ws2812_grb->GetPixelColor(idx);
be_pushint(vm, (rgb.R << 16) | (rgb.G << 8) | rgb.B);
}
if (s_ws2812_grbw) {
RgbwColor rgbw = s_ws2812_grbw->GetPixelColor(idx);
be_pushint(vm, (rgbw.W << 24) | (rgb.R << 16) | (rgb.G << 8) | rgb.B);
}
if (s_sk6812_grb) {
RgbColor rgb = s_sk6812_grb->GetPixelColor(idx);
be_pushint(vm, (rgb.R << 16) | (rgb.G << 8) | rgb.B);
}
if (s_sk6812_grbw) {
RgbwColor rgbw = s_sk6812_grbw->GetPixelColor(idx);
be_pushint(vm, (rgbw.W << 24) | (rgb.R << 16) | (rgb.G << 8) | rgb.B);
}
}
break;
// case 20: // # 20 : RotateLeft (rot:int [, first:int, last:int]) -> void
// case 21: // # 21 : RotateRight (rot:int [, first:int, last:int]) -> void
// case 22: // # 22 : ShiftLeft (rot:int [, first:int, last:int]) -> void
// case 23: // # 23 : ShiftRight (rot:int [, first:int, last:int]) -> void
// {
// int32_t rot = be_toint(vm, 3);
// int32_t first = -1;
// int32_t last = -1;
// if (argc >= 5) {
// first = be_toint(vm, 4);
// last = be_toint(vm, 5);
// }
// if (20 == cmd) {
// if (first >= 0) { strip->RotateLeft(rot, first, last); } else { strip->RotateLeft(rot); };
// } else if (21 == cmd) {
// if (first >= 0) { strip->RotateRight(rot, first, last); } else { strip->RotateRight(rot); };
// } else if (22 == cmd) {
// if (first >= 0) { strip->ShiftLeft(rot, first, last); } else { strip->ShiftLeft(rot); };
// } else if (23 == cmd) {
// if (first >= 0) { strip->ShiftRight(rot, first, last); } else { strip->ShiftRight(rot); };
// }
// }
// break;
default:
break;
}