From 34d8fc098785b8aaecbc7edafeb919b1abbd07cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sun, 11 Aug 2019 12:42:39 +0200 Subject: [PATCH] Limit range of saturation config --- src/kaka/cakelight/Configuration.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/kaka/cakelight/Configuration.java b/src/kaka/cakelight/Configuration.java index 51b2a00..a24f411 100644 --- a/src/kaka/cakelight/Configuration.java +++ b/src/kaka/cakelight/Configuration.java @@ -71,7 +71,7 @@ public class Configuration { default: format = Imgproc.COLOR_YUV2BGR_UYVY; } - saturation = Double.parseDouble(get(prop, "video.saturation", "0.5")); + saturation = inRange(Double.parseDouble(get(prop, "video.saturation", "0.5")), 0, 1); crop = new CropConfiguration(prop); list = new ListConfiguration(prop); } @@ -108,7 +108,7 @@ public class Configuration { private LedConfiguration(Properties prop) { cols = Integer.parseInt(get(prop, "leds.cols")); rows = Integer.parseInt(get(prop, "leds.rows")); - brightness = Math.max(1, Math.min(31, Integer.parseInt(get(prop, "leds.brightness", "31")))); + brightness = (int) inRange(Integer.parseInt(get(prop, "leds.brightness", "31")), 1, 31); switch (get(prop, "leds.type", "").toUpperCase()) { case "WS2801": type = LedType.WS2801; @@ -127,4 +127,10 @@ public class Configuration { public enum LedType { WS2801, APA102 } + + private double inRange(double value, double lower, double upper) { + return value < lower ? lower + : value > upper ? upper + : value; + } } -- 2.11.0