Always return a configuration
[kaka/cakelight.git] / src / kaka / cakelight / Configuration.java
index d91bfb6..4f1525c 100644 (file)
@@ -12,31 +12,22 @@ public class Configuration {
     private List<Map.Entry<String, String>> settings = new ArrayList<>();
     public VideoConfiguration video;
     public LedConfiguration leds;
+    public double gamma;
 
     private Configuration(Properties prop) {
         video = new VideoConfiguration(prop);
         leds = new LedConfiguration(prop);
+        gamma = Double.parseDouble(get(prop,"gamma", "1"));
     }
 
     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) {
@@ -70,13 +61,13 @@ public class Configuration {
             bpp = Integer.parseInt(get(prop, "video.bpp", "2"));
             switch (get(prop, "video.format", "").toUpperCase()) {
                 case "YUYV":
-                    format = Imgproc.COLOR_YUV2RGB_YUYV;
+                    format = Imgproc.COLOR_YUV2BGR_YUYV;
                     break;
                 case "YVYU":
-                    format = Imgproc.COLOR_YUV2RGB_YVYU;
+                    format = Imgproc.COLOR_YUV2BGR_YVYU;
                     break;
                 default:
-                    format = Imgproc.COLOR_YUV2RGB_UYVY;
+                    format = Imgproc.COLOR_YUV2BGR_UYVY;
             }
             crop = new CropConfiguration(prop);
         }
@@ -96,14 +87,29 @@ public class Configuration {
     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 = Math.max(1, Math.min(31, Integer.parseInt(get(prop, "leds.brightness", "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
+    }
 }