First draft of a console
authorTomas Wenström <tomas.wenstrom@gmail.com>
Fri, 25 Aug 2017 22:25:55 +0000 (00:25 +0200)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Fri, 25 Aug 2017 22:25:55 +0000 (00:25 +0200)
src/kaka/cakelight/CakeLight.java
src/kaka/cakelight/Console.java [new file with mode: 0644]

index c51a534..6a00a37 100644 (file)
@@ -25,6 +25,7 @@ public class CakeLight {
     }
 
     public void startLoop() {
+        Console.start(this, config);
         // TODO
 //        FrameGrabber grabber = FrameGrabber.from(config);
 //        grabber.prepare();
diff --git a/src/kaka/cakelight/Console.java b/src/kaka/cakelight/Console.java
new file mode 100644 (file)
index 0000000..a856203
--- /dev/null
@@ -0,0 +1,47 @@
+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;
+            }
+        }
+    }
+
+}