From: Tomas Wenström Date: Sun, 11 Aug 2019 09:46:39 +0000 (+0200) Subject: Add single color mode X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=884380465ae1ae412b7e5858ade7fd3f77da497f;p=kaka%2Fcakelight.git Add single color mode --- diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index c3f782f..0332371 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -108,4 +108,9 @@ public class Color { (int)(b * invertedValue + other.b * value) ); } + + @Override + public String toString() { + return "Color{r=" + r + ", g=" + g + ", b=" + b + "}"; + } } diff --git a/src/kaka/cakelight/Console.java b/src/kaka/cakelight/Console.java index 7d864d8..caae09b 100644 --- a/src/kaka/cakelight/Console.java +++ b/src/kaka/cakelight/Console.java @@ -38,6 +38,15 @@ public class Console extends Thread { cakelight.turnOff(); System.out.println("stopping cakelight"); break; + } else if (input.matches("(c|col|color)(\\s+[0-9]+){3}")) { + String[] split = input.split("\\s+"); + Color c = Color.rgb( + Integer.parseInt(split[1]), + Integer.parseInt(split[2]), + Integer.parseInt(split[3]) + ); + cakelight.setMode(new SingleColorMode(c)); + System.out.println("setting color to " + c); } } catch (IOException e) { System.out.println("Error reading from command line"); diff --git a/src/kaka/cakelight/SingleColorMode.java b/src/kaka/cakelight/SingleColorMode.java new file mode 100644 index 0000000..f72d773 --- /dev/null +++ b/src/kaka/cakelight/SingleColorMode.java @@ -0,0 +1,20 @@ +package kaka.cakelight; + +public class SingleColorMode extends Mode { + private Color color; + + public SingleColorMode(Color c) { + color = c; + } + + @Override + public void enter(Configuration config) { + LedFrame frame = LedFrame.from(config); + frame.fillColor(color); + updateWithFrame(frame); + } + + @Override + public void exit() { + } +}