display: detect display availability
(cherry picked from commit 922b47ca8fdd495b8b2835e9ab5b6430982e1735)
This commit is contained in:
parent
a23820e28d
commit
328d227b8f
|
@ -16,20 +16,25 @@ import planktoscope.uuidName
|
|||
|
||||
|
||||
class Display(object):
|
||||
display_available = True
|
||||
|
||||
def __init__(self):
|
||||
# Raspberry Pi pin configuration:
|
||||
RST = None # on the PiOLED this pin isnt used
|
||||
|
||||
try:
|
||||
# 128x32 display with hardware I2C:
|
||||
self.__disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
|
||||
|
||||
# Initialize library.
|
||||
self.__disp.begin()
|
||||
|
||||
self.display_machine_name()
|
||||
logger.success("planktoscope.display is ready!")
|
||||
except Exception as e:
|
||||
logger.error("Could not detect the display")
|
||||
self.display_available = False
|
||||
|
||||
def display_machine_name(self):
|
||||
if self.display_available:
|
||||
self.__clear()
|
||||
machineName = planktoscope.uuidName.machineName(
|
||||
machine=planktoscope.uuidName.getSerial()
|
||||
|
@ -37,6 +42,7 @@ class Display(object):
|
|||
self.display_text(machineName.replace(" ", "\n"))
|
||||
|
||||
def display_text(self, message):
|
||||
if self.display_available:
|
||||
text = message.replace("\n", " ")
|
||||
logger.info(f"Displaying message {text}")
|
||||
|
||||
|
@ -93,12 +99,14 @@ class Display(object):
|
|||
self.__disp.display()
|
||||
|
||||
def __clear(self):
|
||||
if self.display_available:
|
||||
logger.trace("Clear the display")
|
||||
# Clear display.
|
||||
self.__disp.clear()
|
||||
self.__disp.display()
|
||||
|
||||
def stop(self):
|
||||
if self.display_available:
|
||||
logger.info("Display is out!")
|
||||
self.display_text("Cut the power\nin 5s")
|
||||
|
||||
|
|
Loading…
Reference in a new issue