Add gamma control in console
[kaka/cakelight.git] / src / kaka / cakelight / Console.java
CommitLineData
cd28f68c
TW
1package kaka.cakelight;
2
3import java.io.BufferedReader;
4import java.io.IOException;
5import java.io.InputStreamReader;
6
7public class Console extends Thread {
8 private CakeLight cakelight;
9 private Configuration config;
10 private BufferedReader reader;
11
12 public static void start(CakeLight cakelight, Configuration config) {
13 new Console(cakelight, config).start();
14 }
15
16 private Console(CakeLight cakelight, Configuration config) {
17 this.cakelight = cakelight;
18 this.config = config;
19 reader = new BufferedReader(new InputStreamReader(System.in));
20 }
21
22 @Override
23 public void run() {
24 while (true) {
25 System.out.print("> ");
26 try {
27 String input = reader.readLine();
c8657a8d 28 if (input.matches("[0-5]")) {
cd28f68c
TW
29 cakelight.setMode(new AmbientMode(new String[] {input}));
30 System.out.println("setting ambient mode to " + input);
0b5bef0c
TW
31 } else if (input.matches("v|video")) {
32 cakelight.setMode(new VideoMode());
cd28f68c
TW
33 } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
34 String[] split = input.split("\\s+");
35 config.leds.brightness = Integer.parseInt(split[1]);
8a0c98f8 36 System.out.println("setting brightness to " + config.leds.brightness);
cd28f68c 37 } else if (input.matches("q|quit")) {
a276d5ab 38 cakelight.turnOff();
cd28f68c
TW
39 System.out.println("stopping cakelight");
40 break;
88438046
TW
41 } else if (input.matches("(c|col|color)(\\s+[0-9]+){3}")) {
42 String[] split = input.split("\\s+");
43 Color c = Color.rgb(
44 Integer.parseInt(split[1]),
45 Integer.parseInt(split[2]),
46 Integer.parseInt(split[3])
47 );
48 cakelight.setMode(new SingleColorMode(c));
49 System.out.println("setting color to " + c);
8a0c98f8
TW
50 } else if (input.matches("g|gamma\\s+[0-9.]+")) {
51 String[] split = input.split("\\s+");
52 config.gamma = Double.parseDouble(split[1]);
53 System.out.println("setting gamma to " + config.gamma);
54 break;
cd28f68c
TW
55 }
56 } catch (IOException e) {
57 System.out.println("Error reading from command line");
58 break;
59 }
60 }
61 }
cd28f68c 62}