1 package kaka.cakelight;
3 import kaka.cakelight.mode.AmbientMode;
4 import kaka.cakelight.mode.SingleColorMode;
5 import kaka.cakelight.mode.TwoColorNoiseMode;
6 import kaka.cakelight.mode.VideoMode;
8 import java.util.function.BiFunction;
11 private static Console.Command command(String[] names, BiFunction<Console, String[], Boolean> activate) {
12 return new Console.Command() {
14 public String[] getNames() {
19 public void activate(Console console, String[] args) {
20 if (!activate.apply(console, args)) {
21 console.out("did NOT run command");
27 static Console.Command quit() {
28 return command(new String[] {"q", "quit"}, (console, args) -> {
29 console.getCakelight().turnOff();
30 console.out("stopping cakelight");
35 static Console.Command video() {
36 return command(new String[] {"v", "video"}, (console, args) -> {
37 console.getCakelight().setMode(new VideoMode());
42 static Console.Command color() {
43 return command(new String[] {"c", "col", "color"}, (console, args) -> {
45 if (args.length == 1) {
46 c = console.parseColor(args[0]);
47 } else if (args.length == 3) {
49 Integer.parseInt(args[0]),
50 Integer.parseInt(args[1]),
51 Integer.parseInt(args[2])
55 console.getCakelight().setMode(new SingleColorMode(c));
56 console.out("setting color to " + c);
64 static Console.Command brightness() {
65 return command(new String[] {"b", "brightness"}, (console, args) -> {
66 if (args.length == 1) {
67 int b = Integer.parseInt(args[0]);
68 console.getConfig().leds.brightness = b;
69 console.out("setting brightness to " + b);
77 static Console.Command gamma() {
78 return command(new String[] {"g", "gamma"}, (console, args) -> {
79 if (args.length == 1) {
80 double g = Double.parseDouble(args[0]);
81 console.getConfig().gamma = g;
82 Color.calculateGammaCorrection(g);
83 console.out("setting gamma to " + g);
91 static Console.Command saturation() {
92 return command(new String[] {"s", "saturation"}, (console, args) -> {
93 if (args.length == 1) {
94 double s = Double.parseDouble(args[0]);
95 console.getConfig().video.saturation = s;
96 console.out("setting saturation to " + s);
104 static Console.Command ambientMode() {
105 return command(new String[] {"m", "mode"}, (console, args) -> {
106 if (args.length == 1) {
107 console.getCakelight().setMode(new AmbientMode(new String[] {args[0]}));
108 console.out("setting ambient mode to " + args[0]);
116 static Console.Command twoColorNoiseMode() {
117 return command(new String[] {"n", "noise"}, (console, args) -> {
118 if (args.length == 2) {
119 console.getCakelight().setMode(new TwoColorNoiseMode(
120 console.parseColor(args[0]),
121 console.parseColor(args[1])
123 console.out("setting two-color noise mode");