WIP
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
diff --git a/src/kaka/cakelight/VideoMode.java b/src/kaka/cakelight/VideoMode.java
new file mode 100644 (file)
index 0000000..be2ee41
--- /dev/null
@@ -0,0 +1,41 @@
+package kaka.cakelight;
+
+import java.io.IOException;
+import java.util.Optional;
+
+import static kaka.cakelight.Main.log;
+import static kaka.cakelight.Main.timeIt;
+
+public class VideoMode implements Mode {
+    private Configuration config;
+    private Thread thread;
+
+    @Override
+    public void enter(Configuration config) {
+        this.config = config;
+        startGrabberThread();
+    }
+
+    @Override
+    public void exit() {
+        thread.interrupt();
+    }
+
+    private void startGrabberThread() {
+        thread = new Thread() {
+            public void run() {
+                try (FrameGrabber grabber = FrameGrabber.from(config)) {
+                    while (!isInterrupted()) {
+//                        Optional<Frame> frame = grabber.grabFrame();
+                        timeIt("frame", grabber::grabFrame);
+                        // TODO: process frame
+                        // TODO: save where the LedController can access it
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        };
+        thread.start();
+    }
+}