X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FConfiguration.java;h=755586fd986905024a5ab5a11bce50743b6ec634;hb=eba8feca754a0875f30b8284dab67c8c01f85ef6;hp=35fde300dd0814266c9b8fdd210b9bc46332b479;hpb=e59e98fcf77a104e31dd97641b0ceea6d0a79e00;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Configuration.java b/src/kaka/cakelight/Configuration.java index 35fde30..755586f 100644 --- a/src/kaka/cakelight/Configuration.java +++ b/src/kaka/cakelight/Configuration.java @@ -1,5 +1,7 @@ package kaka.cakelight; +import org.opencv.imgproc.Imgproc; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -10,31 +12,22 @@ public class Configuration { private List> 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) { @@ -56,26 +49,96 @@ public class Configuration { } public class VideoConfiguration { - public String device; public int width; public int height; public int bpp; + public int format; + public boolean mjpg; + public double saturation; + public String device; + public boolean deviceIsAutomatic; + public CropConfiguration crop; + public ListConfiguration list; private VideoConfiguration(Properties prop) { - device = get(prop, "video.device", "/dev/video0"); 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; + break; + case "YVYU": + format = Imgproc.COLOR_YUV2BGR_YVYU; + break; + case "MJPG": + format = 0; + mjpg = true; + 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 { + public int left, right, top, bottom; + + private CropConfiguration(Properties prop) { + left = Integer.parseInt(get(prop, "video.crop.left", "0")); + right = Integer.parseInt(get(prop, "video.crop.right", "0")); + top = Integer.parseInt(get(prop, "video.crop.top", "0")); + 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; + } }