+package kaka.cakelight;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class Console extends Thread {
+ private CakeLight cakelight;
+ private Configuration config;
+ private BufferedReader reader;
+
+ public static void start(CakeLight cakelight, Configuration config) {
+ new Console(cakelight, config).start();
+ }
+
+ private Console(CakeLight cakelight, Configuration config) {
+ this.cakelight = cakelight;
+ this.config = config;
+ reader = new BufferedReader(new InputStreamReader(System.in));
+ }
+
+ @Override
+ public void run() {
+ while (true) {
+ System.out.print("> ");
+ try {
+ String input = reader.readLine();
+ if (input.equals("0") || input.equals("1") || input.equals("2")) {
+ cakelight.setMode(new AmbientMode(new String[] {input}));
+ System.out.println("setting ambient mode to " + input);
+ } else if (input.matches("(b|brightness)\\s+[0-9]+")) {
+ String[] split = input.split("\\s+");
+ config.leds.brightness = Integer.parseInt(split[1]);
+ System.out.println("setting brightness to " + split[1]);
+ } else if (input.matches("q|quit")) {
+ cakelight.cleanup();
+ System.out.println("stopping cakelight");
+ break;
+ }
+ } catch (IOException e) {
+ System.out.println("Error reading from command line");
+ break;
+ }
+ }
+ }
+
+}