Add IR, encoder, motor, display
This commit is contained in:
parent
530ddd8be7
commit
63b8f868c9
6 changed files with 248 additions and 247 deletions
39
compLib/Display.py
Normal file
39
compLib/Display.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
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, "")
|
Reference in a new issue