X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2Fmode%2FAmbientMode.java;fp=src%2Fkaka%2Fcakelight%2Fmode%2FAmbientMode.java;h=ba816d556ab34aa493fc1b04fe1c607014e91f13;hp=77f1bc37ab1a9d336b20df65b962a4527f87fdfe;hb=fa9808cd57e32f096495ad06689f7d23878f5217;hpb=c9edf58db4c00b7b95bb7f521063e5ecd79db262 diff --git a/src/kaka/cakelight/mode/AmbientMode.java b/src/kaka/cakelight/mode/AmbientMode.java index 77f1bc3..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() {} @@ -26,15 +27,12 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St @Override public void pause() { - try { - thread.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + isPaused = true; } @Override public void resume() { + isPaused = false; thread.notify(); } @@ -43,13 +41,16 @@ public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St 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); @@ -57,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(); }