Pause/resume modes when stacking
[kaka/cakelight.git] / src / kaka / cakelight / mode / AmbientMode.java
index afe36ab..77f1bc3 100644 (file)
@@ -7,9 +7,11 @@ import kaka.cakelight.util.SimplexNoise3D;
 
 public class AmbientMode extends Mode { // TODO split into DynamicAmbient and StaticAmbient?
     private Thread thread; // TODO move to a dynamic sub class
-    private Configuration config;
+    protected Configuration config;
     private int type = 0;
 
+    AmbientMode() {}
+
     public AmbientMode(String[] args) {
         if (args.length > 0) {
             type = Integer.parseInt(args[0]);
@@ -23,6 +25,20 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St
     }
 
     @Override
+    public void pause() {
+        try {
+            thread.wait();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void resume() {
+        thread.notify();
+    }
+
+    @Override
     public void exit() {
         stopThread();
     }
@@ -56,7 +72,7 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St
      * @param time  Time in milliseconds since start
      * @param count Goes from 0 to number of LEDs - 1
      */
-    private void updateFrame(LedFrame frame, long time, int count) {
+    protected void updateFrame(LedFrame frame, long time, int count) {
         if (type == 0) {
             for (int i = 0; i < config.leds.getCount(); i++) {
                 double r = Math.sin(2 * i * Math.PI / config.leds.getCount() + time * 0.001) * 0.5 + 0.5;