From 9a0fef44112169912404d0df979c68f9869bd0c0 Mon Sep 17 00:00:00 2001 From: Romain Bazile Date: Mon, 30 Nov 2020 11:52:27 +0100 Subject: [PATCH] first display use release, show machine name --- scripts/main.py | 3 ++ scripts/planktoscope/display.py | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 scripts/planktoscope/display.py diff --git a/scripts/main.py b/scripts/main.py index ef8ce46..73abb04 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -56,6 +56,9 @@ import planktoscope.light # Import the planktonscope uuidName module import planktoscope.uuidName +# Import the planktonscope display module for the OLED screen +import planktoscope.display + # global variable that keeps the wheels spinning run = True diff --git a/scripts/planktoscope/display.py b/scripts/planktoscope/display.py new file mode 100644 index 0000000..d404df0 --- /dev/null +++ b/scripts/planktoscope/display.py @@ -0,0 +1,79 @@ +# Logger library compatible with multiprocessing +from loguru import logger + +import datetime +import os + +import Adafruit_SSD1306 + +import PIL.Image +import PIL.ImageDraw +import PIL.ImageFont + +logger.info("planktoscope.display is loading") + +import planktoscope.uuidName + +machineName = planktoscope.uuidName.machineName( + machine=planktoscope.uuidName.getSerial() +) + +# Raspberry Pi pin configuration: +RST = None # on the PiOLED this pin isnt used + +# 128x32 display with hardware I2C: +disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST) + +# Initialize library. +disp.begin() + +# Clear display. +disp.clear() +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. +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=13) + +# Draw a black filled box to clear the image. +draw.rectangle((0, 0, width, height), outline=0, fill=0) + +draw.text( + (0, 0), + machineName.replace(" ", "\n"), + font=PIL.ImageFont.truetype(font="truetype/dejavu/DejaVuSansMono.ttf", size=15), + 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. +disp.image(image) +disp.display()