display: module rewrite
This commit is contained in:
parent
d9550c777b
commit
7f2d4ca430
|
@ -56,6 +56,9 @@ import planktoscope.light
|
||||||
# Import the planktonscope uuidName module
|
# Import the planktonscope uuidName module
|
||||||
import planktoscope.uuidName
|
import planktoscope.uuidName
|
||||||
|
|
||||||
|
# Import the planktonscope display module for the OLED screen
|
||||||
|
import planktoscope.display
|
||||||
|
|
||||||
# global variable that keeps the wheels spinning
|
# global variable that keeps the wheels spinning
|
||||||
run = True
|
run = True
|
||||||
|
|
||||||
|
@ -126,12 +129,12 @@ if __name__ == "__main__":
|
||||||
segmenter_thread = planktoscope.segmenter.SegmenterProcess(shutdown_event)
|
segmenter_thread = planktoscope.segmenter.SegmenterProcess(shutdown_event)
|
||||||
segmenter_thread.start()
|
segmenter_thread.start()
|
||||||
|
|
||||||
|
logger.info("Starting the display module")
|
||||||
|
display = planktoscope.display.Display()
|
||||||
|
|
||||||
logger.success("Looks like everything is set up and running, have fun!")
|
logger.success("Looks like everything is set up and running, have fun!")
|
||||||
planktoscope.light.ready()
|
planktoscope.light.ready()
|
||||||
|
|
||||||
# Import the planktonscope display module for the OLED screen
|
|
||||||
import planktoscope.display
|
|
||||||
|
|
||||||
while run:
|
while run:
|
||||||
# TODO look into ways of restarting the dead threads
|
# TODO look into ways of restarting the dead threads
|
||||||
logger.trace("Running around in circles while waiting for someone to die!")
|
logger.trace("Running around in circles while waiting for someone to die!")
|
||||||
|
@ -145,14 +148,15 @@ if __name__ == "__main__":
|
||||||
logger.error("The segmenter process died unexpectedly! Oh no!")
|
logger.error("The segmenter process died unexpectedly! Oh no!")
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
display.display_text("Bye Bye!")
|
||||||
logger.info("Shutting down the shop")
|
logger.info("Shutting down the shop")
|
||||||
shutdown_event.set()
|
shutdown_event.set()
|
||||||
time.sleep(0.5)
|
time.sleep(1)
|
||||||
stepper_thread.join()
|
stepper_thread.join()
|
||||||
imager_thread.join()
|
imager_thread.join()
|
||||||
segmenter_thread.join()
|
segmenter_thread.join()
|
||||||
stepper_thread.close()
|
stepper_thread.close()
|
||||||
imager_thread.close()
|
imager_thread.close()
|
||||||
segmenter_thread.close()
|
segmenter_thread.close()
|
||||||
|
display.stop()
|
||||||
logger.info("Bye")
|
logger.info("Bye")
|
|
@ -14,65 +14,101 @@ logger.info("planktoscope.display is loading")
|
||||||
|
|
||||||
import planktoscope.uuidName
|
import planktoscope.uuidName
|
||||||
|
|
||||||
machineName = planktoscope.uuidName.machineName(
|
|
||||||
machine=planktoscope.uuidName.getSerial()
|
|
||||||
)
|
|
||||||
|
|
||||||
# Raspberry Pi pin configuration:
|
class Display(object):
|
||||||
RST = None # on the PiOLED this pin isnt used
|
def __init__(self):
|
||||||
|
# Raspberry Pi pin configuration:
|
||||||
|
RST = None # on the PiOLED this pin isnt used
|
||||||
|
|
||||||
# 128x32 display with hardware I2C:
|
# 128x32 display with hardware I2C:
|
||||||
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
|
self.__disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
|
||||||
|
|
||||||
# Initialize library.
|
# Initialize library.
|
||||||
disp.begin()
|
self.__disp.begin()
|
||||||
|
|
||||||
# Clear display.
|
self.display_machine_name()
|
||||||
disp.clear()
|
logger.success("planktoscope.display is ready!")
|
||||||
disp.display()
|
|
||||||
# Create blank image for drawing.
|
|
||||||
# Make sure to create image with mode '1' for 1-bit color.
|
|
||||||
width = disp.width
|
|
||||||
height = disp.height
|
|
||||||
image = PIL.Image.new("1", (width, height))
|
|
||||||
|
|
||||||
# Get drawing object to draw on image.
|
def display_machine_name(self):
|
||||||
draw = PIL.ImageDraw.Draw(image)
|
self.__clear()
|
||||||
|
machineName = planktoscope.uuidName.machineName(
|
||||||
|
machine=planktoscope.uuidName.getSerial()
|
||||||
|
)
|
||||||
|
self.display_text(machineName.replace(" ", "\n"))
|
||||||
|
|
||||||
# Draw a black filled box to clear the image.
|
def display_text(self, message):
|
||||||
draw.rectangle((0, 0, width, height), outline=0, fill=0)
|
logger.info(f"Displaying message {message}")
|
||||||
|
|
||||||
# Draw some shapes.
|
# Clear display.
|
||||||
# First define some constants to allow easy resizing of shapes.
|
self.__clear()
|
||||||
padding = -2
|
width = self.__disp.width
|
||||||
top = padding
|
height = self.__disp.height
|
||||||
bottom = height - padding
|
|
||||||
# Move left to right keeping track of the current x position for drawing shapes.
|
|
||||||
x = 0
|
|
||||||
|
|
||||||
# Load default font.
|
# Create blank image for drawing.
|
||||||
font = PIL.ImageFont.truetype(font="truetype/dejavu/DejaVuSansMono.ttf", size=15)
|
# Make sure to create image with mode '1' for 1-bit color.
|
||||||
|
|
||||||
# Draw a black filled box to clear the image.
|
image = PIL.Image.new("1", (width, height))
|
||||||
draw.rectangle((0, 0, width, height), outline=0, fill=0)
|
|
||||||
|
# Get drawing object to draw on image.
|
||||||
|
draw = PIL.ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
# Draw a black filled box to clear the image.
|
||||||
|
draw.rectangle((0, 0, width, height), outline=0, fill=0)
|
||||||
|
|
||||||
|
# Draw some shapes.
|
||||||
|
# First define some constants to allow easy resizing of shapes.
|
||||||
|
padding = -2
|
||||||
|
top = padding
|
||||||
|
bottom = height - padding
|
||||||
|
# Move left to right keeping track of the current x position for drawing shapes.
|
||||||
|
x = 0
|
||||||
|
|
||||||
|
# Load default font.
|
||||||
|
font = PIL.ImageFont.truetype(
|
||||||
|
font="truetype/dejavu/DejaVuSansMono.ttf", size=15
|
||||||
|
)
|
||||||
|
|
||||||
|
# Draw a black filled box to clear the image.
|
||||||
|
draw.rectangle((0, 0, width, height), outline=0, fill=0)
|
||||||
|
|
||||||
|
text_size = font.getsize_multiline(message)
|
||||||
|
x = width / 2 - text_size[0] / 2
|
||||||
|
|
||||||
|
draw.text((x, 0), message, font=font, fill=255, align="center")
|
||||||
|
|
||||||
|
# draw.text((0, top + 15), "READY", font=font, fill=255)
|
||||||
|
# now = datetime.datetime.isoformat(datetime.datetime.now())[:-16]
|
||||||
|
# draw.text(
|
||||||
|
# (68, 0),
|
||||||
|
# now,
|
||||||
|
# font=PIL.ImageFont.truetype(font="truetype/dejavu/DejaVuSansMono.ttf", size=10),
|
||||||
|
# fill=255,
|
||||||
|
# )
|
||||||
|
# draw.text((x, top + 16), str(Disk), font=font, fill=255)
|
||||||
|
# draw.text((x, top + 24), "wlan0:" + str(IP), font=font, fill=255)
|
||||||
|
|
||||||
|
# Display image.
|
||||||
|
self.__disp.image(image)
|
||||||
|
self.__disp.display()
|
||||||
|
|
||||||
|
def __clear(self):
|
||||||
|
logger.trace("Clear the display")
|
||||||
|
# Clear display.
|
||||||
|
self.__disp.clear()
|
||||||
|
self.__disp.display()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
logger.info("Display is out!")
|
||||||
|
self.__clear()
|
||||||
|
|
||||||
|
|
||||||
text_size = font.getsize_multiline(machineName.replace(" ", "\n"))
|
if __name__ == "__main__":
|
||||||
x = width / 2 - text_size[0] / 2
|
import time
|
||||||
|
|
||||||
draw.text((x, 0), machineName.replace(" ", "\n"), font=font, fill=255, align="center")
|
display = Display()
|
||||||
|
time.sleep(5)
|
||||||
# draw.text((0, top + 15), "READY", font=font, fill=255)
|
display.display_text("Nice hat you have")
|
||||||
# now = datetime.datetime.isoformat(datetime.datetime.now())[:-16]
|
time.sleep(5)
|
||||||
# draw.text(
|
display.display_text("Bye!")
|
||||||
# (68, 0),
|
time.sleep(5)
|
||||||
# now,
|
display.stop()
|
||||||
# font=PIL.ImageFont.truetype(font="truetype/dejavu/DejaVuSansMono.ttf", size=10),
|
|
||||||
# fill=255,
|
|
||||||
# )
|
|
||||||
# draw.text((x, top + 16), str(Disk), font=font, fill=255)
|
|
||||||
# draw.text((x, top + 24), "wlan0:" + str(IP), font=font, fill=255)
|
|
||||||
|
|
||||||
# Display image.
|
|
||||||
disp.image(image)
|
|
||||||
disp.display()
|
|
Loading…
Reference in a new issue