mirror of
https://github.com/akuker/RASCSI.git
synced 2024-11-26 13:49:21 +00:00
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
This commit is contained in:
parent
65d0a9b2e6
commit
61c4534eab
@ -134,11 +134,12 @@ function installRaScsiScreen() {
|
|||||||
echo "IMPORTANT: This configuration requires a OLED screen to be installed onto your RaSCSI board."
|
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 "See wiki for more information: https://github.com/akuker/RASCSI/wiki/OLED-Status-Display-(Optional)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Do you want to use the recommended screen rotation (180 degrees)?"
|
echo "Choose screen rotation:"
|
||||||
echo "Press Y/n and Enter, or CTRL-C to exit"
|
echo " 1) 0 degrees"
|
||||||
|
echo " 2) 180 degrees (default)"
|
||||||
read REPLY
|
read REPLY
|
||||||
|
|
||||||
if [ "$REPLY" == "N" ] || [ "$REPLY" == "n" ]; then
|
if [ "$REPLY" == "1" ]; then
|
||||||
echo "Proceeding with 0 degrees rotation."
|
echo "Proceeding with 0 degrees rotation."
|
||||||
ROTATION="0"
|
ROTATION="0"
|
||||||
else
|
else
|
||||||
@ -146,6 +147,20 @@ function installRaScsiScreen() {
|
|||||||
ROTATION="180"
|
ROTATION="180"
|
||||||
fi
|
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
|
stopRaScsiScreen
|
||||||
updateRaScsiGit
|
updateRaScsiGit
|
||||||
|
|
||||||
@ -171,7 +186,7 @@ function installRaScsiScreen() {
|
|||||||
echo "Installing the monitor_rascsi.service configuration..."
|
echo "Installing the monitor_rascsi.service configuration..."
|
||||||
sudo cp -f "$BASE/src/oled_monitor/monitor_rascsi.service" /etc/systemd/system/monitor_rascsi.service
|
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 /^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 daemon-reload
|
||||||
sudo systemctl enable monitor_rascsi
|
sudo systemctl enable monitor_rascsi
|
||||||
|
@ -14,7 +14,24 @@ $ python3 rascsi_oled_monitor.py
|
|||||||
|
|
||||||
### Parameters
|
### 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
|
## Static analysis with pylint
|
||||||
|
|
||||||
@ -28,12 +45,11 @@ $ pylint3 python_source_file.py
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
type_writer.ttf
|
### type_writer.ttf
|
||||||
"Type Writer" TrueType font by Mandy Smith
|
* _Type Writer_ TrueType font by Mandy Smith
|
||||||
Source: https://www.dafont.com/type-writer.font
|
* Source: https://www.dafont.com/type-writer.font
|
||||||
Distributed under BSD 3-Clause by permission from author (see LICENSE for full text)
|
* Distributed under BSD 3-Clause by permission from author (see LICENSE for full text)
|
||||||
|
|
||||||
splash_start.bmp, splash_stop.bmp
|
### splash_start_\*.bmp, splash_stop_\*.bmp
|
||||||
Splash screen bitmap images
|
* Drawn by Daniel Markstedt
|
||||||
Drawn by Daniel Markstedt
|
* Distributed under BSD 3-Clause by permission from author (see LICENSE for full text)
|
||||||
Distributed under BSD 3-Clause license
|
|
||||||
|
@ -40,8 +40,29 @@ from interrupt_handler import GracefulInterruptHandler
|
|||||||
from pi_cmds import get_ip_and_host
|
from pi_cmds import get_ip_and_host
|
||||||
from ractl_cmds import device_list
|
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
|
WIDTH = 128
|
||||||
HEIGHT = 32 # Change to 64 if needed
|
|
||||||
BORDER = 5
|
BORDER = 5
|
||||||
|
|
||||||
# How long to delay between each update
|
# How long to delay between each update
|
||||||
@ -61,20 +82,6 @@ print(OLED)
|
|||||||
print()
|
print()
|
||||||
print("Will update the OLED display every " + str(DELAY_TIME_MS) + "ms (approximately)")
|
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.
|
# Clear display.
|
||||||
OLED.rotation = ROTATION
|
OLED.rotation = ROTATION
|
||||||
OLED.fill(0)
|
OLED.fill(0)
|
||||||
@ -99,11 +106,18 @@ BOTTOM = HEIGHT - PADDING
|
|||||||
# Move left to right keeping track of the current x position for drawing shapes.
|
# Move left to right keeping track of the current x position for drawing shapes.
|
||||||
X_POS = 0
|
X_POS = 0
|
||||||
|
|
||||||
# Alternatively load a TTF font. Make sure the .ttf font file
|
# Font size in pixels. Not all TTF fonts have bitmap representations for all sizes.
|
||||||
# is in the same directory as the python script!
|
FONT_SIZE = 8
|
||||||
# When using other fonts, you may need to adjust padding, font size, and line spacing.
|
# 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
|
# 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()
|
IP_ADDR, HOSTNAME = get_ip_and_host()
|
||||||
|
|
||||||
@ -151,7 +165,7 @@ def start_splash():
|
|||||||
Displays a splash screen for the startup sequence
|
Displays a splash screen for the startup sequence
|
||||||
Make sure the splash bitmap image is in the same dir as this script
|
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)
|
DRAW.bitmap((0, 0), splash)
|
||||||
OLED.image(splash)
|
OLED.image(splash)
|
||||||
OLED.show()
|
OLED.show()
|
||||||
@ -163,7 +177,7 @@ def stop_splash():
|
|||||||
Make sure the splash bitmap image is in the same dir as this script
|
Make sure the splash bitmap image is in the same dir as this script
|
||||||
"""
|
"""
|
||||||
DRAW.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)
|
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)
|
DRAW.bitmap((0, 0), splash)
|
||||||
OLED.image(splash)
|
OLED.image(splash)
|
||||||
OLED.show()
|
OLED.show()
|
||||||
@ -191,10 +205,10 @@ with GracefulInterruptHandler() as handler:
|
|||||||
y_pos = TOP
|
y_pos = TOP
|
||||||
for output_line in active_output:
|
for output_line in active_output:
|
||||||
DRAW.text((X_POS, y_pos), output_line, font=FONT, fill=255)
|
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
|
# 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)
|
active_output.rotate(-1)
|
||||||
|
|
||||||
# Display image.
|
# Display image.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 574 B |
BIN
src/oled_monitor/splash_start_32.bmp
Normal file
BIN
src/oled_monitor/splash_start_32.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 574 B |
BIN
src/oled_monitor/splash_start_64.bmp
Normal file
BIN
src/oled_monitor/splash_start_64.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 574 B |
BIN
src/oled_monitor/splash_stop_32.bmp
Normal file
BIN
src/oled_monitor/splash_stop_32.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 574 B |
BIN
src/oled_monitor/splash_stop_64.bmp
Normal file
BIN
src/oled_monitor/splash_stop_64.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
@ -89,13 +89,16 @@ while [ "$1" != "" ]; do
|
|||||||
-r | --rotation)
|
-r | --rotation)
|
||||||
ROTATION=$VALUE
|
ROTATION=$VALUE
|
||||||
;;
|
;;
|
||||||
|
-h | --height)
|
||||||
|
HEIGHT=$VALUE
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ERROR: unknown parameter \"$PARAM\""
|
echo "ERROR: unknown parameter \"$PARAM\""
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
case $VALUE in
|
case $VALUE in
|
||||||
0 | 180 )
|
0 | 180 | 32 | 64 )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ERROR: invalid option \"$VALUE\""
|
echo "ERROR: invalid option \"$VALUE\""
|
||||||
@ -111,4 +114,9 @@ if [ -z ${ROTATION+x} ]; then
|
|||||||
else
|
else
|
||||||
echo "Screen rotation set to $ROTATION degrees."
|
echo "Screen rotation set to $ROTATION degrees."
|
||||||
fi
|
fi
|
||||||
python3 rascsi_oled_monitor.py ${ROTATION}
|
if [ -z ${HEIGHT+x} ]; then
|
||||||
|
echo "No screen height parameter given; falling back to the default."
|
||||||
|
else
|
||||||
|
echo "Screen height set to $HEIGHT px."
|
||||||
|
fi
|
||||||
|
python3 rascsi_oled_monitor.py ${ROTATION} ${HEIGHT}
|
||||||
|
Loading…
Reference in New Issue
Block a user