From 61c4534eab2fae6b7a4b715afb80a7ce23afbf86 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Sat, 13 Nov 2021 17:40:49 -0800 Subject: [PATCH] Add support for 64px OLED screen height (#448) * Add support for 64px screen height * Handle case when only one argument is passed * Simplify arg parsing * Update install script to handle screen height selection * Cleanup * Update README * Add blurb on running start.sh standalone * Format * Global constant for LINE_SPACING * Make FONT_SIZE a global constant; improve code comments --- easyinstall.sh | 23 +++++++-- src/oled_monitor/README.md | 34 ++++++++++---- src/oled_monitor/rascsi_oled_monitor.py | 60 +++++++++++++++--------- src/oled_monitor/splash_start.bmp | Bin 574 -> 0 bytes src/oled_monitor/splash_start_32.bmp | Bin 0 -> 574 bytes src/oled_monitor/splash_start_64.bmp | Bin 0 -> 1086 bytes src/oled_monitor/splash_stop.bmp | Bin 574 -> 0 bytes src/oled_monitor/splash_stop_32.bmp | Bin 0 -> 574 bytes src/oled_monitor/splash_stop_64.bmp | Bin 0 -> 1086 bytes src/oled_monitor/start.sh | 12 ++++- 10 files changed, 91 insertions(+), 38 deletions(-) delete mode 100644 src/oled_monitor/splash_start.bmp create mode 100644 src/oled_monitor/splash_start_32.bmp create mode 100644 src/oled_monitor/splash_start_64.bmp delete mode 100644 src/oled_monitor/splash_stop.bmp create mode 100644 src/oled_monitor/splash_stop_32.bmp create mode 100644 src/oled_monitor/splash_stop_64.bmp diff --git a/easyinstall.sh b/easyinstall.sh index c3ba1c2a..9093f4e4 100755 --- a/easyinstall.sh +++ b/easyinstall.sh @@ -134,11 +134,12 @@ function installRaScsiScreen() { echo "IMPORTANT: This configuration requires a OLED screen to be installed onto your RaSCSI board." echo "See wiki for more information: https://github.com/akuker/RASCSI/wiki/OLED-Status-Display-(Optional)" echo "" - echo "Do you want to use the recommended screen rotation (180 degrees)?" - echo "Press Y/n and Enter, or CTRL-C to exit" + echo "Choose screen rotation:" + echo " 1) 0 degrees" + echo " 2) 180 degrees (default)" read REPLY - if [ "$REPLY" == "N" ] || [ "$REPLY" == "n" ]; then + if [ "$REPLY" == "1" ]; then echo "Proceeding with 0 degrees rotation." ROTATION="0" else @@ -146,6 +147,20 @@ function installRaScsiScreen() { ROTATION="180" fi + echo "" + echo "Choose screen resolution:" + echo " 1) 128x32 pixels (default)" + echo " 2) 128x64 pixels" + read REPLY + + if [ "$REPLY" == "2" ]; then + echo "Proceeding with 128x64 pixel resolution." + SCREEN_HEIGHT="64" + else + echo "Proceeding with 128x32 pixel resolution." + SCREEN_HEIGHT="32" + fi + stopRaScsiScreen updateRaScsiGit @@ -171,7 +186,7 @@ function installRaScsiScreen() { echo "Installing the monitor_rascsi.service configuration..." sudo cp -f "$BASE/src/oled_monitor/monitor_rascsi.service" /etc/systemd/system/monitor_rascsi.service sudo sed -i /^ExecStart=/d /etc/systemd/system/monitor_rascsi.service - sudo sed -i "8 i ExecStart=$BASE/src/oled_monitor/start.sh --rotation=$ROTATION" /etc/systemd/system/monitor_rascsi.service + sudo sed -i "8 i ExecStart=$BASE/src/oled_monitor/start.sh --rotation=$ROTATION --height=$SCREEN_HEIGHT" /etc/systemd/system/monitor_rascsi.service sudo systemctl daemon-reload sudo systemctl enable monitor_rascsi diff --git a/src/oled_monitor/README.md b/src/oled_monitor/README.md index e8f467da..a5484902 100644 --- a/src/oled_monitor/README.md +++ b/src/oled_monitor/README.md @@ -14,7 +14,24 @@ $ python3 rascsi_oled_monitor.py ### Parameters -The script takes one positional parameter: '0' or '180' which decides the screen rotation +The script takes two positional parameters: +* '0' or '180' which decides the screen rotation +* '32' or '64' which decides the vertical screen resolution in pixels + +Ex. +``` +$ python3 rascsi_oled_monitor.py 180 64 +``` + +_Note:_ Both parameters must be passed for the script to read them. Ordering is also important. + +## Run the start.sh script standalone + +The start.sh script can also be run standalone, and will handle the venv creation/updating for you. It takes the same command line parameters in the following format: + +``` +$ ./start.sh --rotation=180 --height=64 +``` ## Static analysis with pylint @@ -28,12 +45,11 @@ $ pylint3 python_source_file.py ``` ## Credits -type_writer.ttf - "Type Writer" TrueType font by Mandy Smith - Source: https://www.dafont.com/type-writer.font - Distributed under BSD 3-Clause by permission from author (see LICENSE for full text) +### type_writer.ttf +* _Type Writer_ TrueType font by Mandy Smith +* Source: https://www.dafont.com/type-writer.font +* Distributed under BSD 3-Clause by permission from author (see LICENSE for full text) -splash_start.bmp, splash_stop.bmp - Splash screen bitmap images - Drawn by Daniel Markstedt - Distributed under BSD 3-Clause license +### splash_start_\*.bmp, splash_stop_\*.bmp +* Drawn by Daniel Markstedt +* Distributed under BSD 3-Clause by permission from author (see LICENSE for full text) diff --git a/src/oled_monitor/rascsi_oled_monitor.py b/src/oled_monitor/rascsi_oled_monitor.py index 7f329b78..ce7cf12e 100755 --- a/src/oled_monitor/rascsi_oled_monitor.py +++ b/src/oled_monitor/rascsi_oled_monitor.py @@ -40,8 +40,29 @@ from interrupt_handler import GracefulInterruptHandler from pi_cmds import get_ip_and_host from ractl_cmds import device_list +# Read positional arguments; expecting exactly two, or none +# Arg 1 is the rotation in degrees, arg 2 is the screen height in pixels +# Valid values are 0/180 for ROTATION, 32/64 for HEIGHT +if len(argv) == 3: + if int(argv[1]) == 0: + ROTATION = 0 + else: + # 2 means 180 degrees + ROTATION = 2 + if int(argv[2]) == 64: + HEIGHT = 64 + LINES = 8 + else: + HEIGHT = 32 + LINES = 4 +else: + # Default settings + ROTATION = 2 + HEIGHT = 32 + LINES = 4 + print("No valid parameters detected; defaulting to 32 px height, 180 degrees rotation.") + WIDTH = 128 -HEIGHT = 32 # Change to 64 if needed BORDER = 5 # How long to delay between each update @@ -61,20 +82,6 @@ print(OLED) print() print("Will update the OLED display every " + str(DELAY_TIME_MS) + "ms (approximately)") -# Attempt to read the first argument to the script; fall back to 2 (180 degrees) -if len(argv) > 1: - if str(argv[1]) == "0": - ROTATION = 0 - print("Using 0 degrees screen rotation.") - elif str(argv[1]) == "180": - ROTATION = 2 - print("Using 180 degrees screen rotation.") - else: - exit("Only 0 and 180 are valid arguments for screen rotation.") -else: - print("Defaulting to 180 degrees screen rotation.") - ROTATION = 2 - # Clear display. OLED.rotation = ROTATION OLED.fill(0) @@ -99,11 +106,18 @@ BOTTOM = HEIGHT - PADDING # Move left to right keeping track of the current x position for drawing shapes. X_POS = 0 -# Alternatively load a TTF font. Make sure the .ttf font file -# is in the same directory as the python script! -# When using other fonts, you may need to adjust padding, font size, and line spacing. +# Font size in pixels. Not all TTF fonts have bitmap representations for all sizes. +FONT_SIZE = 8 +# Vertical spacing between each line of text. Adjust in accordance with font size. +# Depending on the design of the font glyphs, this may be larger than FONT_SIZE. +LINE_SPACING = 8 + +# Load a TTF font for rendering glyphs on the screen. +# Make sure the .ttf font file is in the same directory as the python script! +# When using other fonts, you may need to adjust PADDING, FONT_SIZE, +# LINE_SPACING, and LINES. # Some other nice fonts to try: http://www.dafont.com/bitmap.php -FONT = ImageFont.truetype('type_writer.ttf', 8) +FONT = ImageFont.truetype('type_writer.ttf', FONT_SIZE) IP_ADDR, HOSTNAME = get_ip_and_host() @@ -151,7 +165,7 @@ def start_splash(): Displays a splash screen for the startup sequence Make sure the splash bitmap image is in the same dir as this script """ - splash = Image.open("splash_start.bmp").convert("1") + splash = Image.open(f"splash_start_{HEIGHT}.bmp").convert("1") DRAW.bitmap((0, 0), splash) OLED.image(splash) OLED.show() @@ -163,7 +177,7 @@ def stop_splash(): Make sure the splash bitmap image is in the same dir as this script """ DRAW.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0) - splash = Image.open("splash_stop.bmp").convert("1") + splash = Image.open(f"splash_stop_{HEIGHT}.bmp").convert("1") DRAW.bitmap((0, 0), splash) OLED.image(splash) OLED.show() @@ -191,10 +205,10 @@ with GracefulInterruptHandler() as handler: y_pos = TOP for output_line in active_output: DRAW.text((X_POS, y_pos), output_line, font=FONT, fill=255) - y_pos += 8 + y_pos += LINE_SPACING # Shift the index of the array by one to get a scrolling effect - if len(active_output) > 5: + if len(active_output) > LINES: active_output.rotate(-1) # Display image. diff --git a/src/oled_monitor/splash_start.bmp b/src/oled_monitor/splash_start.bmp deleted file mode 100644 index bd7493748530b66373663776ba4e0ef37db9ff8a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 574 zcmZ?rwPRuc13Mt80mKbJtN_G}KnMdu+zbpL3{nbJ{vQNF(ZDJ+fF>P^CcVl5W&xCL zK;xrx>%q3di67MFJJ`uQK0I@d{d4|j1%(eEpYXZ!=IqRwGw+{Ef0mYW?&b-fGk?wl z`Ts%un)5$_d>$ZwhCGO0asDHae+DE!|6KZm4~6G}`p=vJ=?C(kE|eH1mFOE1K)&R}IR+Nyn+<{H u*B?Gm0W@F2z`%U70W;VK1`Lu7l7>b|e0c^wp#4<#9~)Yj{v{MYgyaFr54c1C literal 0 HcmV?d00001 diff --git a/src/oled_monitor/splash_start_64.bmp b/src/oled_monitor/splash_start_64.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4448f28d249507d59f65b35b713bab70e5bee6e3 GIT binary patch literal 1086 zcmZ?rwPRrb13Mt80mKbJ>;S}!KnMdu+zbpL%mfqw;r~DYqE?}SP&9xhy$Ve_bfnAg z2L&V&s7GRBV>SQ-9SN{EAaQ_9iuwBwK9;dbOFkg+L9)M3PR4w*vanHFTAG6449S_3 z4b{vy8#5aK`3xX_vjH2B{~5?ne*ogQ8}I@7#vu6w!x{4YeFi}N#>OE1K)&R}IR+Ny zn+<{H*B?Gm0W@F2z`%U70W;VK1`Lu7l7>b|e0c^wp#4<#9~)Yj{vGM*k5c~w0R2?A AbpQYW literal 0 HcmV?d00001 diff --git a/src/oled_monitor/splash_stop.bmp b/src/oled_monitor/splash_stop.bmp deleted file mode 100644 index 3dde1c7f5ad4c72ea9ebee0149a80b4755fd926e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 574 zcmbu6u@1r@5Qec!2REO<(Xq+D)Wj6y?${?`aid$`rK^wN!*n(2AjC#I5HQ}Ni9fl! zeB8lZ;BagT5!8_1kac8hvIVWA)lvv=zBHCQua;?GV(FHphka@gW5<}I4qdY|KXR%| z@g`qaBzBo+RqrO$vh2kK7<~t}BOn1N&+g5T&gci@S>^hWH`6EEtEw*5Nuo!k>AXEV gJJK)+0~tLlVw$Fm971+^-njEGTlT)ixBue#CsqtU=Kufz diff --git a/src/oled_monitor/splash_stop_32.bmp b/src/oled_monitor/splash_stop_32.bmp new file mode 100644 index 0000000000000000000000000000000000000000..eac18956dd94f72e427ace7fa3d86246dc16991e GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/src/oled_monitor/splash_stop_64.bmp b/src/oled_monitor/splash_stop_64.bmp new file mode 100644 index 0000000000000000000000000000000000000000..511f821476e801c6079c57924510735283ea5119 GIT binary patch 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