diff --git a/stats-sender/requirements.txt b/stats-sender/requirements.txt index b5ed4d6..69bd6db 100644 --- a/stats-sender/requirements.txt +++ b/stats-sender/requirements.txt @@ -1,3 +1,4 @@ pyserial PySensors -psutil \ No newline at end of file +psutil +openrgb-python \ No newline at end of file diff --git a/stats-sender/stats_sender.py b/stats-sender/stats_sender.py index d81680c..d5a54d5 100644 --- a/stats-sender/stats_sender.py +++ b/stats-sender/stats_sender.py @@ -10,9 +10,11 @@ import time import psutil import sensors import serial +from openrgb import OpenRGBClient +from openrgb.utils import DeviceType, RGBColor should_stop = False -debug = False +debug = True structure = [ {'pack': 'I', 'mode': 'magic', 'value': 0xAAAAAAAA}, @@ -152,9 +154,35 @@ def read_serial(s: serial.Serial): line = s.readline(1024) if line.endswith(b'\n'): line = line[:-1] - if len(line) > 0: + if len(line) == 0: + continue + + if debug: print(f"recv[{len(line):>3}]: ", line.decode(errors='replace'), ) + # Set fridge light on if the lid is open + if line.strip().startswith(b"LID "): + lid_open = None + if b"LID OPEN" in line: + lid_open = True + if b"LID CLOSED" in line: + lid_open = False + + if lid_open is not None: + set_fridge_lights(lid_open) + + +def set_fridge_lights(on: bool): + client = None + try: + client = OpenRGBClient() + motherboard = client.get_devices_by_type(DeviceType.MOTHERBOARD)[0] + onboard_led_0 = filter(lambda x: x.name == "Onboard LED 0", motherboard.zones).__next__() + onboard_led_0.set_color(RGBColor(0x00, 0xFF if on else 0x00, 0x00)) + finally: + if client is not None: + client.disconnect() + def main(): global should_stop @@ -174,9 +202,8 @@ def main(): s = serial.Serial(port=sys.argv[1], baudrate=115200, timeout=0.5) - if debug: - t = threading.Thread(target=read_serial, args=(s,)) - t.start() + t = threading.Thread(target=read_serial, args=(s,)) + t.start() try: loop(s, hwmon)