Skip to content
Snippets Groups Projects
Commit e2e9608c authored by Martin Winter's avatar Martin Winter
Browse files

specify get, set and blit function to correct the x-y-coordinates

parent 161ae796
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,15 @@ class TM1640Matrix(LEDMatrix): ...@@ -49,7 +49,15 @@ class TM1640Matrix(LEDMatrix):
self.intensity = max(0, min(7, intensity)) self.intensity = max(0, min(7, intensity))
self.active = active self.active = active
self._send_command(0x80 | self.intensity | (0x08 if self.active else 0)) self._send_command(0x80 | self.intensity | (0x08 if self.active else 0))
def get(self, i: int, j: int) -> bool:
"""Get state of one pixel."""
return self.fb[7-i][7-j]
def set(self, i: int, j: int, state: bool):
"""Set state of one pixel."""
self.fb[i][7-j] = state
def update(self): def update(self):
data = self._to_bytes() data = self._to_bytes()
...@@ -62,7 +70,8 @@ class TM1640Matrix(LEDMatrix): ...@@ -62,7 +70,8 @@ class TM1640Matrix(LEDMatrix):
def _to_bytes(self) -> bytes: def _to_bytes(self) -> bytes:
data = b"" data = b""
for row in range(self.rows - 1, -1, -1): #for row in range(self.rows - 1, -1, -1):
for row in range(self.rows):
byte = 0 byte = 0
for col in range(0, self.cols): for col in range(0, self.cols):
byte |= int(self.fb[row][col]) << (self.cols - col - 1) byte |= int(self.fb[row][col]) << (self.cols - col - 1)
...@@ -93,6 +102,22 @@ class TM1640Matrix(LEDMatrix): ...@@ -93,6 +102,22 @@ class TM1640Matrix(LEDMatrix):
self._send(0xCB | address) self._send(0xCB | address)
self._send(byte) self._send(byte)
self._send_end() self._send_end()
def blit(
self,
source: list[list[int | bool]],
source_offset: tuple[int, int] = (0, 0),
dest_offset: tuple[int, int] = (0, 0),
):
"""Copy (part of) a source bitmap to the framebuffer."""
dest_width = self.cols - dest_offset[1]
dest_height = self.rows - dest_offset[0]
source_width = dest_width - source_offset[1]
source_height = dest_height - source_offset[0]
for row in range(source_offset[0], source_height + source_offset[0]):
for col in range(source_offset[1], source_width + source_offset[1]):
self.set(self.rows - (row + dest_offset[0])-1, col + dest_offset[1], bool(source[row][col]))
class WEMOSMatrixLEDShield(TM1640Matrix): class WEMOSMatrixLEDShield(TM1640Matrix):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment