Limit range of saturation config
[kaka/cakelight.git] / src / kaka / cakelight / Configuration.java
index 86ade8e..a24f411 100644 (file)
@@ -21,24 +21,13 @@ public class Configuration {
     }
 
     public static Configuration from(String propertiesFile) {
-        InputStream input = null;
-        try {
-            input = new FileInputStream(propertiesFile);
-            Properties prop = new Properties();
+        Properties prop = new Properties();
+        try (InputStream input = new FileInputStream(propertiesFile)) {
             prop.load(input);
-            return new Configuration(prop);
         } catch (IOException ex) {
             ex.printStackTrace();
-        } finally {
-            if (input != null) {
-                try {
-                    input.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
         }
-        return null;
+        return new Configuration(prop);
     }
 
     private String get(Properties prop, String name) {
@@ -64,7 +53,9 @@ public class Configuration {
         public int height;
         public int bpp;
         public int format;
+        public double saturation;
         public CropConfiguration crop;
+        public ListConfiguration list;
 
         private VideoConfiguration(Properties prop) {
             width = Integer.parseInt(get(prop, "video.width", "720"));
@@ -80,7 +71,9 @@ public class Configuration {
                 default:
                     format = Imgproc.COLOR_YUV2BGR_UYVY;
             }
+            saturation = inRange(Double.parseDouble(get(prop, "video.saturation", "0.5")), 0, 1);
             crop = new CropConfiguration(prop);
+            list = new ListConfiguration(prop);
         }
 
         public class CropConfiguration {
@@ -93,19 +86,51 @@ public class Configuration {
                 bottom = Integer.parseInt(get(prop, "video.crop.bottom", "0"));
             }
         }
+
+        public class ListConfiguration {
+            public boolean top, bottom, left, right;
+
+            private ListConfiguration(Properties prop) {
+                top = get(prop, "video.list.top", "on").equals("on");
+                bottom = get(prop, "video.list.bottom", "on").equals("on");
+                left = get(prop, "video.list.left", "on").equals("on");
+                right = get(prop, "video.list.right", "on").equals("on");
+            }
+        }
     }
 
     public class LedConfiguration {
         public int cols;
         public int rows;
+        public int brightness;
+        public LedType type;
 
         private LedConfiguration(Properties prop) {
             cols = Integer.parseInt(get(prop, "leds.cols"));
             rows = Integer.parseInt(get(prop, "leds.rows"));
+            brightness = (int) inRange(Integer.parseInt(get(prop, "leds.brightness", "31")), 1, 31);
+            switch (get(prop, "leds.type", "").toUpperCase()) {
+                case "WS2801":
+                    type = LedType.WS2801;
+                    break;
+                case "APA102":
+                default:
+                    type = LedType.APA102;
+            }
         }
 
         public int getCount() {
             return cols * 2 + rows * 2;
         }
     }
+
+    public enum LedType {
+        WS2801, APA102
+    }
+
+    private double inRange(double value, double lower, double upper) {
+        return value < lower ? lower
+                : value > upper ? upper
+                : value;
+    }
 }