Skip to content

Commit

Permalink
add scroll method to Leds_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Staars committed Dec 21, 2024
1 parent 8311bff commit a67066b
Show file tree
Hide file tree
Showing 5 changed files with 727 additions and 293 deletions.
111 changes: 110 additions & 1 deletion lib/libesp32/berry_tasmota/src/embedded/leds.be
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,117 @@ class Leds : Leds_ntv
self.strip.set_pixel_color(x * self.w + y + self.offset, col, bri)
end
end
def _reverse_line(buffer) # for RGB only - no RGBW
var len = size(buffer)
var pos = 0
var b0
while pos < len
b0 = buffer[pos]
buffer[pos] = buffer[pos+2]
buffer[pos+2] = b0
pos += 3 # pixel size
end
return buffer.reverse()
end

def scroll(direction, outshift, inshift) # 0 - up, 1 - left, 2 - down, 3 - right ; outshift madatory, inshift optional
var buf = self.pix_buffer
var h = self.h
var sz = self.w * 3 # row size in bytes
var pos
if direction%2 == 0 #up/down
if direction == 0 #up
outshift.setbytes(0,self._reverse_line(buf[0..sz-1]))
var line = 0
while line < (h-1)
pos = 0
var offset_dst = line * sz
var offset_src = ((line+2) * sz) - 3
while pos < sz
var dst = pos + offset_dst
var src = offset_src - pos
buf[dst] = buf[src]
buf[dst+1] = buf[src+1]
buf[dst+2] = buf[src+2]
pos += 3
end
line += 1
end
var lastline = inshift ? inshift : outshift
if h%2 == 1
lastline.setbytes(0,self._reverse_line(lastline))
end
buf.setbytes((h-1) * sz, lastline)
else # down
outshift.setbytes(0,self._reverse_line(buf[size(buf)-sz..]))
var line = h - 1
while line > 0
buf.setbytes(line * sz,self._reverse_line(buf[(line-1) * sz..line * sz-1]))
line -= 1
end
var lastline = inshift ? inshift : outshift
if h%2 == 1
lastline.setbytes(0,self._reverse_line(lastline))
end
buf.setbytes(0, lastline)
end
else # left/right
var pixel_copy = bytes(-3)
var line = 0
var step = 3
if direction == 3 # right
step *= -1
end
while line < h
pos = line * sz
if step > 0
var line_end = pos + sz - step
outshift[(line * 3)] = buf[pos]
outshift[(line * 3) + 1] = buf[pos+1]
outshift[(line * 3) + 2] = buf[pos+2]
while pos < line_end
buf[pos] = buf[pos+3]
buf[pos+1] = buf[pos+4]
buf[pos+2] = buf[pos+5]
pos += step
end
if inshift == nil
buf[line_end] = outshift[(line * 3)]
buf[line_end+1] = outshift[(line * 3) + 1]
buf[line_end+2] = outshift[(line * 3) + 2]
else
buf[line_end] = inshift[(line * 3)]
buf[line_end+1] = inshift[(line * 3) + 1]
buf[line_end+2] = inshift[(line * 3) + 2]
end
else
var line_end = pos
pos = pos + sz + step
outshift[(line * 3)] = buf[pos]
outshift[(line * 3) + 1] = buf[pos+1]
outshift[(line * 3) + 2] = buf[pos+2]
while pos > line_end
buf[pos] = buf[pos-3]
buf[pos+1] = buf[pos-2]
buf[pos+2] = buf[pos-1]
pos += step
end
if inshift == nil
buf[line_end] = outshift[(line * 3)]
buf[line_end+1] = outshift[(line * 3) + 1]
buf[line_end+2] = outshift[(line * 3) + 2]
else
buf[line_end] = inshift[(line * 3)]
buf[line_end+1] = inshift[(line * 3) + 1]
buf[line_end+2] = inshift[(line * 3) + 2]
end
end
step *= -1
line += 1
end
end
end
end

return Leds_matrix(self, w, h, offset)

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static const bvalue be_ktab_class_AXP192[37] = {
/* K3 */ be_const_int(2),
/* K4 */ be_const_int(3),
/* K5 */ be_nested_str(read24),
/* K6 */ be_const_real_hex(0x3A102DE0),
/* K6 */ be_const_real_hex(0x3A102DE1),
/* K7 */ be_nested_str(read12),
/* K8 */ be_const_real_hex(0x3A902DE0),
/* K9 */ be_const_real_hex(0x3EC00000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const bvalue be_ktab_class_AXP202[24] = {
/* K9 */ be_nested_str(read13),
/* K10 */ be_const_real_hex(0x3F000000),
/* K11 */ be_nested_str(read24),
/* K12 */ be_const_real_hex(0x3A102DE0),
/* K12 */ be_const_real_hex(0x3A102DE1),
/* K13 */ be_const_real_hex(0x3AB78035),
/* K14 */ be_const_real_hex(0x3ADED28A),
/* K15 */ be_nested_str(write_bit),
Expand Down
Loading

0 comments on commit a67066b

Please sign in to comment.