Merge Python Branch into Main #1
|
@ -55,4 +55,5 @@ commands =
|
||||||
max_line_length = 88
|
max_line_length = 88
|
||||||
|
|
||||||
[mypy]
|
[mypy]
|
||||||
|
check_untyped_defs = True
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
|
@ -4,3 +4,4 @@ from blunderboard.boardreader import BoardReader
|
||||||
def main():
|
def main():
|
||||||
reader = BoardReader()
|
reader = BoardReader()
|
||||||
reader.scan()
|
reader.scan()
|
||||||
|
reader.print()
|
||||||
|
|
|
@ -17,24 +17,33 @@ class BoardReader:
|
||||||
gpio.setup(rows, gpio.OUT, initial=gpio.LOW)
|
gpio.setup(rows, gpio.OUT, initial=gpio.LOW)
|
||||||
self.columns = columns
|
self.columns = columns
|
||||||
self.rows = rows
|
self.rows = rows
|
||||||
|
self.board: list[list[str]] = []
|
||||||
|
for i in range(8):
|
||||||
|
self.board.append([" "] * 8)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
gpio.cleanup()
|
gpio.cleanup()
|
||||||
|
|
||||||
def scan(self) -> None:
|
def scan(self) -> None:
|
||||||
print(" a b c d e f g h")
|
|
||||||
print(" +---------------+")
|
|
||||||
for i, row in enumerate(self.rows):
|
for i, row in enumerate(self.rows):
|
||||||
print("%d|" % (i + 1), end="")
|
|
||||||
gpio.output(row, gpio.HIGH)
|
gpio.output(row, gpio.HIGH)
|
||||||
for j, column in enumerate(self.columns):
|
for j, column in enumerate(self.columns):
|
||||||
if gpio.input(column):
|
if gpio.input(column):
|
||||||
print("x", end="")
|
self.board[i][j] = "x"
|
||||||
else:
|
else:
|
||||||
print(" ", end="")
|
self.board[i][j] = " "
|
||||||
if j == 7:
|
|
||||||
print("|", end="")
|
|
||||||
else:
|
|
||||||
print(" ", end="")
|
|
||||||
gpio.output(row, gpio.LOW)
|
gpio.output(row, gpio.LOW)
|
||||||
print("")
|
|
||||||
|
def print(self) -> None:
|
||||||
|
print(" a b c d e f g h")
|
||||||
|
print(" +---------------+")
|
||||||
|
for i, row in reversed(list(enumerate(self.board))):
|
||||||
|
print("%d|" % (i + 1), end="")
|
||||||
|
for j, field in enumerate(row):
|
||||||
|
print(field, end="")
|
||||||
|
if j == 7:
|
||||||
|
print("|%d" % (i + 1))
|
||||||
|
else:
|
||||||
|
print(" ", end="")
|
||||||
|
print(" +---------------+")
|
||||||
|
print(" a b c d e f g h")
|
||||||
|
|
Loading…
Reference in a new issue