mirror of https://github.com/arendst/Tasmota.git
add scroll to Leds_matrix (#22693)
This commit is contained in:
parent
9f3c7859d7
commit
6745bc1b48
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue