From 9954cb3e0d17b2141bb3cf6c234da40c799cf836 Mon Sep 17 00:00:00 2001 From: johan Date: Sun, 1 Dec 2013 15:22:51 +0100 Subject: [PATCH] Added parameter value checks to effects Former-commit-id: daf5d46862d9deeb12df56d262c7a0026a191a25 --- effects/knight-rider.py | 4 ++++ effects/rainbow-mood.py | 5 +++++ effects/rainbow-swirl.py | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/effects/knight-rider.py b/effects/knight-rider.py index d855b1a2..1245336c 100644 --- a/effects/knight-rider.py +++ b/effects/knight-rider.py @@ -6,6 +6,10 @@ import colorsys speed = hyperion.args.get('speed', 1.0) fadeFactor = hyperion.args.get('fadeFactor', 0.7) +# Check parameters +speed = max(0.0001, speed) +fadeFactor = max(0.0, min(fadeFactor, 1.0)) + # Initialize the led data width = 25 imageData = bytearray(width * (0,0,0)) diff --git a/effects/rainbow-mood.py b/effects/rainbow-mood.py index 7f3c5727..622dfd8c 100644 --- a/effects/rainbow-mood.py +++ b/effects/rainbow-mood.py @@ -8,6 +8,11 @@ brightness = hyperion.args.get('brightness', 1.0) saturation = hyperion.args.get('saturation', 1.0) reverse = hyperion.args.get('reverse', False) +# Check parameters +rotationTime = max(0.1, rotationTime) +brightness = max(0.0, min(brightness, 1.0)) +saturation = max(0.0, min(saturation, 1.0)) + # Calculate the sleep time and hue increment sleepTime = 0.1 hueIncrement = sleepTime / rotationTime diff --git a/effects/rainbow-swirl.py b/effects/rainbow-swirl.py index a274ace2..f8ac2522 100644 --- a/effects/rainbow-swirl.py +++ b/effects/rainbow-swirl.py @@ -8,6 +8,11 @@ brightness = hyperion.args.get('brightness', 1.0) saturation = hyperion.args.get('saturation', 1.0) reverse = hyperion.args.get('reverse', False) +# Check parameters +rotationTime = max(0.1, rotationTime) +brightness = max(0.0, min(brightness, 1.0)) +saturation = max(0.0, min(saturation, 1.0)) + # Initialize the led data ledData = bytearray() for i in range(hyperion.ledCount):