X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FCommands.java;fp=src%2Fkaka%2Fcakelight%2FCommands.java;h=75b1b100adab4f47edef0c70d7bd5c8962c22649;hb=2b49e4e255f8591fb730f88e71b6b006008ccd3d;hp=0000000000000000000000000000000000000000;hpb=be3f24968584e816ad89e318f1d0f9078f90d200;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Commands.java b/src/kaka/cakelight/Commands.java new file mode 100644 index 0000000..75b1b10 --- /dev/null +++ b/src/kaka/cakelight/Commands.java @@ -0,0 +1,130 @@ +package kaka.cakelight; + +import kaka.cakelight.mode.AmbientMode; +import kaka.cakelight.mode.SingleColorMode; +import kaka.cakelight.mode.TwoColorNoiseMode; +import kaka.cakelight.mode.VideoMode; + +import java.util.function.BiFunction; + +class Commands { + private static Console.Command command(String[] names, BiFunction activate) { + return new Console.Command() { + @Override + public String[] getNames() { + return names; + } + + @Override + public void activate(Console console, String[] args) { + if (!activate.apply(console, args)) { + console.out("did NOT run command"); + } + } + }; + } + + static Console.Command quit() { + return command(new String[] {"q", "quit"}, (console, args) -> { + console.getCakelight().turnOff(); + console.out("stopping cakelight"); + return true; + }); + } + + static Console.Command video() { + return command(new String[] {"v", "video"}, (console, args) -> { + console.getCakelight().setMode(new VideoMode()); + return true; + }); + } + + static Console.Command color() { + return command(new String[] {"c", "col", "color"}, (console, args) -> { + Color c = null; + if (args.length == 1) { + c = console.parseColor(args[0]); + } else if (args.length == 3) { + c = Color.rgb( + Integer.parseInt(args[0]), + Integer.parseInt(args[1]), + Integer.parseInt(args[2]) + ); + } + if (c != null) { + console.getCakelight().setMode(new SingleColorMode(c)); + console.out("setting color to " + c); + return true; + } else { + return false; + } + }); + } + + static Console.Command brightness() { + return command(new String[] {"b", "brightness"}, (console, args) -> { + if (args.length == 1) { + int b = Integer.parseInt(args[0]); + console.getConfig().leds.brightness = b; + console.out("setting brightness to " + b); + return true; + } else { + return false; + } + }); + } + + static Console.Command gamma() { + return command(new String[] {"g", "gamma"}, (console, args) -> { + if (args.length == 1) { + double g = Double.parseDouble(args[0]); + console.getConfig().gamma = g; + Color.calculateGammaCorrection(g); + console.out("setting gamma to " + g); + return true; + } else { + return false; + } + }); + } + + static Console.Command saturation() { + return command(new String[] {"s", "saturation"}, (console, args) -> { + if (args.length == 1) { + double s = Double.parseDouble(args[0]); + console.getConfig().video.saturation = s; + console.out("setting saturation to " + s); + return true; + } else { + return false; + } + }); + } + + static Console.Command ambientMode() { + return command(new String[] {"m", "mode"}, (console, args) -> { + if (args.length == 1) { + console.getCakelight().setMode(new AmbientMode(new String[] {args[0]})); + console.out("setting ambient mode to " + args[0]); + return true; + } else { + return false; + } + }); + } + + static Console.Command twoColorNoiseMode() { + return command(new String[] {"n", "noise"}, (console, args) -> { + if (args.length == 2) { + console.getCakelight().setMode(new TwoColorNoiseMode( + console.parseColor(args[0]), + console.parseColor(args[1]) + )); + console.out("setting two-color noise mode"); + return true; + } else { + return false; + } + }); + } +}