Move all modes to package kaka.cakelight.mode
[kaka/cakelight.git] / src / kaka / cakelight / Console.java
CommitLineData
cd28f68c
TW
1package kaka.cakelight;
2
67b0a758
TW
3import kaka.cakelight.mode.AmbientMode;
4import kaka.cakelight.mode.SingleColorMode;
5import kaka.cakelight.mode.VideoMode;
6
cd28f68c
TW
7import java.io.BufferedReader;
8import java.io.IOException;
9import java.io.InputStreamReader;
10
11public 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();
c8657a8d 32 if (input.matches("[0-5]")) {
cd28f68c
TW
33 cakelight.setMode(new AmbientMode(new String[] {input}));
34 System.out.println("setting ambient mode to " + input);
0b5bef0c
TW
35 } else if (input.matches("v|video")) {
36 cakelight.setMode(new VideoMode());
cd28f68c
TW
37 } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
38 String[] split = input.split("\\s+");
39 config.leds.brightness = Integer.parseInt(split[1]);
8a0c98f8 40 System.out.println("setting brightness to " + config.leds.brightness);
cd28f68c 41 } else if (input.matches("q|quit")) {
a276d5ab 42 cakelight.turnOff();
cd28f68c
TW
43 System.out.println("stopping cakelight");
44 break;
88438046
TW
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);
6b446d77 54 } else if (input.matches("(g|gamma)\\s+[0-9.]+")) {
8a0c98f8
TW
55 String[] split = input.split("\\s+");
56 config.gamma = Double.parseDouble(split[1]);
b1899e91 57 Color.calculateGammaCorrection(config.gamma);
8a0c98f8 58 System.out.println("setting gamma to " + config.gamma);
6b446d77 59 } else if (input.matches("(s|saturation)\\s+[0-9.]+")) {
53b74d64
TW
60 String[] split = input.split("\\s+");
61 config.video.saturation = Double.parseDouble(split[1]);
62 System.out.println("setting saturation to " + config.video.saturation);
cd28f68c
TW
63 }
64 } catch (IOException e) {
65 System.out.println("Error reading from command line");
66 break;
67 }
68 }
69 }
cd28f68c 70}