Optimized oled script startup and shutdown (#573)

* Optimize the oled script for quicker startup. Blank the screen instead of showing a splash.

* Remove shutdown splash bitmap images

* Cleanup

* Resolve pylint warnings
This commit is contained in:
Daniel Markstedt 2021-12-28 12:10:42 -08:00 committed by GitHub
parent fecdc44629
commit 5f39afc5d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 39 deletions

View File

@ -31,8 +31,8 @@
THE SOFTWARE.
"""
import argparse
import sys
from time import sleep
from sys import argv
from collections import deque
from board import I2C
from adafruit_ssd1306 import SSD1306_I2C
@ -95,20 +95,22 @@ I2C = I2C()
# 128x32 display with hardware I2C:
OLED = SSD1306_I2C(WIDTH, HEIGHT, I2C, addr=0x3C, reset=OLED_RESET)
OLED.rotation = ROTATION
print("Running with the following display:")
print(OLED)
print()
print("Will update the OLED display every " + str(DELAY_TIME_MS) + "ms (approximately)")
# Clear display.
OLED.rotation = ROTATION
OLED.fill(0)
# Show a startup splash bitmap image before starting the main loop
# Convert the image to mode '1' for 1-bit color (monochrome)
# Make sure the splash bitmap image is in the same dir as this script
IMAGE = Image.open(f"splash_start_{HEIGHT}.bmp").convert("1")
OLED.image(IMAGE)
OLED.show()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
IMAGE = Image.new("1", (OLED.width, OLED.height))
# Keep the pretty splash on screen for a number of seconds
sleep(4)
# Get drawing object to draw on image.
DRAW = ImageDraw.Draw(IMAGE)
@ -138,11 +140,6 @@ LINE_SPACING = 8
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
FONT = ImageFont.truetype('type_writer.ttf', FONT_SIZE)
# Load a bitmap image for start and stop splash screens and convert to monocrome
# Make sure the splash bitmap image is in the same dir as this script
SPLASH_START = Image.open(f"splash_start_{HEIGHT}.bmp").convert("1")
SPLASH_STOP = Image.open(f"splash_stop_{HEIGHT}.bmp").convert("1")
IP_ADDR, HOSTNAME = get_ip_and_host()
@ -190,28 +187,7 @@ def formatted_output():
return output
def start_splash():
"""
Displays a splash screen for the startup sequence
"""
OLED.image(SPLASH_START)
OLED.show()
sleep(4)
def stop_splash():
"""
Displays a splash screen for the shutdown sequence
"""
OLED.image(SPLASH_STOP)
OLED.show()
# Show a startup splash bitmap image before starting the main loop
start_splash()
with GracefulInterruptHandler() as handler:
"""
The main loop of displaying attached device info, and other info
"""
while True:
# The reference snapshot of attached devices that will be compared against each cycle
@ -225,10 +201,10 @@ with GracefulInterruptHandler() as handler:
while snapshot == ref_snapshot:
# Draw a black filled box to clear the image.
DRAW.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)
y_pos = TOP
Y_POS = TOP
for output_line in active_output:
DRAW.text((X_POS, y_pos), output_line, font=FONT, fill=255)
y_pos += LINE_SPACING
DRAW.text((X_POS, Y_POS), output_line, font=FONT, fill=255)
Y_POS += LINE_SPACING
# Shift the index of the array by one to get a scrolling effect
if len(active_output) > LINES:
@ -242,6 +218,8 @@ with GracefulInterruptHandler() as handler:
snapshot = formatted_output()
if handler.interrupted:
# Catch interrupt signals and show a shutdown splash bitmap image
stop_splash()
exit("Shutting down the OLED display...")
# Catch interrupt signals and blank out the screen
DRAW.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)
OLED.image(IMAGE)
OLED.show()
sys.exit("Shutting down the OLED display...")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 574 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB