Skip to content

Commit a40f439

Browse files
committed
Updated docs, service installer
1 parent 6e9b682 commit a40f439

7 files changed

Lines changed: 74 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Fan Shim
1+
# Fan Shim for Raspberry Pi
22

33
[![Build Status](https://travis-ci.com/pimoroni/fanshim-python.svg?branch=master)](https://travis-ci.com/pimoroni/fanshim-python)
44
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/fanshim-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/fanshim-python?branch=master)

examples/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# led.py
2+
3+
Basic demonstration of Fan Shim's RGB LED. Cycles around the circumference of the Hue/Saturation/Value colourspace.
4+
5+
# button.py
6+
7+
Demonstrates usage of button press, release and hold handlers.
8+
9+
# toggle.py
10+
11+
Demonstrates toggling the fan on and off with the button.
12+
13+
# automatic.py
14+
15+
Complete example for monitoring temperature and automatic fan control.
16+
17+
* A long press on the button will toggle automatic mode off/on
18+
* A short press - when automatic is off - will toggle the fan
19+
20+
The LED should light up Green when the fan is enabled, and Red when it's not.
21+
22+
The script supports three arguments:
23+
24+
* `--threshold N` the temperature at which the fan should turn on, in degrees C
25+
* `--hysteresis N` the change in temperature needed to trigger a fan state change, in degrees C
26+
* `--delay N` the delay between subsequent temperature readings, in seconds
27+
28+
You can use systemd or crontab to run this example as a fan controller service on your Pi.
29+
30+
To use systemd, just run:
31+
32+
```
33+
sudo ./install-service.sh
34+
```
35+
36+
You can then stop the fan service with:
37+
38+
```
39+
sudo systemctl stop pimoroni-fanshim.service
40+
```

examples/automatic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
from fanshim import FanShim
23
import psutil
34
import argparse
@@ -35,6 +36,7 @@ def set_automatic(status):
3536
parser = argparse.ArgumentParser()
3637
parser.add_argument('--threshold', type=float, default=37.0, help='Temperature threshold in degrees C to enable fan')
3738
parser.add_argument('--hysteresis', type=float, default=2.0, help='Distance from threshold before fan is disabled')
39+
parser.add_argument('--delay', type=float, default=2.0, help='Delay, in seconds, between temperature readings')
3840

3941
args = parser.parse_args()
4042

@@ -78,6 +80,6 @@ def held_handler():
7880
if abs(last_change - t) > args.hysteresis and armed:
7981
if set_fan(t >= args.threshold):
8082
last_change = t
81-
time.sleep(1.0)
83+
time.sleep(args.delay)
8284
except KeyboardInterrupt:
8385
pass

examples/button.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import signal
23
from fanshim import FanShim
34

examples/install-service.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
SERVICE_PATH=/etc/systemd/system/pimoroni-fanshim.service
3+
4+
read -r -d '' UNIT_FILE << EOF
5+
[Unit]
6+
Description=Fan Shim Service
7+
After=multi-user.target
8+
9+
[Service]
10+
Type=simple
11+
WorkingDirectory=$(pwd)
12+
ExecStart=$(pwd)/automatic.py --threshold 36
13+
Restart=on-failure
14+
15+
[Install]
16+
WantedBy=multi-user.target
17+
EOF
18+
19+
echo "Installing psutil"
20+
pip3 install psutil
21+
22+
echo "Installing service to: $SERVICE_PATH"
23+
echo "$UNIT_FILE" > $SERVICE_PATH
24+
systemctl daemon-reload
25+
systemctl enable pimoroni-fanshim.service
26+
systemctl start pimoroni-fanshim.service
27+
systemctl status pimoroni-fanshim.service

examples/led.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
from fanshim import FanShim
23
import time
34
import colorsys

examples/toggle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import signal
23
from fanshim import FanShim
34

0 commit comments

Comments
 (0)