From: Tomas Wenström Date: Fri, 25 Aug 2017 22:25:55 +0000 (+0200) Subject: First draft of a console X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=commitdiff_plain;h=cd28f68c5085af337dc710d04634ad38f7af2438 First draft of a console --- 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; + } + } + } + +}