1 package kaka.cakelight;
3 public class AmbientMode extends Mode { // TODO split into DynamicAmbient and StaticAmbient?
4 private Thread thread; // TODO move to a dynamic sub class
5 private Configuration config;
8 public void enter(Configuration config) {
10 // LedFrame frame = LedFrame.from(config);
11 // frame.fillColor(255, 0, 128);
12 // frame.setLedColor(0, Color.rgb(255, 0, 0));
13 // frame.setLedColor(1, Color.rgb(0, 255, 0));
14 // frame.setLedColor(2, Color.rgb(0, 0, 255));
15 // for (int i = 0; i < config.leds.getCount(); i++) {
16 //// int v = 255 * i / config.leds.getCount();
17 // int v = 60 * (i % 3);
18 // frame.setLedColor(i, Color.rgb(v, v, v));
20 // frameListener.accept(frame);
29 public void startThread() {
30 thread = new Thread() {
33 long start = System.currentTimeMillis();
35 while (!isInterrupted()) {
36 LedFrame frame = LedFrame.from(config);
37 updateFrame(frame, System.currentTimeMillis() - start, index);
38 updateWithFrame(frame);
39 index = (index + 1) % config.leds.getCount();
42 } catch (InterruptedException e) {
49 public void stopThread() {
55 * @param time Time in milliseconds since start
56 * @param count Goes from 0 to number of LEDs - 1
58 private void updateFrame(LedFrame frame, long time, int count) {
59 frame.setLedColor(count, Color.rgb(255, 0, 0));
60 frame.setLedColor((count + 1) % config.leds.getCount(), Color.rgb(0, 255, 0));
61 frame.setLedColor((count + 2) % config.leds.getCount(), Color.rgb(0, 0, 255));
62 // for (int i = 0; i < config.leds.getCount(); i++) {