Commit | Line | Data |
---|---|---|
cd28f68c TW |
1 | package kaka.cakelight; |
2 | ||
3 | import java.io.BufferedReader; | |
4 | import java.io.IOException; | |
5 | import java.io.InputStreamReader; | |
6 | ||
7 | public 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); | |
31 | } else if (input.matches("(b|brightness)\\s+[0-9]+")) { | |
32 | String[] split = input.split("\\s+"); | |
33 | config.leds.brightness = Integer.parseInt(split[1]); | |
34 | System.out.println("setting brightness to " + split[1]); | |
35 | } else if (input.matches("q|quit")) { | |
a276d5ab | 36 | cakelight.turnOff(); |
cd28f68c TW |
37 | System.out.println("stopping cakelight"); |
38 | break; | |
39 | } | |
40 | } catch (IOException e) { | |
41 | System.out.println("Error reading from command line"); | |
42 | break; | |
43 | } | |
44 | } | |
45 | } | |
46 | ||
47 | } |