From cd28f68c5085af337dc710d04634ad38f7af2438 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Sat, 26 Aug 2017 00:25:55 +0200 Subject: [PATCH] First draft of a console --- src/kaka/cakelight/CakeLight.java | 1 + src/kaka/cakelight/Console.java | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/kaka/cakelight/Console.java diff --git a/src/kaka/cakelight/CakeLight.java b/src/kaka/cakelight/CakeLight.java index c51a534..6a00a37 100644 --- a/src/kaka/cakelight/CakeLight.java +++ b/src/kaka/cakelight/CakeLight.java @@ -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 index 0000000..a856203 --- /dev/null +++ b/src/kaka/cakelight/Console.java @@ -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; + } + } + } + +} -- 2.11.0