X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FConfiguration.java;h=4f1525c9b2caf51ec2a459b629f63c040e38e075;hb=2d8ddb23fc7f3ead7114314704319fff4dcce1a8;hp=21c2072dee6f44a07384dd6d8f8c1e1ef25ba341;hpb=aa9e49c2a448c4fa4c16d2afe373ea52eefdffd2;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Configuration.java b/src/kaka/cakelight/Configuration.java index 21c2072..4f1525c 100644 --- a/src/kaka/cakelight/Configuration.java +++ b/src/kaka/cakelight/Configuration.java @@ -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) { @@ -98,11 +87,13 @@ 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;