1 package kaka.cakelight;
3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
7 import java.util.stream.Collectors;
9 public class Configuration {
10 private List<Map.Entry<String, String>> settings = new ArrayList<>();
11 public VideoConfiguration video;
12 public LedConfiguration leds;
14 private Configuration(Properties prop) {
15 video = new VideoConfiguration(prop);
16 leds = new LedConfiguration(prop);
19 public static Configuration from(String propertiesFile) {
20 InputStream input = null;
22 input = new FileInputStream(propertiesFile);
23 Properties prop = new Properties();
25 return new Configuration(prop);
26 } catch (IOException ex) {
32 } catch (IOException e) {
40 private String get(Properties prop, String name) {
41 return addSetting(name, prop.getProperty(name));
44 private String get(Properties prop, String name, String dflt) {
45 return addSetting(name, prop.getProperty(name, dflt));
48 private String addSetting(String name, String value) {
49 settings.add(new AbstractMap.SimpleEntry<>(name, value));
54 public String toString() {
55 return settings.stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining("\n"));
58 public class VideoConfiguration {
64 private VideoConfiguration(Properties prop) {
65 device = get(prop, "video.device", "/dev/video0");
66 width = Integer.parseInt(get(prop, "video.width", "720"));
67 height = Integer.parseInt(get(prop, "video.height", "576"));
68 bpp = Integer.parseInt(get(prop, "video.bpp", "2"));
72 public class LedConfiguration {
76 private LedConfiguration(Properties prop) {
77 cols = Integer.parseInt(get(prop, "leds.cols"));
78 rows = Integer.parseInt(get(prop, "leds.rows"));