diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-31 10:47:37 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2016-03-31 10:47:37 +0200 |
| commit | 58a70ad52de0380e7cfee372bd88cbebe90ad412 (patch) | |
| tree | 9202ca95515c0e6e25b46d6a3091f58ad45f8d7d /src/args/ArgsTypeA.java | |
| parent | f9764bba46881a9357de8d949674b6636a2373ed (diff) | |
Add argument parsing
Diffstat (limited to 'src/args/ArgsTypeA.java')
| -rw-r--r-- | src/args/ArgsTypeA.java | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/src/args/ArgsTypeA.java b/src/args/ArgsTypeA.java index 0fd9a1e..1eabf46 100644 --- a/src/args/ArgsTypeA.java +++ b/src/args/ArgsTypeA.java @@ -7,6 +7,9 @@ import org.manzerbredes.open_klm.drivers.Driver; import org.manzerbredes.open_klm.drivers.DriverTypeA; import org.manzerbredes.open_klm.drivers.DriverTypeA.*; +import joptsimple.OptionParser; +import joptsimple.OptionSet; + /** * Parse args for DriverTypeA * @@ -48,12 +51,63 @@ public class ArgsTypeA implements Args{ this.mode=Mode.NORMAL; } + @Override public void applyAndExit(Driver aDriver, String[] args){ if(aDriver.getType().equals(DriverTypeA.class)){ + // Build arguments parser + OptionParser argsParser = new OptionParser(); + + // Define left color, middle color, right color + argsParser.accepts("lc").withRequiredArg(); + argsParser.accepts("mc").withRequiredArg(); + argsParser.accepts("rc").withRequiredArg(); + + // Define left secondary color, middle secondary color, right secondary color + argsParser.accepts("lsc").withRequiredArg(); + argsParser.accepts("msc").withRequiredArg(); + argsParser.accepts("rsc").withRequiredArg(); + + // Define mode + argsParser.accepts("mode").withRequiredArg(); + + + // Parse the options + OptionSet parsedOptions = argsParser.parse(args); + + // Try to apply options + try { + if(parsedOptions.hasArgument("lc")){ + this.primaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("lc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("mc")){ + this.primaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("mc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("rc")){ + this.primaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("rc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("lsc")){ + this.secondaryColorsState.put(Region.LEFT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("lsc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("msc")){ + this.secondaryColorsState.put(Region.MIDDLE, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("msc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("rsc")){ + this.secondaryColorsState.put(Region.RIGHT, new Pair<DriverTypeA.Color, DriverTypeA.Intensity>(Color.valueOf((String) parsedOptions.valueOf("rsc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("mode")){ + this.mode=Mode.valueOf(parsedOptions.argumentOf("mode")); + } + } + catch(Exception e){ + System.err.println(e.getMessage()); + System.exit(1); + } - //TODO Parse and apply args with args4j + // Apply argument + this.applyArguments((DriverTypeA) aDriver); + // Exit after apply System.exit(0); } @@ -61,4 +115,19 @@ public class ArgsTypeA implements Args{ System.exit(1); } + + + /** + * Apply to device + */ + private void applyArguments(DriverTypeA driver){ + for(Region region:Region.values()){ + driver.setRegionColor(region, this.primaryColorsState.get(region).getValue0(), this.primaryColorsState.get(region).getValue1()); + } + for(Region region:Region.values()){ + driver.setSecondaryRegionColor(region, this.secondaryColorsState.get(region).getValue0(), this.primaryColorsState.get(region).getValue1()); + } + driver.setMode(this.mode); + } + }
\ No newline at end of file |
