From 6f178c6874c47b6855ec0a479c6fbf35275fdc20 Mon Sep 17 00:00:00 2001 From: "Leone, Mark A [LGS]" Date: Sat, 12 Jul 2025 23:20:03 -0400 Subject: [PATCH] Enable pynput keylistener to work as service --- install_as_service.sh | 12 +++++++++++- led_system_monitor.py | 5 +---- run.sh | 4 ++-- snapshot_files/right/check.json | 1 + snapshot_files/right/every-third-row.json | 1 - 5 files changed, 15 insertions(+), 8 deletions(-) mode change 100644 => 100755 run.sh create mode 100644 snapshot_files/right/check.json delete mode 100644 snapshot_files/right/every-third-row.json diff --git a/install_as_service.sh b/install_as_service.sh index f5d39db..030d873 100755 --- a/install_as_service.sh +++ b/install_as_service.sh @@ -1,6 +1,15 @@ #!/bin/bash -args="$*" 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 sed -i "s#led_system_monitor.py.*\$#led_system_monitor.py ${args}#" run.sh cat <>./fwledmonitor.service @@ -9,6 +18,7 @@ Description=Framework 16 LED System Monitor After=network.service [Service] +Environment=DISPLAY=${dsp} Type=simple Restart=always WorkingDirectory=$PWD diff --git a/led_system_monitor.py b/led_system_monitor.py index 721e3ec..313d876 100644 --- a/led_system_monitor.py +++ b/led_system_monitor.py @@ -16,7 +16,6 @@ from monitors import CPUMonitor, MemoryMonitor, BatteryMonitor, DiskMonitor, Net # External Dependencies import numpy as np from pynput.keyboard import Key, Listener -import evdev from serial.tools import list_ports @@ -35,9 +34,7 @@ def discover_led_devices(): return sorted(locations, key = lambda x: re.sub('^\d+\-\d+\.', '', x[0])) except Exception as e: print(f"An Exception occured while tring to locate LED Matrix devices. {e}") - -device = evdev.InputDevice('/dev/input/event7') - + def main(args): led_devices = discover_led_devices() if not len(led_devices): diff --git a/run.sh b/run.sh old mode 100644 new mode 100755 index 3c4cf5e..79bcc0b --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ sudo apt install -y python3-numpy python3-psutil python3-serial python3-evdev - -python3 ./led_system_monitor.py +xhost +local:root +python3 ./led_system_monitor.py diff --git a/snapshot_files/right/check.json b/snapshot_files/right/check.json new file mode 100644 index 0000000..9e07a86 --- /dev/null +++ b/snapshot_files/right/check.json @@ -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,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]] \ No newline at end of file diff --git a/snapshot_files/right/every-third-row.json b/snapshot_files/right/every-third-row.json deleted file mode 100644 index e34fbad..0000000 --- a/snapshot_files/right/every-third-row.json +++ /dev/null @@ -1 +0,0 @@ -[[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1]] \ No newline at end of file