Renamed Frame to VideoFrame
[kaka/cakelight.git] / src / kaka / cakelight / CakeLight.java
index afc7b26..3769dce 100644 (file)
@@ -1,32 +1,36 @@
 package kaka.cakelight;
 
-import static kaka.cakelight.Main.timeIt;
-
 public class CakeLight {
     private Configuration config;
     private Mode mode;
+    private LedController ledController;
 
-    public CakeLight(Configuration config) {
+    public CakeLight(Configuration config, LedController ledController) {
         this.config = config;
+        this.ledController = ledController;
+        Color.calculateGammaCorrection(config.gamma);
     }
 
     public void setMode(Mode mode) {
         cleanup();
         this.mode = mode;
+        mode.setFrameListener(ledController::onFrame);
         mode.enter(config);
     }
 
     public void cleanup() {
         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();
         }
     }
 
     public void startLoop() {
+        Console.start(this, config);
         // TODO
 //        FrameGrabber grabber = FrameGrabber.from(config);
 //        grabber.prepare();
-//        Frame frame = grabber.grabFrame();
+//        VideoFrame frame = grabber.grabFrame();
 //        double time = 0;
 //        for (int i = 0; i < 100; i++) {
 //            time += timeIt("frame", () -> grabber.grabFrame());
@@ -36,4 +40,9 @@ public class CakeLight {
 //     byte[] data = frame.getData();
 //     saveFile(data, "/home/kaka/test.img");
     }
+
+    public void turnOff() {
+        cleanup();
+        ledController.onFrame(LedFrame.from(config).fillColor(0, 0, 0));
+    }
 }