1 package kaka.cakelight;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
7 public class Console extends Thread {
8 private CakeLight cakelight;
9 private Configuration config;
10 private BufferedReader reader;
12 public static void start(CakeLight cakelight, Configuration config) {
13 new Console(cakelight, config).start();
16 private Console(CakeLight cakelight, Configuration config) {
17 this.cakelight = cakelight;
19 reader = new BufferedReader(new InputStreamReader(System.in));
25 System.out.print("> ");
27 String input = reader.readLine();
28 if (input.matches("[0-5]")) {
29 cakelight.setMode(new AmbientMode(new String[] {input}));
30 System.out.println("setting ambient mode to " + input);
31 } else if (input.matches("v|video")) {
32 cakelight.setMode(new VideoMode());
33 } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
34 String[] split = input.split("\\s+");
35 config.leds.brightness = Integer.parseInt(split[1]);
36 System.out.println("setting brightness to " + split[1]);
37 } else if (input.matches("q|quit")) {
39 System.out.println("stopping cakelight");
42 } catch (IOException e) {
43 System.out.println("Error reading from command line");