adsl-bouncer/lcd.py

40 lines
874 B
Python

import serial
class LCDScreen(object):
def _command(self, command):
self.serial.write("\xFE" + chr(command))
self.serial.flush()
def clear(self):
self._command(1)
def home(self):
self._command(2)
def blank(self):
self._command(8)
def unblank(self):
self._command(12)
def location(self, x, y):
self._command(128 + 0x40*y + x)
def text(self, text):
sanitized = "".join(c for c in text if c.lower() in "1234567890abcdefghjiklmnopqrstuvwxyz{}[]/+-_. ")
self.serial.write(sanitized)
self.serial.flush()
def text_at(self, x, y, text):
self.location(x, y)
self.text(text)
def __init__(self):
self.serial = serial.Serial("/dev/ttyS1", 2400)
self.clear()
self.home()
def close(self):
self.serial.close()