Add single color mode
authorTomas Wenström <tomas.wenstrom@gmail.com>
Sun, 11 Aug 2019 09:46:39 +0000 (11:46 +0200)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Sun, 11 Aug 2019 09:46:39 +0000 (11:46 +0200)
src/kaka/cakelight/Color.java
src/kaka/cakelight/Console.java
src/kaka/cakelight/SingleColorMode.java [new file with mode: 0644]

index c3f782f..0332371 100644 (file)
@@ -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 + "}";
+    }
 }
index 7d864d8..caae09b 100644 (file)
@@ -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 (file)
index 0000000..f72d773
--- /dev/null
@@ -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() {
+    }
+}