mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-07 13:53:33 +00:00
ea3bb8363a
commit94786aec54
Author: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue Dec 21 08:43:21 2021 +0100 Added support for operation meta data, code cleanup (#534) * Added messages * Comment update * Interface update * Support for localized descriptions * Sort operations * Completed meta data * rasctl -s returns operation meta data * Manpage update * Type update * Comment update * Description updates * Comment update * Added convenience method * Added convenience method * Code cleanup * Comment update * Display permitted values * For completeness sake added permitted boolean values * Added support for default value * Removed redundant message field * Description update * Description upddate * Squashed commit of the following: commit 8171c6ea27982c736c30c0db69a7fdde07ee10ce Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:43:14 2021 +0100 The data type is implicit commit fb01dc9d82e8ff7456b05a0cb9d08069adacc64c Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:37:49 2021 +0100 Renaming commit 057dbf1aca7be3f7e76a5ff89a582a276b6d3089 Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:29:54 2021 +0100 Comment update commit 5f699aad2f835f72accdb445d1e59f094aeb108f Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:24:25 2021 +0100 Signature update commit cbcf8b09f9d1ba7b82f816269bcfe91d9f00eb6e Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:22:45 2021 +0100 Signature update commit a8148ef802ca809e5a305d2caa69856c9033d932 Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:16:46 2021 +0100 Comment update commit ce685a92d4827e131d80d10ecd56e2b3baf173f8 Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 12:15:46 2021 +0100 Use map instead of list commit 454c0438f3589904f5dbe5253963dd200ea416dd Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 10:47:36 2021 +0100 Updated size check commit b386dbba4b0262f4f6f02aecb2a1daeffd41f4a2 Author: Uwe Seimet <Uwe.Seimet@seimet.de> Date: Sat Dec 18 01:23:43 2021 +0100 Initial improvements * Default value update * Comment update * Comment update * Map operations by ordinal * Added safeguard against unknown operations * Added cast * Data type update * Sort map by operation name * Renaming * Code cleanup * Comment update * Renaming * Comment update * Description updates * Fixed typo * Added operation * Logging update * Interface comment update * Fixed typo * Aded operation parameters * Updated handling of mandatory parameters * Updated assertion handling * Added missing condition * Removed duplicate cod3 * Code cleanup * Logging update * Removed duplicate code * Code cleanup * Squashed commit of the following: commit4ae273ccbd
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 22:30:22 2021 -0600 Loopback tester pcb (#545) commit46c5c1966f
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 22:29:59 2021 -0600 RaSCSI Zero version 1.0 (#546) commitd09df31d67
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 20:25:23 2021 -0800 Remove redundant code from OLED script (#547) commitd8828da690
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 21:02:50 2021 -0600 Added list of sponsors commitbcd7e8396d
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:51:45 2021 -0800 Second attempt at properly creating the manpage dir (#542) commitc887edfc8c
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:50:03 2021 -0800 Remove special elevated privileges for the Web Interface (#536) * Use the pi_shutdown method to restart the rascsi service * Use the pi_shutdown method to restart the rascsi service * Remove modifications to sudoers no longer needed * Introduce sleeps attempting to connect to socket; reduce overall number of retries * Remove systemd helped methods and the functionality that depends on it * Attempts to speed up splash code * Remove unneccessary verbosity * Attempt to optimize service definition commit801aebfb96
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:47:22 2021 -0800 More readable message when downloading a file (#531) commit29cf58288f
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:47:03 2021 -0800 Add a warning notice when ejecting removable media (#526) commit7efa895239
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:46:22 2021 -0800 Unzip zipfiles before storing to iso (#525) * Unzip zipfiles before storing to iso * Add helptext * Skip unzip for MacZip format * Should not be an fstring commit39bc485671
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:28:22 2021 -0800 Add pip3 to global dependencies; remove duplicates from monitor_rascs… (#523) * Add pip3 to global dependencies; remove duplicates from monitor_rascsi dependencies * Cleanup * Shutdown functionality is only available if started with root permissions * Only restrict shutdown parameters, not everything if not root * Updated operation count check commit693ade2967
Author: Daniel Markstedt <markstedt@gmail.com> Date: Mon Dec 20 12:04:23 2021 -0800 Bump Macproxy version to 21.12.2 (#550) commit958fb95908
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Mon Dec 20 12:50:14 2021 -0600 Adjust bus settle delay to match SCSI standard (#544) * Move the GCC v10 compiler flags into makefile instead of easyinstall.sh * #504 - Update the bus settle time to match the SCSI standard Co-authored-by: RaSCSI User <user@rascsi.com> commit200bc7251f
Author: Daniel Markstedt <markstedt@gmail.com> Date: Mon Dec 20 06:20:22 2021 -0800 More helpful error message when IP does not resolve for OLED screen (#541) * More helpful error message * Remove confusing fallback IP * Tweak message commit4ae273ccbd
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 22:30:22 2021 -0600 Loopback tester pcb (#545) commit46c5c1966f
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 22:29:59 2021 -0600 RaSCSI Zero version 1.0 (#546) commitd09df31d67
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 20:25:23 2021 -0800 Remove redundant code from OLED script (#547) commitd8828da690
Author: akuker <34318535+akuker@users.noreply.github.com> Date: Sun Dec 19 21:02:50 2021 -0600 Added list of sponsors commitbcd7e8396d
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:51:45 2021 -0800 Second attempt at properly creating the manpage dir (#542) commitc887edfc8c
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:50:03 2021 -0800 Remove special elevated privileges for the Web Interface (#536) * Use the pi_shutdown method to restart the rascsi service * Use the pi_shutdown method to restart the rascsi service * Remove modifications to sudoers no longer needed * Introduce sleeps attempting to connect to socket; reduce overall number of retries * Remove systemd helped methods and the functionality that depends on it * Attempts to speed up splash code * Remove unneccessary verbosity * Attempt to optimize service definition commit801aebfb96
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:47:22 2021 -0800 More readable message when downloading a file (#531) commit29cf58288f
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:47:03 2021 -0800 Add a warning notice when ejecting removable media (#526) commit7efa895239
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:46:22 2021 -0800 Unzip zipfiles before storing to iso (#525) * Unzip zipfiles before storing to iso * Add helptext * Skip unzip for MacZip format * Should not be an fstring commit39bc485671
Author: Daniel Markstedt <markstedt@gmail.com> Date: Sun Dec 19 15:28:22 2021 -0800 Add pip3 to global dependencies; remove duplicates from monitor_rascs… (#523) * Add pip3 to global dependencies; remove duplicates from monitor_rascsi dependencies * Cleanup
227 lines
7.8 KiB
Python
Executable File
227 lines
7.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
RaSCSI Updates:
|
|
Updates to output rascsi status to an OLED display
|
|
Copyright (C) 2020 Tony Kuker
|
|
Author: Tony Kuker
|
|
Developed for:
|
|
https://www.makerfocus.com/collections/oled/products/2pcs-i2c-oled-display-module-0-91-inch-i2c-ssd1306-oled-display-module-1
|
|
|
|
All other code:
|
|
Copyright (c) 2017 Adafruit Industries
|
|
Author: Tony DiCola & James DeVito
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
"""
|
|
from time import sleep
|
|
from sys import argv
|
|
from collections import deque
|
|
from board import I2C
|
|
from adafruit_ssd1306 import SSD1306_I2C
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
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
|
|
BORDER = 5
|
|
|
|
# How long to delay between each update
|
|
DELAY_TIME_MS = 1000
|
|
|
|
# Define the Reset Pin
|
|
OLED_RESET = None
|
|
|
|
# init i2c
|
|
I2C = I2C()
|
|
|
|
# 128x32 display with hardware I2C:
|
|
OLED = SSD1306_I2C(WIDTH, HEIGHT, I2C, addr=0x3C, reset=OLED_RESET)
|
|
|
|
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)
|
|
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))
|
|
|
|
# Get drawing object to draw on image.
|
|
DRAW = 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.
|
|
# Depending on the font used, you may want to change the value of PADDING
|
|
PADDING = 0
|
|
TOP = PADDING
|
|
BOTTOM = HEIGHT - PADDING
|
|
# Move left to right keeping track of the current x position for drawing shapes.
|
|
X_POS = 0
|
|
|
|
# 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', 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()
|
|
|
|
|
|
def formatted_output():
|
|
"""
|
|
Formats the strings to be displayed on the Screen
|
|
Returns a (list) of (str) output
|
|
"""
|
|
rascsi_list = device_list()
|
|
output = []
|
|
|
|
if rascsi_list:
|
|
for line in rascsi_list:
|
|
if line["device_type"] in ("SCCD", "SCRM", "SCMO"):
|
|
# Print image file name only when there is an image attached
|
|
if line["file"]:
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} "
|
|
f"{line['file']} {line['status']}")
|
|
else:
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} {line['status']}")
|
|
# Special handling for the DaynaPort device
|
|
elif line["device_type"] == "SCDP":
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} {line['vendor']} "
|
|
f"{line['product']}")
|
|
# Special handling for the Host Bridge device
|
|
elif line["device_type"] == "SCBR":
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} {line['product']}")
|
|
# Print only the Vendor/Product info if it's not generic RaSCSI
|
|
elif line["vendor"] not in "RaSCSI":
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} {line['file']} "
|
|
f"{line['vendor']} {line['product']} {line['status']}")
|
|
else:
|
|
output.append(f"{line['id']} {line['device_type'][2:4]} {line['file']} "
|
|
f"{line['status']}")
|
|
else:
|
|
output.append("No image mounted!")
|
|
|
|
if IP_ADDR:
|
|
output.append(f"IP {IP_ADDR} - {HOSTNAME}")
|
|
else:
|
|
output.append("RaSCSI has no IP address")
|
|
output.append("Check network connection")
|
|
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
|
|
# to identify changes in RaSCSI backend
|
|
ref_snapshot = formatted_output()
|
|
# The snapshot updated each cycle that will compared with ref_snapshot
|
|
snapshot = ref_snapshot
|
|
# The active output that will be displayed on the screen
|
|
active_output = deque(snapshot)
|
|
|
|
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
|
|
for output_line in active_output:
|
|
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:
|
|
active_output.rotate(-1)
|
|
|
|
# Display image.
|
|
OLED.image(IMAGE)
|
|
OLED.show()
|
|
sleep(1000/DELAY_TIME_MS)
|
|
|
|
snapshot = formatted_output()
|
|
|
|
if handler.interrupted:
|
|
# Catch interrupt signals and show a shutdown splash bitmap image
|
|
stop_splash()
|
|
exit("Shutting down the OLED display...")
|