Skip to content

Commit 3f93d2d

Browse files
authored
Berry remove 'Leds.create_matrix' from the standard library waiting for reimplementation (arendst#23114)
1 parent 06aa356 commit 3f93d2d

File tree

3 files changed

+450
-1727
lines changed

3 files changed

+450
-1727
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Berry load `.tapp` files in `/.extensions/` then in `/`
99

1010
### Breaking Changed
11+
- Berry remove `Leds.create_matrix` from the standard library waiting for reimplementation
1112

1213
### Changed
1314
- ESP32 Platform from 2025.02.30 to 2025.03.30, Framework (Arduino Core) from v3.1.1.250203 to v3.1.3.250302 and IDF from v5.3.2.250120 to 5.3.2.250228 (#23088)

lib/libesp32/berry_tasmota/src/embedded/leds.be

-246
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,6 @@ class Leds : Leds_ntv
158158
def get_gamma()
159159
return self.gamma
160160
end
161-
# def rotate_left(rot, first, last)
162-
# self.call_native(20, rot, first, last)
163-
# end
164-
# def rotate_right(rot, first, last)
165-
# self.call_native(21, rot, first, last)
166-
# end
167-
# def shift_left(rot, first, last)
168-
# self.call_native(22, rot, first, last)
169-
# end
170-
# def shift_right(rot, first, last)
171-
# self.call_native(22, rot, first, last)
172-
# end
173161

174162
# apply gamma and bri
175163
def to_gamma(rgb, bri)
@@ -252,217 +240,6 @@ class Leds : Leds_ntv
252240

253241
end
254242

255-
def create_matrix(w, h, offset)
256-
offset = int(offset)
257-
w = int(w)
258-
h = int(h)
259-
if offset == nil offset = 0 end
260-
if w * h + offset > self.leds || h < 0 || w < 0 || offset < 0
261-
raise "value_error", "out of range"
262-
end
263-
264-
# inner class
265-
class Leds_matrix
266-
var strip
267-
var offset
268-
var h, w
269-
var alternate # are rows in alternate mode (even/odd are reversed)
270-
var pix_buffer
271-
var pix_size
272-
273-
def init(strip, w, h, offset)
274-
self.strip = strip
275-
self.offset = offset
276-
self.h = h
277-
self.w = w
278-
self.alternate = false
279-
280-
self.pix_buffer = self.strip.pixels_buffer()
281-
self.pix_size = self.strip.pixel_size()
282-
end
283-
284-
def clear()
285-
self.clear_to(0x000000)
286-
self.show()
287-
end
288-
289-
def begin()
290-
# do nothing, already being handled by physical strip
291-
end
292-
def show(force)
293-
# don't trigger on segment, you will need to trigger on full strip instead
294-
if bool(force) || (self.offset == 0 && self.w * self.h == self.strip.leds)
295-
self.strip.show()
296-
self.pix_buffer = self.strip.pixels_buffer(self.pix_buffer) # update buffer after show()
297-
end
298-
end
299-
def can_show()
300-
return self.strip.can_show()
301-
end
302-
def is_dirty() ## DEPRECATED
303-
return self.strip.is_dirty()
304-
end
305-
def dirty() ## DEPRECATED
306-
self.strip.dirty()
307-
end
308-
def pixels_buffer()
309-
return self.strip.pixels_buffer()
310-
end
311-
def pixel_size()
312-
return self.pix_size
313-
end
314-
def pixel_count()
315-
return self.w * self.h
316-
end
317-
def pixel_offset()
318-
return self.offset
319-
end
320-
def clear_to(col, bri)
321-
if (bri == nil) bri = self.strip.bri end
322-
self.strip.call_native(9, self.strip.to_gamma(col, bri), self.offset, self.w * self.h)
323-
end
324-
def set_pixel_color(idx, col, bri)
325-
if (bri == nil) bri = self.strip.bri end
326-
self.strip.set_pixel_color(idx + self.offset, col, bri)
327-
end
328-
def get_pixel_color(idx)
329-
return self.strip.get_pixel_color(idx + self.offseta)
330-
end
331-
332-
# setbytes(row, bytes)
333-
# sets the raw bytes for `row`, copying at most 3 or 4 x col bytes
334-
def set_bytes(row, buf, offset, len)
335-
var h_bytes = self.h * self.pix_size
336-
if (len > h_bytes) len = h_bytes end
337-
var offset_in_matrix = (self.offset + row) * h_bytes
338-
self.pix_buffer.setbytes(offset_in_matrix, buf, offset, len)
339-
end
340-
341-
# Leds_matrix specific
342-
def set_alternate(alt)
343-
self.alternate = alt
344-
end
345-
def get_alternate()
346-
return self.alternate
347-
end
348-
349-
def set_matrix_pixel_color(x, y, col, bri)
350-
if (bri == nil) bri = self.strip.bri end
351-
if self.alternate && (y & 0x1)
352-
# reversed line
353-
self.strip.set_pixel_color(x * self.w + self.h - y - 1 + self.offset, col, bri)
354-
else
355-
self.strip.set_pixel_color(x * self.w + y + self.offset, col, bri)
356-
end
357-
end
358-
359-
def scroll(direction, outshift, inshift) # 0 - up, 1 - left, 2 - down, 3 - right ; outshift mandatory, inshift optional
360-
var buf = self.pix_buffer
361-
var h = self.h
362-
var sz = self.w * 3 # row size in bytes
363-
var pos
364-
if direction%2 == 0 #up/down
365-
if direction == 0 #up
366-
outshift.setbytes(0,(buf[0..sz-1]).reverse(0,nil,3))
367-
var line = 0
368-
while line < (h-1)
369-
pos = 0
370-
var offset_dst = line * sz
371-
var offset_src = ((line+2) * sz) - 3
372-
while pos < sz
373-
var dst = pos + offset_dst
374-
var src = offset_src - pos
375-
buf[dst] = buf[src]
376-
buf[dst+1] = buf[src+1]
377-
buf[dst+2] = buf[src+2]
378-
pos += 3
379-
end
380-
line += 1
381-
end
382-
var lastline = inshift ? inshift : outshift
383-
if h%2 == 1
384-
lastline.reverse(0,nil,3)
385-
end
386-
buf.setbytes((h-1) * sz, lastline)
387-
else # down
388-
outshift.setbytes(0,(buf[size(buf)-sz..]).reverse(0,nil,3))
389-
var line = h - 1
390-
while line > 0
391-
buf.setbytes(line * sz,(buf[(line-1) * sz..line * sz-1]).reverse(0,nil,3))
392-
line -= 1
393-
end
394-
var lastline = inshift ? inshift : outshift
395-
if h%2 == 1
396-
lastline.reverse(0,nil,3)
397-
end
398-
buf.setbytes(0, lastline)
399-
end
400-
else # left/right
401-
var line = 0
402-
var step = 3
403-
if direction == 3 # right
404-
step *= -1
405-
end
406-
while line < h
407-
pos = line * sz
408-
if step > 0
409-
var line_end = pos + sz - step
410-
outshift[(line * 3)] = buf[pos]
411-
outshift[(line * 3) + 1] = buf[pos+1]
412-
outshift[(line * 3) + 2] = buf[pos+2]
413-
while pos < line_end
414-
buf[pos] = buf[pos+3]
415-
buf[pos+1] = buf[pos+4]
416-
buf[pos+2] = buf[pos+5]
417-
pos += step
418-
end
419-
if inshift == nil
420-
buf[line_end] = outshift[(line * 3)]
421-
buf[line_end+1] = outshift[(line * 3) + 1]
422-
buf[line_end+2] = outshift[(line * 3) + 2]
423-
else
424-
buf[line_end] = inshift[(line * 3)]
425-
buf[line_end+1] = inshift[(line * 3) + 1]
426-
buf[line_end+2] = inshift[(line * 3) + 2]
427-
end
428-
else
429-
var line_end = pos
430-
pos = pos + sz + step
431-
outshift[(line * 3)] = buf[pos]
432-
outshift[(line * 3) + 1] = buf[pos+1]
433-
outshift[(line * 3) + 2] = buf[pos+2]
434-
while pos > line_end
435-
buf[pos] = buf[pos-3]
436-
buf[pos+1] = buf[pos-2]
437-
buf[pos+2] = buf[pos-1]
438-
pos += step
439-
end
440-
if inshift == nil
441-
buf[line_end] = outshift[(line * 3)]
442-
buf[line_end+1] = outshift[(line * 3) + 1]
443-
buf[line_end+2] = outshift[(line * 3) + 2]
444-
else
445-
buf[line_end] = inshift[(line * 3)]
446-
buf[line_end+1] = inshift[(line * 3) + 1]
447-
buf[line_end+2] = inshift[(line * 3) + 2]
448-
end
449-
end
450-
step *= -1
451-
line += 1
452-
end
453-
end
454-
end
455-
end
456-
457-
return Leds_matrix(self, w, h, offset)
458-
459-
end
460-
461-
static def matrix(w, h, gpio, rmt)
462-
var strip = Leds(w * h, gpio, rmt)
463-
var matrix = strip.create_matrix(w, h, 0)
464-
return matrix
465-
end
466243
end
467244

468245

@@ -483,26 +260,3 @@ end
483260
anim()
484261
485262
-#
486-
487-
#-
488-
489-
var s = Leds(25, gpio.pin(gpio.WS2812, 1)).create_matrix(5, 5)
490-
s.set_alternate(true)
491-
s.clear_to(0x400000)
492-
s.show()
493-
x = 0
494-
y = 0
495-
496-
def anim()
497-
s.clear_to(0x400000)
498-
s.set_matrix_pixel_color(x, y, 0x004000)
499-
s.show()
500-
y = (y + 1) % 5
501-
if y == 0
502-
x = (x + 1) % 5
503-
end
504-
tasmota.set_timer(200, anim)
505-
end
506-
anim()
507-
508-
-#

0 commit comments

Comments
 (0)