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].replaceAll("[+-]+", ""));
68 if (args[0].startsWith("+")) {
69 b = Math.min(console.getConfig().leds.brightness + b, 31);
70 } else if (args[0].startsWith("-")) {
71 b = Math.max(console.getConfig().leds.brightness - b, 0);
73 console.getConfig().leds.brightness = b;
74 console.out("setting brightness to " + b);
82 static Console.Command gamma() {
83 return command(new String[] {"g", "gamma"}, (console, args) -> {
84 if (args.length == 1) {
85 double g = Double.parseDouble(args[0]);
86 console.getConfig().gamma = g;
87 Color.calculateGammaCorrection(g);
88 console.out("setting gamma to " + g);
96 static Console.Command saturation() {
97 return command(new String[] {"s", "saturation"}, (console, args) -> {
98 if (args.length == 1) {
99 double s = Double.parseDouble(args[0]);
100 console.getConfig().video.saturation = s;
101 console.out("setting saturation to " + s);
109 static Console.Command ambientMode() {
110 return command(new String[] {"m", "mode"}, (console, args) -> {
111 if (args.length == 1) {
112 console.getCakelight().setMode(new AmbientMode(new String[] {args[0]}));
113 console.out("setting ambient mode to " + args[0]);
121 static Console.Command twoColorNoiseMode() {
122 return command(new String[] {"n", "noise"}, (console, args) -> {
123 if (args.length == 2) {
124 console.getCakelight().setMode(new TwoColorNoiseMode(
125 console.parseColor(args[0]),
126 console.parseColor(args[1])
128 console.out("setting two-color noise mode");