X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2Fmode%2FAmbientMode.java;h=ba816d556ab34aa493fc1b04fe1c607014e91f13;hb=5552e9bd6fc5bd9d23642721e763ccb812a0f1c4;hp=bc8a68016b4447015787e78db5b8c6e933b9de7c;hpb=eca6fd31ebbf5cc015c0a4acd4f1509de061e3df;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/mode/AmbientMode.java b/src/kaka/cakelight/mode/AmbientMode.java index bc8a680..ba816d5 100644 --- a/src/kaka/cakelight/mode/AmbientMode.java +++ b/src/kaka/cakelight/mode/AmbientMode.java @@ -9,6 +9,7 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St private Thread thread; // TODO move to a dynamic sub class protected Configuration config; private int type = 0; + private boolean isPaused = false; AmbientMode() {} @@ -25,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); @@ -43,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(); }