1 package kaka.cakelight;
3 import kaka.cakelight.mode.AmbientMode;
4 import kaka.cakelight.mode.SingleColorMode;
5 import kaka.cakelight.mode.VideoMode;
7 import java.io.BufferedReader;
8 import java.io.IOException;
9 import java.io.InputStreamReader;
11 public class Console extends Thread {
12 private CakeLight cakelight;
13 private Configuration config;
14 private BufferedReader reader;
16 public static void start(CakeLight cakelight, Configuration config) {
17 new Console(cakelight, config).start();
20 private Console(CakeLight cakelight, Configuration config) {
21 this.cakelight = cakelight;
23 reader = new BufferedReader(new InputStreamReader(System.in));
29 System.out.print("> ");
31 String input = reader.readLine();
32 if (input.matches("[0-5]")) {
33 cakelight.setMode(new AmbientMode(new String[] {input}));
34 System.out.println("setting ambient mode to " + input);
35 } else if (input.matches("v|video")) {
36 cakelight.setMode(new VideoMode());
37 } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
38 String[] split = input.split("\\s+");
39 config.leds.brightness = Integer.parseInt(split[1]);
40 System.out.println("setting brightness to " + config.leds.brightness);
41 } else if (input.matches("q|quit")) {
43 System.out.println("stopping cakelight");
45 } else if (input.matches("(c|col|color)(\\s+[0-9]+){3}")) {
46 String[] split = input.split("\\s+");
48 Integer.parseInt(split[1]),
49 Integer.parseInt(split[2]),
50 Integer.parseInt(split[3])
52 cakelight.setMode(new SingleColorMode(c));
53 System.out.println("setting color to " + c);
54 } else if (input.matches("(g|gamma)\\s+[0-9.]+")) {
55 String[] split = input.split("\\s+");
56 config.gamma = Double.parseDouble(split[1]);
57 Color.calculateGammaCorrection(config.gamma);
58 System.out.println("setting gamma to " + config.gamma);
59 } else if (input.matches("(s|saturation)\\s+[0-9.]+")) {
60 String[] split = input.split("\\s+");
61 config.video.saturation = Double.parseDouble(split[1]);
62 System.out.println("setting saturation to " + config.video.saturation);
64 } catch (IOException e) {
65 System.out.println("Error reading from command line");