Handle fridge door properly
This commit is contained in:
parent
f7e5330b9a
commit
04264c34fe
2 changed files with 34 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
|||
pyserial
|
||||
PySensors
|
||||
psutil
|
||||
openrgb-python
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue