pimoroni / fanshim-python

Python library for the Fan SHIM for Raspberry Pi
https://shop.pimoroni.com/products/fan-shim
MIT License
295 stars 85 forks source link

Extended colours #82

Closed druck13 closed 4 years ago

druck13 commented 4 years ago

Two changes in this branch concerning how the LED is driven. Also removed deprecated threshold and hysteresis parameters to simply code.

1) Added optional --low-temp and --high-temp arguments to install-service.sh and automatic.py This allows temperatures at which the LED shows green and red to be set independently of the fan thresholds. If not specified it will default to the off-threshold and on-threshold values as currently.

2) Added optional --extended-colours argument to install-service.sh and automatic.py which causes the LED to show from blue to green in the range of a notional minimum temperature of 30C up to the low-temp (or off-threshold), and red to magenta in the range of high-temp (or on-threshold) to the maximum of 85C. This allows visualisation of temperature outside the normal expected range where green to red is displayed.

(1) and (2) can be used either independently or together, and if not specified the current LED behaviour is maintained. I implemented these when experiment on how best to use the fanshim:-

Scenario a) Fan wanted on all the time, so off-threshold set to less than the normal idle temperature with the fan on (e.g. 40C), and on-threshold set to just under the maximum temperature normal load (e.g. 65C). The LED shows green at idle, and red under load which is good, but if the Pi cools down overnight and the fan goes off, the temperature then continually cycles over a large range. Using (1) you can set the thresholds lower so the fan stays on (35C and 45C), but the LED still shows the wider range of temperatures (40C to 70C).

Scenario b) Want the fan to be off most of the time (as have had two fans fail running continuously), but come on quickly when there is any load. The off threshold is set to just above the fan off idle temperature (e.g. 50C) and the on threshold set to 5C higher (e.g. 55C). The LED the goes from green to red very quickly, so using (1) you can set up a larger range (45C to 70C).

In either scenario sometimes the Pi's temperature will be lower than the normal range, such as overnight in the winter, or when just powered up. Or higher than the normal maximum, when running long computational tasks. This is where (2) is useful, particularly for high temperatures as you can see if the Pi is getting close to its maximum temperature (shown as magenta) even if the monitor is switched to another computer.

Gadgetoid commented 4 years ago

Can totally see this being useful to people. Thank you!

My oh my does this whole script need a rewrite, though.