72e9c1392a
Initial implementation of a USB-gadget-linked cooling controller: - fan_controller.c: PWM PID control, tach reading, TCP temp receiver, Unix socket IPC, safe-mode fallback, CSV logging via pigpio. - temp_sender.py: laptop-side lm-sensors/thermal_zone temp sender with auto-reconnect. - FanController.qml: Quickshell floating widget for monitoring and setpoint/manual duty control over the Unix socket.
30 lines
982 B
Python
30 lines
982 B
Python
import socket, time
|
|
import subprocess
|
|
|
|
RPI_IP = "10.55.0.1"
|
|
RPI_PORT = 9000
|
|
INTERVAL = 2.0
|
|
|
|
def get_temp():
|
|
out = subprocess.check_output(["sensors", "-u"]).decode()
|
|
# AMD Ryzen — Tctl is the control temp the firmware uses
|
|
for line in out.splitlines():
|
|
if "tctl" in line.lower() and "input" in line.lower():
|
|
return float(line.split(":")[1].strip())
|
|
# fallback to thermal_zone0
|
|
with open("/sys/class/thermal/thermal_zone0/temp") as f:
|
|
return int(f.read().strip()) / 1000.0
|
|
|
|
# Auto-reconnect loop
|
|
while True:
|
|
try:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.connect((RPI_IP, RPI_PORT))
|
|
print(f"Connected to {RPI_IP}:{RPI_PORT}")
|
|
while True:
|
|
s.sendall(f"{get_temp():.1f}\n".encode())
|
|
time.sleep(INTERVAL)
|
|
except (OSError, ConnectionResetError) as e:
|
|
print(f"Connection lost: {e} — retrying in 5s")
|
|
time.sleep(5)
|