modified for 8x8 panels

This commit is contained in:
2021-01-07 10:42:20 +01:00
parent 57106a07d3
commit 4f4cbde2bf

View File

@@ -9,6 +9,8 @@
# e.g. a driver that implements a serial protocol running on an MCU.
#
import time
import math
if not hasattr(time, 'ticks_ms'):
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
time.ticks_ms = lambda: int(time.time()*1000)
@@ -24,6 +26,7 @@ class LedMatrix:
self.fix_r = 0xff
self.fix_g = 0xff
self.fix_b = 0xc0
self.panelcolumn = 8
if config:
if 'debug' in config:
self.debug = config['debug']
@@ -47,6 +50,12 @@ class LedMatrix:
# Initialize display
self.driver.init_display(self.num_pixels)
def round_down(self, n, decimals=0):
multiplier = 10 ** decimals
return math.floor(n * multiplier) / multiplier
def xy_to_phys(self, x, y):
"""
Map x,y to physical LED address after accounting for display rotation
@@ -68,12 +77,13 @@ class LedMatrix:
# one step to the east, and then south to north, before the cycle
# starts over.
stride = self.stride
phys_addr = x*stride
if x & 1:
phys_addr += stride - 1 - y
else:
phys_addr += y
return phys_addr
phys_addr = ((x-1)%self.panelcolumn) + ((y-1)*self.panelcolumn) + (round_down((x-1)/self.panelcolumn) * self.panelcolumn * self.panelcolumn)
#MOD(x-1;panelCol) + ((y-1)*panelCol) + (FLOOR.MATH((x-1)/panelCol;1)*panelCol*panelRow)
# if x & 1:
# phys_addr += stride - 1 - y
# else:
# phys_addr += y
# return phys_addr
def get_pixel(self, x, y):
"""