Move all modes to package kaka.cakelight.mode
[kaka/cakelight.git] / src / kaka / cakelight / Console.java
1 package kaka.cakelight;
2
3 import kaka.cakelight.mode.AmbientMode;
4 import kaka.cakelight.mode.SingleColorMode;
5 import kaka.cakelight.mode.VideoMode;
6
7 import java.io.BufferedReader;
8 import java.io.IOException;
9 import java.io.InputStreamReader;
10
11 public class Console extends Thread {
12     private CakeLight cakelight;
13     private Configuration config;
14     private BufferedReader reader;
15
16     public static void start(CakeLight cakelight, Configuration config) {
17         new Console(cakelight, config).start();
18     }
19
20     private Console(CakeLight cakelight, Configuration config) {
21         this.cakelight = cakelight;
22         this.config = config;
23         reader = new BufferedReader(new InputStreamReader(System.in));
24     }
25
26     @Override
27     public void run() {
28         while (true) {
29             System.out.print("> ");
30             try {
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")) {
42                     cakelight.turnOff();
43                     System.out.println("stopping cakelight");
44                     break;
45                 } else if (input.matches("(c|col|color)(\\s+[0-9]+){3}")) {
46                     String[] split = input.split("\\s+");
47                     Color c = Color.rgb(
48                             Integer.parseInt(split[1]),
49                             Integer.parseInt(split[2]),
50                             Integer.parseInt(split[3])
51                     );
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);
63                 }
64             } catch (IOException e) {
65                 System.out.println("Error reading from command line");
66                 break;
67             }
68         }
69     }
70 }