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.io.BufferedReader;
9 import java.io.IOException;
10 import java.io.InputStreamReader;
12 public class Console extends Thread {
13 private CakeLight cakelight;
14 private Configuration config;
15 private BufferedReader reader;
17 public static void start(CakeLight cakelight, Configuration config) {
18 new Console(cakelight, config).start();
21 private Console(CakeLight cakelight, Configuration config) {
22 this.cakelight = cakelight;
24 reader = new BufferedReader(new InputStreamReader(System.in));
30 System.out.print("> ");
32 String input = reader.readLine();
33 if (input.matches("[0-5]")) {
34 cakelight.setMode(new AmbientMode(new String[] {input}));
35 System.out.println("setting ambient mode to " + input);
36 } else if (input.matches("v|video")) {
37 cakelight.setMode(new VideoMode());
38 } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
39 String[] split = input.split("\\s+");
40 config.leds.brightness = Integer.parseInt(split[1]);
41 System.out.println("setting brightness to " + config.leds.brightness);
42 } else if (input.matches("q|quit")) {
44 System.out.println("stopping cakelight");
46 } else if (input.matches("(c|col|color)(\\s+[0-9]+){3}")) {
47 String[] split = input.split("\\s+");
49 Integer.parseInt(split[1]),
50 Integer.parseInt(split[2]),
51 Integer.parseInt(split[3])
53 cakelight.setMode(new SingleColorMode(c));
54 System.out.println("setting color to " + c);
55 } else if (input.matches("(g|gamma)\\s+[0-9.]+")) {
56 String[] split = input.split("\\s+");
57 config.gamma = Double.parseDouble(split[1]);
58 Color.calculateGammaCorrection(config.gamma);
59 System.out.println("setting gamma to " + config.gamma);
60 } else if (input.matches("(s|saturation)\\s+[0-9.]+")) {
61 String[] split = input.split("\\s+");
62 config.video.saturation = Double.parseDouble(split[1]);
63 System.out.println("setting saturation to " + config.video.saturation);
64 } else if (input.matches("(n|noise)(\\s+[a-z0-9]+){2}")) {
65 TwoColorNoiseMode.getCommand().activate(cakelight, config, input.split("\\s+"));
66 System.out.println("setting two-color noise mode");
68 } catch (IOException e) {
69 System.out.println("Error reading from command line");
75 public interface Command {
77 void activate(CakeLight cakelight, Configuration config, String[] args);