}
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) {
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) {
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;
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 {
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 {
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;
public enum LedType {
WS2801, APA102
}
+
+ private double inRange(double value, double lower, double upper) {
+ return value < lower ? lower
+ : value > upper ? upper
+ : value;
+ }
}