Skip to content

Commit 1ce4a57

Browse files
committed
Merge branch 'markhenrick-master'
2 parents 10666a6 + 13bc096 commit 1ce4a57

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ Complete example for monitoring temperature and automatic fan control.
1717
* A long press on the button will toggle automatic mode off/on
1818
* A short press - when automatic is off - will toggle the fan
1919

20-
The LED should light up Green when the fan is enabled, and Red when it's not.
20+
The LED will fade between green (cool) to red (hot) as the Pi's temperature changes.
2121

2222
The script supports these arguments:
2323

2424
* `--on-threshold N` the temperature at which to turn the fan on, in degrees C (default 65)
2525
* `--off-threshold N` the temperature at which to turn the fan off, in degrees C (default 55)
2626
* `--delay N` the delay between subsequent temperature readings, in seconds (default 2)
2727
* `--preempt` preemptively kick in the fan when the CPU frequency is raised (default off)
28+
* `--brightness` the brightness (value of HSV) of the LED (0-255, default 255)
2829

2930
Deprecated arguments
3031

examples/automatic.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
import sys
1010

1111

12-
T_MIN = 35
13-
T_MAX = 95
14-
15-
1612
parser = argparse.ArgumentParser()
1713
parser.add_argument('--threshold', type=float, default=-1, help='Temperature threshold in degrees C to enable fan')
1814
parser.add_argument('--hysteresis', type=float, default=-1, help='Distance from threshold before fan is disabled')
@@ -24,6 +20,7 @@
2420
parser.add_argument('--verbose', action='store_true', default=False, help='Output temp and fan status messages')
2521
parser.add_argument('--nobutton', action='store_true', default=False, help='Disable button input')
2622
parser.add_argument('--noled', action='store_true', default=False, help='Disable LED control')
23+
parser.add_argument('--brightness', type=float, default=255.0, help='LED brightness, from 0 to 255')
2724

2825
args = parser.parse_args()
2926

@@ -44,20 +41,11 @@ def update_led_temperature(temp):
4441
temp = 1.0 - temp
4542
temp *= 120.0
4643
temp /= 360.0
47-
r, g, b = [int(c * 255.0) for c in colorsys.hsv_to_rgb(temp, 1.0, 1.0)]
44+
r, g, b = [int(c * 255.0) for c in colorsys.hsv_to_rgb(temp, 1.0, args.brightness / 255.0)]
4845
fanshim.set_light(r, g, b)
4946
led_busy.release()
5047

5148

52-
def update_led(state):
53-
if args.noled:
54-
return
55-
if state:
56-
fanshim.set_light(0, 255, 0)
57-
else:
58-
fanshim.set_light(255, 0, 0)
59-
60-
6149
def get_cpu_temp():
6250
t = psutil.sensors_temperatures()
6351
for x in ['cpu-thermal', 'cpu_thermal']:
@@ -77,7 +65,6 @@ def set_fan(status):
7765
changed = False
7866
if status != enabled:
7967
changed = True
80-
# update_led(status)
8168
fanshim.set_fan(status)
8269
enabled = status
8370
return changed

examples/install-service.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PREEMPT="no"
77
POSITIONAL_ARGS=()
88
NOLED="no"
99
NOBUTTON="no"
10+
BRIGHTNESS=255
1011

1112
OLD_THRESHOLD=""
1213
OLD_HYSTERESIS=""
@@ -80,6 +81,11 @@ while [[ $# -gt 0 ]]; do
8081
shift
8182
shift
8283
;;
84+
--brightness)
85+
BRIGHTNESS="$2"
86+
shift
87+
shift
88+
;;
8389
*)
8490
POSITIONAL_ARGS+=("$1")
8591
shift
@@ -125,9 +131,10 @@ Delay: $DELAY seconds
125131
Preempt: $PREEMPT
126132
No LED: $NOLED
127133
No Button: $NOBUTTON
134+
Brightness: $BRIGHTNESS
128135
129136
To change these options, run:
130-
sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> (--preempt) (--noled) (--nobutton)
137+
sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> (--preempt) (--noled) (--nobutton)
131138
132139
Or edit: $SERVICE_PATH
133140
@@ -142,7 +149,7 @@ After=multi-user.target
142149
[Service]
143150
Type=simple
144151
WorkingDirectory=$(pwd)
145-
ExecStart=$(pwd)/automatic.py --on-threshold $ON_THRESHOLD --off-threshold $OFF_THRESHOLD --delay $DELAY $EXTRA_ARGS
152+
ExecStart=$(pwd)/automatic.py --on-threshold $ON_THRESHOLD --off-threshold $OFF_THRESHOLD --delay $DELAY --brightness $BRIGHTNESS $EXTRA_ARGS
146153
Restart=on-failure
147154
148155
[Install]

0 commit comments

Comments
 (0)