-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadless-Version.py
More file actions
108 lines (89 loc) · 2.41 KB
/
Copy pathHeadless-Version.py
File metadata and controls
108 lines (89 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# BETA
#!/usr/bin/env python3
import time
import argparse
import os
from app import (
find_hwmon,
find_cooling_device,
find_temp_sensor_path,
find_cpu_freq_path,
read_temp_c,
read_cpu_freq_mhz,
read_mem_used_total_mb,
read_rpm,
read_pwm_value,
read_cooling_state,
set_mode_auto,
set_mode_percent,
is_root,
)
MODES = {
"auto": "auto",
"25": 25,
"50": 50,
"100": 100,
}
def apply_mode(hw, cd, mode):
if mode == "auto":
return set_mode_auto(hw, cd)
else:
return set_mode_percent(hw, cd, mode)
def status_loop(hw, cd, sensor, freq_path, interval):
while True:
temp = read_temp_c(sensor)
rpm = read_rpm(hw)
pwm = read_pwm_value(hw)
cd_state = read_cooling_state(cd)
freq = read_cpu_freq_mhz(freq_path)
used, total = read_mem_used_total_mb()
print(
f"Temp: {temp:.1f}°C | "
f"RPM: {rpm or '--'} | "
f"PWM: {pwm or '--'} | "
f"Cooling: {cd_state or '--'} | "
f"CPU: {freq:.0f} MHz | "
f"RAM: {used/1024:.1f}/{total/1024:.1f} GB"
)
time.sleep(interval)
def main():
parser = argparse.ArgumentParser(
description="Raspberry Pi 5 Fan Controller (Console / Headless)"
)
parser.add_argument(
"--mode",
choices=MODES.keys(),
default="auto",
help="Fan mode: auto, 25, 50, 100",
)
parser.add_argument(
"--interval",
type=float,
default=2.0,
help="Status refresh interval in seconds",
)
parser.add_argument(
"--once",
action="store_true",
help="Apply mode once and exit",
)
args = parser.parse_args()
if not is_root():
print("❌ Bitte mit sudo starten (GPIO / PWM benötigt Root).")
exit(1)
hw = find_hwmon()
cd = find_cooling_device()
sensor = find_temp_sensor_path()
freq_path = find_cpu_freq_path()
if not hw and not cd:
print("❌ Keine hwmon- oder cooling_device-Pfade gefunden.")
exit(1)
mode = MODES[args.mode]
ok = apply_mode(hw, cd, mode)
print(f"✔ Modus gesetzt: {args.mode.upper()} ({'OK' if ok else 'teilweise'})")
if args.once:
return
print("▶ Statusanzeige gestartet (CTRL+C zum Beenden)")
status_loop(hw, cd, sensor, freq_path, args.interval)
if __name__ == "__main__":
main()