Skip to content

Commit

Permalink
support for display availability
Browse files Browse the repository at this point in the history
  • Loading branch information
pintman committed Dec 29, 2023
1 parent d71ac86 commit 1132a69
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fffserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SerialDisplay(displayprovider.DisplayBase):
PXSET = 0b10000011 # Es folgen zwei Bytes X, Y mit Positionsinformationen
PXRESET = 0b10000010 # Es folgen zwei Bytes X, y mit Positionsinformationen
ECHO = 0b11110000 # Das gesendete Byte wird zurückgesendet.
LED_BRIGTHNESS = 0b10000100 # Setzt die Hellifgkeit der Erwartet ein zweites Byte it der Helligkeit
LED_BRIGTHNESS = 0b10000100 # Setzt die Helligkeit der LED. Erwartet ein zweites Byte it der Helligkeit

def __init__(self, width=4, height=3, serial_device="/dev/ttyUSB0", baud=9600, buffered=True):
'''
Expand All @@ -34,6 +34,8 @@ def __init__(self, width=4, height=3, serial_device="/dev/ttyUSB0", baud=9600, b
self.ser = serial.serial_for_url(serial_device, baudrate=baud, timeout=1)
self.buffered = buffered
self.buffer = [False] * (width * height)
if not self.display_available():
print("WARNING: display not available")

def led(self, on_off):
'Turn LED of the display on or off'
Expand Down Expand Up @@ -75,11 +77,19 @@ def show(self):
byte_sequence.append(int(byte, base=2))

self.ser.write(bytes(byte_sequence))

def display_available(self):
test_byte = 42
self.ser.write(bytes([SerialDisplay.ECHO, test_byte]))
bs = self.ser.read(2)
# TODO firmware should not return a string
return len(bs) == 2 and str(bs, encoding="UTF8") == str(test_byte)

def close(self):
'Close the serial device'
self.ser.close()


def demo_simple():
ffd = SerialDisplay(width=28, height=13, serial_device=DEVICE, baud=BAUD, buffered=True)
print("sending pixel")
Expand Down Expand Up @@ -143,6 +153,6 @@ def demo():
ffd.close()

if __name__ == '__main__':
demo()
#demo()
demo_all_onoff()
#demo_simple()

0 comments on commit 1132a69

Please sign in to comment.