Skip to content

Commit

Permalink
Added extended-colours argument to installer and automatic to make ex…
Browse files Browse the repository at this point in the history
…tended colours optional
  • Loading branch information
druck authored and druck committed May 19, 2020
1 parent 3abdfa4 commit 3f741d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
6 changes: 4 additions & 2 deletions examples/automatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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)]
Expand Down
35 changes: 25 additions & 10 deletions examples/install-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ POSITIONAL_ARGS=()
NOLED="no"
NOBUTTON="no"
BRIGHTNESS=255
EXTCOLOURS="no"
PYTHON="python3"
PIP="pip3"
PSUTIL_MIN_VERSION="5.6.7"
Expand All @@ -19,7 +20,7 @@ OFF_THRESHOLD_SET=false

SERVICE_PATH=/etc/systemd/system/pimoroni-fanshim.service

USAGE="sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> --low-temp <n> --high-temp <n> --venv <python_virtual_environment> (--preempt) (--noled) (--nobutton)"
USAGE="sudo ./install-service.sh --off-threshold <n> --on-threshold <n> --delay <n> --brightness <n> --low-temp <n> --high-temp <n> --venv <python_virtual_environment> (--preempt) (--noled) (--nobutton) (--extended-colours)"

# Convert Python path to absolute for systemd
PYTHON=`type -P $PYTHON`
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3f741d4

Please sign in to comment.