Skip to content

Commit 6ecb9e6

Browse files
committed
led-matrix: Make sure it's sorted properly
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 067a43f commit 6ecb9e6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

led-matrix.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# (0x1e, 0), // x:2, y:1, sw:2, cs:1, id:2
88
# [...]
99

10+
import math
1011
from dataclasses import dataclass
1112

1213
WIDTH = 9
@@ -36,6 +37,12 @@ def led_register(self):
3637
register = 0x5A + self.cs - 31 + (self.sw-1) * 9
3738
return (register, page)
3839

40+
def __lt__(self, other):
41+
if self.y == other.y:
42+
return self.x < other.x
43+
else:
44+
return self.y < other.y
45+
3946

4047
def get_leds():
4148
leds = []
@@ -91,6 +98,9 @@ def main():
9198
# Assumes that the index in the LEDs list is: index = x + y * 9
9299
leds = get_leds()
93100

101+
# Needs to be sorted according to x and y
102+
leds.sort()
103+
94104
debug = False
95105

96106
for led in leds:

0 commit comments

Comments
 (0)