diff --git a/examples/automatic.py b/examples/automatic.py index 6a70928..5f48904 100755 --- a/examples/automatic.py +++ b/examples/automatic.py @@ -20,6 +20,7 @@ parser.add_argument('--nobutton', action='store_true', default=False, help='Disable button input') parser.add_argument('--noled', action='store_true', default=False, help='Disable LED control') parser.add_argument('--brightness', type=float, default=255.0, help='LED brightness, from 0 to 255') +parser.add_argument('--extended-colours', action='store_true', default=False, help='Extend LED colours for outside of normal low to high range') args = parser.parse_args() @@ -34,13 +35,13 @@ def clean_exit(signum, frame): def update_led_temperature(temp): led_busy.acquire() temp = float(temp) - if temp < args.low_temp: + if temp < args.low_temp and args.extended_colours: # Between minimum temp and low temp, set LED to blue through to green temp -= min_temp temp /= float(args.low_temp - min_temp) temp = max(0, temp) hue = (120.0 / 360.0) + ((1.0 - temp) * 120.0 / 360.0) - elif temp > args.high_temp: + elif temp > args.high_temp and args.extended_colours: # Between high temp and maximum temp, set LED to red through to magenta temp -= args.high_temp temp /= float(max_temp - args.high_temp) @@ -50,6 +51,7 @@ def update_led_temperature(temp): # In the normal low temp to high temp range, set LED to green through to red temp -= args.low_temp temp /= float(args.high_temp - args.low_temp) + temp = max(0, min(1, temp)) hue = (1.0 - temp) * 120.0 / 360.0 r, g, b = [int(c * 255.0) for c in colorsys.hsv_to_rgb(hue, 1.0, args.brightness / 255.0)] diff --git a/examples/install-service.sh b/examples/install-service.sh index 75879ff..7da0f41 100755 --- a/examples/install-service.sh +++ b/examples/install-service.sh @@ -10,6 +10,7 @@ POSITIONAL_ARGS=() NOLED="no" NOBUTTON="no" BRIGHTNESS=255 +EXTCOLOURS="no" PYTHON="python3" PIP="pip3" PSUTIL_MIN_VERSION="5.6.7" @@ -19,7 +20,7 @@ OFF_THRESHOLD_SET=false SERVICE_PATH=/etc/systemd/system/pimoroni-fanshim.service -USAGE="sudo ./install-service.sh --off-threshold --on-threshold --delay --brightness --low-temp --high-temp --venv (--preempt) (--noled) (--nobutton)" +USAGE="sudo ./install-service.sh --off-threshold --on-threshold --delay --brightness --low-temp --high-temp --venv (--preempt) (--noled) (--nobutton) (--extended-colours)" # Convert Python path to absolute for systemd PYTHON=`type -P $PYTHON` @@ -93,6 +94,15 @@ while [[ $# -gt 0 ]]; do shift shift ;; + -x|--extended-colours) + if [ "$2" == "yes" ] || [ "$2" == "no" ]; then + EXTCOLOURS="$2" + shift + else + EXTCOLOURS="yes" + fi + shift + ;; *) if [[ $1 == -* ]]; then printf "Unrecognised option: $1\n"; @@ -141,6 +151,10 @@ if [ "$NOBUTTON" == "yes" ]; then EXTRA_ARGS+=' --nobutton' fi +if [ "$EXTCOLOURS" == "yes" ]; then + EXTRA_ARGS+=' --extended-colours' +fi + if ! [ "$1" == "" ]; then if [ $ON_THRESHOLD_SET ]; then printf "Refusing to overwrite explicitly set On Threshold ($ON_THRESHOLD) with positional argument!\n" @@ -169,15 +183,16 @@ fi cat << EOF Setting up with: -Off Threshold: $OFF_THRESHOLD C -On Threshold: $ON_THRESHOLD C -Low Temp: $LOW_TEMP C -High Temp: $HIGH_TEMP C -Delay: $DELAY seconds -Preempt: $PREEMPT -Disable LED: $NOLED -Disable Button: $NOBUTTON -Brightness: $BRIGHTNESS +Off Threshold: $OFF_THRESHOLD C +On Threshold: $ON_THRESHOLD C +Low Temp: $LOW_TEMP C +High Temp: $HIGH_TEMP C +Delay: $DELAY seconds +Preempt: $PREEMPT +Disable LED: $NOLED +Disable Button: $NOBUTTON +Brightness: $BRIGHTNESS +Extended Colours: $EXTCOLOURS To change these options, run: $USAGE