Dolda2000 GitWeb
/
kaka
/
cakelight.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fc040bc
)
Pause/resume modes when stacking
author
Tomas Wenström
<tomas.wenstrom@gmail.com>
Sun, 1 Dec 2019 21:29:06 +0000
(22:29 +0100)
committer
Tomas Wenström
<tomas.wenstrom@gmail.com>
Sun, 1 Dec 2019 21:29:06 +0000
(22:29 +0100)
src/kaka/cakelight/CakeLight.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/mode/AmbientMode.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/mode/Mode.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/mode/SingleColorMode.java
patch
|
blob
|
blame
|
history
src/kaka/cakelight/mode/VideoMode.java
patch
|
blob
|
blame
|
history
diff --git
a/src/kaka/cakelight/CakeLight.java
b/src/kaka/cakelight/CakeLight.java
index
0c1aa1a
..
822e2ab
100644
(file)
--- a/
src/kaka/cakelight/CakeLight.java
+++ b/
src/kaka/cakelight/CakeLight.java
@@
-34,7
+34,7
@@
public class CakeLight {
public void pushMode(Mode mode) {
Objects.requireNonNull(mode);
if (!modes.isEmpty()) {
public void pushMode(Mode mode) {
Objects.requireNonNull(mode);
if (!modes.isEmpty()) {
-
stop
Mode(modes.peek());
+
pause
Mode(modes.peek());
}
modes.push(mode);
startMode(mode);
}
modes.push(mode);
startMode(mode);
@@
-46,7
+46,7
@@
public class CakeLight {
Mode mode = modes.pop();
stopMode(mode);
if (!modes.isEmpty()) {
Mode mode = modes.pop();
stopMode(mode);
if (!modes.isEmpty()) {
-
start
Mode(modes.peek());
+
resume
Mode(modes.peek());
}
return true;
}
}
return true;
}
@@
-59,6
+59,14
@@
public class CakeLight {
mode.enter(config);
}
mode.enter(config);
}
+ private void pauseMode(Mode mode) {
+ mode.pause();
+ }
+
+ private void resumeMode(Mode mode) {
+ mode.resume();
+ }
+
private void stopMode(Mode mode) {
mode.setFrameListener(ledFrame -> {}); // To avoid any frame being sent to the controller while the thread is exiting
mode.exit();
private void stopMode(Mode mode) {
mode.setFrameListener(ledFrame -> {}); // To avoid any frame being sent to the controller while the thread is exiting
mode.exit();
diff --git
a/src/kaka/cakelight/mode/AmbientMode.java
b/src/kaka/cakelight/mode/AmbientMode.java
index
bc8a680
..
77f1bc3
100644
(file)
--- a/
src/kaka/cakelight/mode/AmbientMode.java
+++ b/
src/kaka/cakelight/mode/AmbientMode.java
@@
-25,6
+25,20
@@
public class AmbientMode extends Mode { // TODO split into DynamicAmbient and St
}
@Override
}
@Override
+ public void pause() {
+ try {
+ thread.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void resume() {
+ thread.notify();
+ }
+
+ @Override
public void exit() {
stopThread();
}
public void exit() {
stopThread();
}
diff --git
a/src/kaka/cakelight/mode/Mode.java
b/src/kaka/cakelight/mode/Mode.java
index
5ece5ea
..
a72e706
100644
(file)
--- a/
src/kaka/cakelight/mode/Mode.java
+++ b/
src/kaka/cakelight/mode/Mode.java
@@
-9,6
+9,8
@@
public abstract class Mode {
private Consumer<LedFrame> frameListener;
public abstract void enter(Configuration config);
private Consumer<LedFrame> frameListener;
public abstract void enter(Configuration config);
+ public abstract void pause();
+ public abstract void resume();
public abstract void exit();
public void setFrameListener(Consumer<LedFrame> listener) {
public abstract void exit();
public void setFrameListener(Consumer<LedFrame> listener) {
diff --git
a/src/kaka/cakelight/mode/SingleColorMode.java
b/src/kaka/cakelight/mode/SingleColorMode.java
index
36c752a
..
3cf4b53
100644
(file)
--- a/
src/kaka/cakelight/mode/SingleColorMode.java
+++ b/
src/kaka/cakelight/mode/SingleColorMode.java
@@
-6,19
+6,33
@@
import kaka.cakelight.LedFrame;
public class SingleColorMode extends Mode {
private Color color;
public class SingleColorMode extends Mode {
private Color color;
+ private LedFrame frame;
public SingleColorMode(Color c) {
color = c;
}
public SingleColorMode(Color c) {
color = c;
}
- @Override
- public void enter(Configuration config) {
- LedFrame frame = LedFrame.from(config);
+ private void colorizeFrame() {
frame.fillColor(color);
updateWithFrame(frame);
}
@Override
frame.fillColor(color);
updateWithFrame(frame);
}
@Override
+ public void enter(Configuration config) {
+ frame = LedFrame.from(config);
+ colorizeFrame();
+ }
+
+ @Override
+ public void pause() {
+ }
+
+ @Override
+ public void resume() {
+ colorizeFrame();
+ }
+
+ @Override
public void exit() {
}
}
public void exit() {
}
}
diff --git
a/src/kaka/cakelight/mode/VideoMode.java
b/src/kaka/cakelight/mode/VideoMode.java
index
91a9f04
..
1f43ffb
100644
(file)
--- a/
src/kaka/cakelight/mode/VideoMode.java
+++ b/
src/kaka/cakelight/mode/VideoMode.java
@@
-28,6
+28,20
@@
public class VideoMode extends Mode {
}
@Override
}
@Override
+ public void pause() {
+ try {
+ grabberThread.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void resume() {
+ grabberThread.notify();
+ }
+
+ @Override
public void exit() {
grabberThread.interrupt();
deviceListener.stopListening();
public void exit() {
grabberThread.interrupt();
deviceListener.stopListening();