This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/compLib/Display.py
2021-08-22 18:37:20 +02:00

39 lines
1.1 KiB
Python

import string
from compLib.LogstashLogging import logstash_logger
from compLib.Spi import Spi, Register
LINE_COUNT = 4
CHARS_PER_LINE = 16
class Display(object):
"""Access the different IR Sensors of the robot
"""
@staticmethod
def write(line: int, text: string):
if len(text) > CHARS_PER_LINE:
logstash_logger.error(f"Too many characters specified!")
return
if line <= 0 or line > LINE_COUNT:
raise IndexError("Invalid line number specified")
to_write = [0] * CHARS_PER_LINE
for i in range(len(text)):
to_write[i] = ord(text[i])
if line == 1:
Spi.write(Register.DISPLAY_LINE_1_C0, CHARS_PER_LINE, to_write)
elif line == 2:
Spi.write(Register.DISPLAY_LINE_2_C0, CHARS_PER_LINE, to_write)
elif line == 3:
Spi.write(Register.DISPLAY_LINE_3_C0, CHARS_PER_LINE, to_write)
elif line == 4:
Spi.write(Register.DISPLAY_LINE_4_C0, CHARS_PER_LINE, to_write)
@staticmethod
def clear():
for i in range(1, LINE_COUNT + 1):
Display.write(i, "")