Added a LED controller that consumes LED frames from the modes
[kaka/cakelight.git] / src / kaka / cakelight / GuiTest.java
index 8feac32..a3cabf4 100644 (file)
@@ -56,11 +56,16 @@ public class GuiTest extends Application {
 
     private void setupCakeLight() {
         log("Running with config:\n" + config);
-        cakelight = new CakeLight(config);
+        cakelight = new CakeLight(config, new LedController() {
+            @Override
+            public void accept(LedFrame ledFrame) {
+                if (!paused) drawLEDs(canvas.getGraphicsContext2D(), ledFrame);
+            }
+        });
         VideoMode mode = new VideoMode();
         cakelight.setMode(mode);
         cakelight.startLoop();
-        mode.onFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame));
+        mode.onVideoFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame));
     }
 
     private void drawFrame(GraphicsContext gc, Frame frame) {
@@ -70,24 +75,23 @@ public class GuiTest extends Application {
         drawRows(gc, frame);
 //        drawVideo(gc, frame);
         drawBorderAndGrid(gc);
-        drawLEDs(gc, frame);
     }
 
-    private void drawLEDs(GraphicsContext gc, Frame frame) {
+    private void drawLEDs(GraphicsContext gc, LedFrame frame) {
         int ledLength = GUTTER;
         float colSize = 16f * BLOCK / config.leds.cols;
         float rowSize = 9f * BLOCK / config.leds.rows;
 //        DropShadow shadow = new DropShadow(BlurType.ONE_PASS_BOX, Color.RED, colSize * 2, colSize, 0, 0);
         for (int x = 0; x < config.leds.cols; x++) {
-            gc.setFill(frame.getLedColor(ListPosition.TOP, x));
+            gc.setFill(frame.getLedColor(x + config.leds.rows));
             gc.fillRect(GUTTER + x * colSize, GUTTER - ledLength, colSize, ledLength);
-            gc.setFill(frame.getLedColor(ListPosition.BOTTOM, x));
+            gc.setFill(frame.getLedColor(config.leds.rows * 2 + config.leds.cols * 2 - 1 - x));
             gc.fillRect(GUTTER + x * colSize, GUTTER + 9 * BLOCK, colSize, ledLength);
         }
         for (int y = 0; y < config.leds.rows; y++) {
-            gc.setFill(frame.getLedColor(ListPosition.LEFT, y));
+            gc.setFill(frame.getLedColor(config.leds.rows - 1 - y));
             gc.fillRect(GUTTER - ledLength, GUTTER + y * rowSize, ledLength, rowSize);
-            gc.setFill(frame.getLedColor(ListPosition.RIGHT, y));
+            gc.setFill(frame.getLedColor(y + config.leds.rows + config.leds.cols));
             gc.fillRect(GUTTER + 16 * BLOCK, GUTTER + y * rowSize, ledLength, rowSize);
         }
     }