Add video device to config
[kaka/cakelight.git] / src / kaka / cakelight / Configuration.java
index 51b2a00..9975658 100644 (file)
@@ -54,6 +54,8 @@ public class Configuration {
         public int bpp;
         public int format;
         public double saturation;
+        public String device;
+        public boolean deviceIsAutomatic;
         public CropConfiguration crop;
         public ListConfiguration list;
 
@@ -61,6 +63,8 @@ public class Configuration {
             width = Integer.parseInt(get(prop, "video.width", "720"));
             height = Integer.parseInt(get(prop, "video.height", "576"));
             bpp = Integer.parseInt(get(prop, "video.bpp", "2"));
+            device = get(prop, "video.device", "auto");
+            deviceIsAutomatic = "auto".equals(device);
             switch (get(prop, "video.format", "").toUpperCase()) {
                 case "YUYV":
                     format = Imgproc.COLOR_YUV2BGR_YUYV;
@@ -71,7 +75,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 +112,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 +131,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;
+    }
 }