X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FAmbientMode.java;fp=src%2Fkaka%2Fcakelight%2FAmbientMode.java;h=528a1c3a251fa00f5104279b35bf41c60c7db67c;hb=6b5696708b4d9aaf03c8c04bea6e734c045a3e25;hp=0000000000000000000000000000000000000000;hpb=ed56b145bc04170b4129f4ff92b9eab0e6e4dc74;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/AmbientMode.java b/src/kaka/cakelight/AmbientMode.java new file mode 100644 index 0000000..528a1c3 --- /dev/null +++ b/src/kaka/cakelight/AmbientMode.java @@ -0,0 +1,66 @@ +package kaka.cakelight; + +public class AmbientMode extends Mode { // TODO split into DynamicAmbient and StaticAmbient? + private Thread thread; // TODO move to a dynamic sub class + private Configuration config; + + @Override + public void enter(Configuration config) { + this.config = config; +// LedFrame frame = LedFrame.from(config); +// frame.fillColor(255, 0, 128); +// frame.setLedColor(0, Color.rgb(255, 0, 0)); +// frame.setLedColor(1, Color.rgb(0, 255, 0)); +// frame.setLedColor(2, Color.rgb(0, 0, 255)); +// for (int i = 0; i < config.leds.getCount(); i++) { +//// int v = 255 * i / config.leds.getCount(); +// int v = 60 * (i % 3); +// frame.setLedColor(i, Color.rgb(v, v, v)); +// } +// frameListener.accept(frame); + startThread(); + } + + @Override + public void exit() { + stopThread(); + } + + public void startThread() { + thread = new Thread() { + public void run() { + try { + long start = System.currentTimeMillis(); + int index = 0; + while (!isInterrupted()) { + LedFrame frame = LedFrame.from(config); + updateFrame(frame, System.currentTimeMillis() - start, index); + updateWithFrame(frame); + index = (index + 1) % config.leds.getCount(); + Thread.sleep(0); + } + } catch (InterruptedException e) { + } + } + }; + thread.start(); + } + + public void stopThread() { + thread.interrupt(); + } + + /** + * @param frame + * @param time Time in milliseconds since start + * @param count Goes from 0 to number of LEDs - 1 + */ + private void updateFrame(LedFrame frame, long time, int count) { + frame.setLedColor(count, Color.rgb(255, 0, 0)); + frame.setLedColor((count + 1) % config.leds.getCount(), Color.rgb(0, 255, 0)); + frame.setLedColor((count + 2) % config.leds.getCount(), Color.rgb(0, 0, 255)); +// for (int i = 0; i < config.leds.getCount(); i++) { +// +// } + } +}