Skip to content

Commit

Permalink
add scroll to Leds_matrix (#22693)
Browse files Browse the repository at this point in the history
  • Loading branch information
Staars authored Dec 21, 2024
1 parent 9f3c785 commit 6745bc1
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions lib/libesp32/berry_tasmota/src/embedded/leds.be
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,103 @@ class Leds : Leds_ntv
self.strip.set_pixel_color(x * self.w + y + self.offset, col, bri)
end
end

def scroll(direction, outshift, inshift) # 0 - up, 1 - left, 2 - down, 3 - right ; outshift mandatory, 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,(buf[0..sz-1]).reverse(0,nil,3))
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.reverse(0,nil,3)
end
buf.setbytes((h-1) * sz, lastline)
else # down
outshift.setbytes(0,(buf[size(buf)-sz..]).reverse(0,nil,3))
var line = h - 1
while line > 0
buf.setbytes(line * sz,(buf[(line-1) * sz..line * sz-1]).reverse(0,nil,3))
line -= 1
end
var lastline = inshift ? inshift : outshift
if h%2 == 1
lastline.reverse(0,nil,3)
end
buf.setbytes(0, lastline)
end
else # left/right
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)
Expand Down

0 comments on commit 6745bc1

Please sign in to comment.