X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fkaka%2Fcakelight%2Fmode%2FAmbientMode.java;h=ba816d556ab34aa493fc1b04fe1c607014e91f13;hb=fa9808cd57e32f096495ad06689f7d23878f5217;hp=afe36ab9a657abf2a6520ff908d834ca4e82abf8;hpb=67b0a75891f19e91cc35e23fa56915cfd7cd52de;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/mode/AmbientMode.java b/src/kaka/cakelight/mode/AmbientMode.java index afe36ab..ba816d5 100644 --- a/src/kaka/cakelight/mode/AmbientMode.java +++ b/src/kaka/cakelight/mode/AmbientMode.java @@ -7,8 +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; + private boolean isPaused = false; + + AmbientMode() {} public AmbientMode(String[] args) { if (args.length > 0) { @@ -23,17 +26,31 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St } @Override + public void pause() { + isPaused = true; + } + + @Override + public void resume() { + isPaused = false; + thread.notify(); + } + + @Override public void exit() { stopThread(); } - public void startThread() { + private void startThread() { thread = new Thread() { public void run() { try { long start = System.currentTimeMillis(); int index = 0; while (!isInterrupted()) { + if (isPaused) { + wait(); + } LedFrame frame = LedFrame.from(config); updateFrame(frame, System.currentTimeMillis() - start, index); updateWithFrame(frame); @@ -41,13 +58,14 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St Thread.sleep(20); } } catch (InterruptedException e) { + e.printStackTrace(); } } }; thread.start(); } - public void stopThread() { + private void stopThread() { thread.interrupt(); } @@ -56,7 +74,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;