- if (this.mode != null) {
- this.mode.setFrameListener(ledFrame -> {}); // To avoid any frame being sent to the controller while the thread is exiting
- this.mode.exit();
+ while (popMode());
+ }
+
+ public void pushMode(Mode mode) {
+ Objects.requireNonNull(mode);
+ if (!modes.isEmpty()) {
+ stopMode(modes.peek());
+ }
+ modes.push(mode);
+ startMode(mode);
+ // TODO: create a composite fading mode of top of stack and new mode
+ }
+
+ public boolean popMode() {
+ if (!modes.isEmpty()) {
+ Mode mode = modes.pop();
+ stopMode(mode);
+ if (!modes.isEmpty()) {
+ startMode(modes.peek());
+ }
+ return true;