From 5f39afc5d1e652ed80091ba579fae7441ab8f07f Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 28 Dec 2021 12:10:42 -0800 Subject: [PATCH] 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 --- src/oled_monitor/rascsi_oled_monitor.py | 56 +++++++----------------- src/oled_monitor/splash_stop_32.bmp | Bin 574 -> 0 bytes src/oled_monitor/splash_stop_64.bmp | Bin 1086 -> 0 bytes 3 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 src/oled_monitor/splash_stop_32.bmp delete mode 100644 src/oled_monitor/splash_stop_64.bmp diff --git a/src/oled_monitor/rascsi_oled_monitor.py b/src/oled_monitor/rascsi_oled_monitor.py index 0d1dfaf0..32b290e3 100755 --- a/src/oled_monitor/rascsi_oled_monitor.py +++ b/src/oled_monitor/rascsi_oled_monitor.py @@ -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...") diff --git a/src/oled_monitor/splash_stop_32.bmp b/src/oled_monitor/splash_stop_32.bmp deleted file mode 100644 index eac18956dd94f72e427ace7fa3d86246dc16991e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 574 zcmb7>y$ZrG6opeOiC{o*>gec0ln%~1_FcM}%_UFLmoOmMNara3mMXe5l28#) z`iuR%k1O-q=a~i0b$65K%+QPy5NZkB3%~%-mf4$O=)NrBT!;0pF61Zkjqc0-V$h&h lw4WatFQ^%~hJ?yBF?BOc>_QkqzthaW%#$~L%>AFa`V+0!(Gvgw diff --git a/src/oled_monitor/splash_stop_64.bmp b/src/oled_monitor/splash_stop_64.bmp deleted file mode 100644 index 511f821476e801c6079c57924510735283ea5119..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1086 zcmZ?rwPRrb13Mt80mKbJ>;S}!KnMdu+zbpL%mfqw;r~DYqE?}SP&9xhy$Ve_bfnAg z2L&V&s7GRBV>SQ-9SN{EAaQ_9Tzr@~jOI81(Ffx*!1>HQ#}D(IIey?r#ebeNXV@E9 z&YU?Wapuf{GiT29fcOju{+R