diff --git a/resources/lib/args4j-2.33.jar b/resources/lib/args4j-2.33.jar deleted file mode 100644 index 61be8f3..0000000 Binary files a/resources/lib/args4j-2.33.jar and /dev/null differ diff --git a/resources/lib/jopt-simple-2.3.6.jar b/resources/lib/jopt-simple-2.3.6.jar new file mode 100644 index 0000000..83e13b1 Binary files /dev/null and b/resources/lib/jopt-simple-2.3.6.jar differ diff --git a/src/app/App.java b/src/app/App.java index 6478a7e..b71c5bc 100644 --- a/src/app/App.java +++ b/src/app/App.java @@ -10,9 +10,7 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.Option; +import org.manzerbredes.open_klm.args.ArgsTypeA; import org.manzerbredes.open_klm.client.MainWindow; import org.manzerbredes.open_klm.drivers.*; import org.manzerbredes.open_klm.drivers.DriverTypeA.*; @@ -22,7 +20,7 @@ import org.manzerbredes.open_klm.drivers.DriverTypeA.*; * */ public class App -{ +{/* @Option(name="-leftColor",usage="Set the left color") public String leftColor=null; @Option(name="-middleColor",usage="Set the middle color") @@ -52,22 +50,26 @@ public class App System.exit(0); } - } + }*/ - public static void main( String[] args ) throws InstantiationException, CmdLineException, LineUnavailableException, IOException + public static void main( String[] args ) { - App app =new App(); - CmdLineParser parser = new CmdLineParser(app); - parser.parseArgument(args); - //app.parseArguments(); - // new MainWindow(); - DriverTypeA device=new Driver_1770_ff00(); + + /*app.parseArguments(); + new MainWindow();*/ + /*DriverTypeA device=new Driver_1770_ff00(); Driver a=(Driver) device; a.initDriver(); device.setRegionColor(Region.LEFT, Color.RED, Intensity.HIGH); device.setRegionColor(Region.MIDDLE, Color.ORANGE, Intensity.HIGH); device.setRegionColor(Region.RIGHT, Color.PURPLE, Intensity.HIGH); - device.setMode(Mode.NORMAL); + device.setMode(Mode.WAVE);*/ + System.out.println("Parsing... "+ args.length); + ArgsTypeA a=new ArgsTypeA(); + Driver aa=new Driver_1770_ff00(); + aa.initDriver(); + a.applyAndExit(aa, args); + } } diff --git a/src/args/ArgsManager.java b/src/args/ArgsManager.java new file mode 100644 index 0000000..20eb39b --- /dev/null +++ b/src/args/ArgsManager.java @@ -0,0 +1,5 @@ +package org.manzerbredes.open_klm.args; + +public interface ArgsManager{ + +} \ No newline at end of file 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(); - //TODO Parse and apply args with args4j + // 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(Color.valueOf((String) parsedOptions.valueOf("lc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("mc")){ + this.primaryColorsState.put(Region.MIDDLE, new Pair(Color.valueOf((String) parsedOptions.valueOf("mc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("rc")){ + this.primaryColorsState.put(Region.RIGHT, new Pair(Color.valueOf((String) parsedOptions.valueOf("rc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("lsc")){ + this.secondaryColorsState.put(Region.LEFT, new Pair(Color.valueOf((String) parsedOptions.valueOf("lsc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("msc")){ + this.secondaryColorsState.put(Region.MIDDLE, new Pair(Color.valueOf((String) parsedOptions.valueOf("msc")),Intensity.HIGH)); + } + if(parsedOptions.hasArgument("rsc")){ + this.secondaryColorsState.put(Region.RIGHT, new Pair(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); + } + + // 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