Compare commits

...

2 commits

5 changed files with 107 additions and 77 deletions

View file

@ -1,6 +1,15 @@
#!/bin/bash #!/bin/bash
args="$*"
chmod +x run.sh chmod +x run.sh
# If first arg is of form :n it will set DISPLAY to :n. Default is :0
dsp_prefix=:
dsp=:0
# if [[ -n "${1+x}" ]]; then
if [[ $1 == $dsp_prefix* ]]; then
dsp="$1"
shift
fi
# fi
args="$*"
rm -f fwledmonitor.service || true rm -f fwledmonitor.service || true
sed -i "s#led_system_monitor.py.*\$#led_system_monitor.py ${args}#" run.sh sed -i "s#led_system_monitor.py.*\$#led_system_monitor.py ${args}#" run.sh
cat <<EOF >>./fwledmonitor.service cat <<EOF >>./fwledmonitor.service
@ -9,6 +18,7 @@ Description=Framework 16 LED System Monitor
After=network.service After=network.service
[Service] [Service]
Environment=DISPLAY=${dsp}
Type=simple Type=simple
Restart=always Restart=always
WorkingDirectory=$PWD WorkingDirectory=$PWD

View file

@ -15,7 +15,7 @@ from monitors import CPUMonitor, MemoryMonitor, BatteryMonitor, DiskMonitor, Net
# External Dependencies # External Dependencies
import numpy as np import numpy as np
import evdev from pynput.keyboard import Key, Listener
from serial.tools import list_ports from serial.tools import list_ports
@ -34,9 +34,7 @@ def discover_led_devices():
return sorted(locations, key = lambda x: re.sub('^\d+\-\d+\.', '', x[0])) return sorted(locations, key = lambda x: re.sub('^\d+\-\d+\.', '', x[0]))
except Exception as e: except Exception as e:
print(f"An Exception occured while tring to locate LED Matrix devices. {e}") print(f"An Exception occured while tring to locate LED Matrix devices. {e}")
device = evdev.InputDevice('/dev/input/event7')
def main(args): def main(args):
led_devices = discover_led_devices() led_devices = discover_led_devices()
if not len(led_devices): if not len(led_devices):
@ -112,6 +110,27 @@ def main(args):
"snap": draw_snap, "snap": draw_snap,
"none": lambda *x: x # noop "none": lambda *x: x # noop
} }
def on_press(key):
global alt_pressed
global i_pressed
if type(key).__name__ == 'KeyCode':
if key.char == 'i':
i_pressed = True
elif key == Key.alt:
alt_pressed = True
def on_release(key):
global alt_pressed
global i_pressed
if type(key).__name__ == 'KeyCode':
if key.char == 'i':
i_pressed = False
elif key == Key.alt:
alt_pressed = False
if key == Key.esc:
# Stop listener
return False
################################################# #################################################
### Load app functions from plugins ### ### Load app functions from plugins ###
@ -133,78 +152,79 @@ def main(args):
if args.snapshot_duration > args.snapshot_interval: if args.snapshot_duration > args.snapshot_interval:
print("Snapshot duration must be less than snapshot interval. Exiting...") print("Snapshot duration must be less than snapshot interval. Exiting...")
sys.exit(0) sys.exit(0)
start_time = time.time() with Listener(
while True: on_press=on_press,
elapsed_time = time.time() on_release=on_release):
show_snapshot = True if args.snapshot_interval == 0 or elapsed_time % args.snapshot_interval <= args.snapshot_duration else False while True:
try: elapsed_time = time.time()
screen_brightness = get_monitor_brightness() show_snapshot = True if args.snapshot_interval == 0 or elapsed_time % args.snapshot_interval <= args.snapshot_duration else False
background_value = int(screen_brightness * (max_background_brightness - min_background_brightness) + min_background_brightness) try:
foreground_value = int(screen_brightness * (max_foreground_brightness - min_foreground_brightness) + min_foreground_brightness) screen_brightness = get_monitor_brightness()
grid = np.zeros((9,34), dtype = int) background_value = int(screen_brightness * (max_background_brightness - min_background_brightness) + min_background_brightness)
active_keys = device.active_keys(verbose=True) foreground_value = int(screen_brightness * (max_foreground_brightness - min_foreground_brightness) + min_foreground_brightness)
if (MODIFIER_KEYS[0] in active_keys or MODIFIER_KEYS[1] in active_keys) and KEY_I in active_keys and not args.no_key_listener:
if args.left_snap and show_snapshot:
draw_id(grid, "snap", foreground_value)
else:
draw_outline_border(grid, background_value)
draw_ids(grid, args.top_left, args.bottom_left, foreground_value)
left_drawing_queue.put(grid)
grid = np.zeros((9,34), dtype = int) grid = np.zeros((9,34), dtype = int)
if args.right_snap and show_snapshot: if i_pressed and alt_pressed and not args.no_key_listener:
draw_id(grid, "snap", foreground_value) if args.left_snap and show_snapshot:
else: draw_id(grid, "snap", foreground_value)
draw_outline_border(grid, background_value) else:
draw_ids(grid, args.top_right, args.bottom_right, foreground_value) draw_outline_border(grid, background_value)
right_drawing_queue.put(grid) draw_ids(grid, args.top_left, args.bottom_left, foreground_value)
grid = np.zeros((9,34), dtype = int) left_drawing_queue.put(grid)
time.sleep(0.1) grid = np.zeros((9,34), dtype = int)
continue if args.right_snap and show_snapshot:
draw_id(grid, "snap", foreground_value)
else:
draw_outline_border(grid, background_value)
draw_ids(grid, args.top_right, args.bottom_right, foreground_value)
right_drawing_queue.put(grid)
grid = np.zeros((9,34), dtype = int)
time.sleep(0.1)
continue
# Draw by half or whole panel, depending on program args # Draw by half or whole panel, depending on program args
for i, draw_queue in enumerate(drawing_queues): for i, draw_queue in enumerate(drawing_queues):
grid = np.zeros((9,34), dtype = int) grid = np.zeros((9,34), dtype = int)
if i == 0: if i == 0:
panel = 'left' panel = 'left'
if args.left_snap is not None and show_snapshot: if args.left_snap is not None and show_snapshot:
app_functions["snap"](grid, foreground_value, args.left_snap, args.snapshot_path, 'left') app_functions["snap"](grid, foreground_value, args.left_snap, args.snapshot_path, 'left')
draw_queue.put(grid) draw_queue.put(grid)
continue continue
else:
_args = [args.top_left, args.bottom_left]
else: else:
_args = [args.top_left, args.bottom_left] panel = 'right'
else: if args.right_snap is not None and show_snapshot:
panel = 'right' app_functions["snap"](grid, foreground_value, args.right_snap, args.snapshot_path, 'right')
if args.right_snap is not None and show_snapshot: draw_queue.put(grid)
app_functions["snap"](grid, foreground_value, args.right_snap, args.snapshot_path, 'right') continue
draw_queue.put(grid) _args = [args.top_right, args.bottom_right]
continue for j, arg in enumerate(_args):
_args = [args.top_right, args.bottom_right] if j == 0:
for j, arg in enumerate(_args): idx = 0
if j == 0: loc = 'top'
idx = 0 else:
loc = 'top' idx = 16
else: loc = 'bottom'
idx = 16 try:
loc = 'bottom' func = app_functions[arg]
try: func(arg, grid, foreground_value, idx)
func = app_functions[arg] except KeyError:
func(arg, grid, foreground_value, idx) print(f"Unrecognized display option {arg} for {loc} {panel}")
except KeyError: if arg == 'mem-bat': arg = 'mem' # Single border draw for mem and bat together
print(f"Unrecognized display option {arg} for {loc} {panel}") draw_app_border(arg, grid, background_value, idx)
if arg == 'mem-bat': arg = 'mem' # Single border draw for mem and bat together draw_queue.put(grid)
draw_app_border(arg, grid, background_value, idx)
draw_queue.put(grid) except KeyboardInterrupt:
break
except KeyboardInterrupt: except Exception as e:
break import traceback
except Exception as e: print(f"Error in main loop: {e}")
import traceback traceback.print_exc()
print(f"Error in main loop: {e}") time.sleep(1.0)
traceback.print_exc() time.sleep(0.1)
time.sleep(1.0)
time.sleep(0.1) print("Exiting")
print("Exiting")
if __name__ == "__main__": if __name__ == "__main__":
app_names = ["cpu", "net", "disk", "mem-bat", "none"] app_names = ["cpu", "net", "disk", "mem-bat", "none"]

4
run.sh Normal file → Executable file
View file

@ -1,3 +1,3 @@
sudo apt install -y python3-numpy python3-psutil python3-serial python3-evdev sudo apt install -y python3-numpy python3-psutil python3-serial python3-evdev
xhost +local:root
python3 ./led_system_monitor.py python3 ./led_system_monitor.py

View file

@ -0,0 +1 @@
[[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1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