Compare commits
No commits in common. "953a64459a4a77e94d6e07570140f67ddede859c" and "ecbb5e8ede91126a2cafb63c21c965bc9d7593aa" have entirely different histories.
953a64459a
...
ecbb5e8ede
11 changed files with 484 additions and 516 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
*.pyc
|
||||
fwledmonitor.service
|
||||
|
|
|
@ -187,7 +187,7 @@ def init_device(location = "1-4.2"):
|
|||
# PID = 5678
|
||||
device_list = list_ports.comports()
|
||||
for device in device_list:
|
||||
if device.location and device.location.startswith(location):
|
||||
if device.location == location:
|
||||
s = serial.Serial(device.device, 115200)
|
||||
return s
|
||||
except Exception as e:
|
||||
|
@ -195,11 +195,10 @@ def init_device(location = "1-4.2"):
|
|||
|
||||
|
||||
class DrawingThread(threading.Thread):
|
||||
def __init__(self, port_location, input_queue):
|
||||
def __init__(self, serial_port, input_queue):
|
||||
super().__init__()
|
||||
self.daemon = True
|
||||
self.port_location = port_location
|
||||
self.serial_port = init_device(self.port_location)
|
||||
self.serial_port = init_device(serial_port)
|
||||
self.input_queue = input_queue
|
||||
|
||||
def run(self):
|
||||
|
@ -211,5 +210,5 @@ class DrawingThread(threading.Thread):
|
|||
print(f"Error in DrawingThread: {e}")
|
||||
del self.serial_port
|
||||
time.sleep(1.0)
|
||||
self.serial_port = init_device(self.port_location)
|
||||
self.serial_port = init_device(self.serial_port)
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
chmod +x run.sh
|
||||
rm -f fwledmonitor.service || true
|
||||
cat <<EOF >>./fwledmonitor.service
|
||||
[Unit]
|
||||
Description=Framework 16 LED System Monitor
|
||||
After=network.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
WorkingDirectory=$PWD
|
||||
ExecStart=sh -c "'$PWD/run.sh'"
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
EOF
|
||||
|
||||
sudo systemctl stop fwledmonitor
|
||||
sudo cp fwledmonitor.service /lib/systemd/system
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable fwledmonitor
|
|
@ -7,7 +7,18 @@ from drawing import draw_cpu, draw_memory, draw_battery, draw_borders_left, draw
|
|||
from monitors import CPUMonitor, MemoryMonitor, BatteryMonitor, DiskMonitor, NetworkMonitor, get_monitor_brightness
|
||||
|
||||
# External Dependencies
|
||||
import numpy as np
|
||||
try:
|
||||
# These are used in later scripts, but imported here to test if missing
|
||||
import serial # pyserial
|
||||
from serial.tools import list_ports
|
||||
import numpy as np
|
||||
except ImportError:
|
||||
import pip
|
||||
for dependency in ["numpy", "pyserial"]:
|
||||
pip.main(['install', '--user', dependency])
|
||||
import numpy as np
|
||||
|
||||
# print(sbc.get_brightness())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -15,9 +26,9 @@ if __name__ == "__main__":
|
|||
# Right LED Matrix location: "1-3.3"
|
||||
|
||||
# Set up monitors and serial for left LED Matrix
|
||||
min_background_brightness = 12
|
||||
min_background_brightness = 8
|
||||
max_background_brightness = 35
|
||||
min_foreground_brightness = 24
|
||||
min_foreground_brightness = 30
|
||||
max_foreground_brightness = 160
|
||||
|
||||
cpu_monitor = CPUMonitor()
|
||||
|
@ -40,8 +51,8 @@ if __name__ == "__main__":
|
|||
while True:
|
||||
try:
|
||||
screen_brightness = get_monitor_brightness()
|
||||
background_value = int(screen_brightness * (max_background_brightness - min_background_brightness) + min_background_brightness)
|
||||
foreground_value = int(screen_brightness * (max_foreground_brightness - min_foreground_brightness) + min_foreground_brightness)
|
||||
background_value = int(screen_brightness / 100 * (max_background_brightness - min_background_brightness) + min_background_brightness)
|
||||
foreground_value = int(screen_brightness / 100 * (max_foreground_brightness - min_foreground_brightness) + min_foreground_brightness)
|
||||
|
||||
left_start_time = time.time()
|
||||
# Draw to left LED Matrix
|
||||
|
@ -67,13 +78,9 @@ if __name__ == "__main__":
|
|||
draw_bar(grid, last_network_download, foreground_value, bar_x_offset=5, draw_at_bottom=True) # Download
|
||||
draw_borders_right(grid, background_value)
|
||||
right_drawing_queue.put(grid)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception as e:
|
||||
import traceback
|
||||
print(f"Error in main loop: {e}")
|
||||
traceback.print_exc()
|
||||
time.sleep(1.0)
|
||||
time.sleep(0.1)
|
||||
|
||||
print("Exiting")
|
BIN
ledmatrix_gui_windows.exe
Normal file
BIN
ledmatrix_gui_windows.exe
Normal file
Binary file not shown.
33
monitors.py
33
monitors.py
|
@ -5,12 +5,14 @@ import os
|
|||
|
||||
if os.name == 'nt':
|
||||
import wmi
|
||||
else:
|
||||
raise Exception("This script is not supported on this OS")
|
||||
|
||||
class DiskMonitor:
|
||||
def __init__(self, hysterisis_time = 20):
|
||||
self.read_usage_history = [0]
|
||||
self.write_usage_history = [0]
|
||||
self.history_times = [0]
|
||||
self.read_usage_history = []
|
||||
self.write_usage_history = []
|
||||
self.history_times = []
|
||||
self.highest_read_rate = 0.00001
|
||||
self.highest_write_rate = 0.00001
|
||||
self.max_history_size = hysterisis_time
|
||||
|
@ -44,9 +46,9 @@ class DiskMonitor:
|
|||
|
||||
class NetworkMonitor:
|
||||
def __init__(self, hysterisis_time = 20):
|
||||
self.sent_usage_history = [0]
|
||||
self.recv_usage_history = [0]
|
||||
self.history_times = [0]
|
||||
self.sent_usage_history = []
|
||||
self.recv_usage_history = []
|
||||
self.history_times = []
|
||||
self.highest_sent_rate = 0.00001
|
||||
self.highest_recv_rate = 0.00001
|
||||
self.max_history_size = hysterisis_time
|
||||
|
@ -117,25 +119,12 @@ class BatteryMonitor:
|
|||
battery = psutil.sensors_battery()
|
||||
if battery is not None:
|
||||
battery_percentage = battery.percent / 100.0
|
||||
if os.name == "nt":
|
||||
battery_plugged = battery.power_plugged
|
||||
else:
|
||||
bat_status = open('/sys/class/power_supply/BAT1/status', 'r').read().strip()
|
||||
battery_plugged = (bat_status != 'Discharging')
|
||||
return battery_percentage, battery_plugged
|
||||
|
||||
|
||||
def get_monitor_brightness():
|
||||
try:
|
||||
if os.name == 'nt':
|
||||
return wmi.WMI(namespace='wmi').WmiMonitorBrightness()[0].CurrentBrightness / 100.0
|
||||
else:
|
||||
try: # First try the dGPU brightness
|
||||
return int(open('/sys/class/backlight/amdgpu_bl2/brightness', 'r').read()) / 255.0
|
||||
except: # If that doesn't work, try the iGPU brightness
|
||||
return int(open('/sys/class/backlight/amdgpu_bl1/brightness', 'r').read()) / 255.0
|
||||
except Exception as e:
|
||||
return 1.0
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_monitor_brightness())
|
||||
return wmi.WMI(namespace='wmi').WmiMonitorBrightness()[0].CurrentBrightness
|
||||
except:
|
||||
return 50
|
||||
|
|
3
run.bat
3
run.bat
|
@ -1,3 +0,0 @@
|
|||
py -3 -m pip install pyserial numpy wmi psutil
|
||||
|
||||
py -3 led_system_monitor.py
|
3
run.sh
3
run.sh
|
@ -1,3 +0,0 @@
|
|||
sudo apt install python3-numpy python3-psutil
|
||||
|
||||
python3 ./led_system_monitor.py
|
1
start.bat
Normal file
1
start.bat
Normal file
|
@ -0,0 +1 @@
|
|||
py -3 led_system_monitor.py
|
Loading…
Add table
Reference in a new issue