1 package kaka.cakelight;
3 import java.io.IOException;
4 import java.util.Optional;
5 import java.util.function.Consumer;
7 import static kaka.cakelight.Main.log;
8 import static kaka.cakelight.Main.timeIt;
10 public class VideoMode implements Mode {
11 private Configuration config;
12 private Thread thread;
13 private Consumer<Frame> frameConsumer;
16 public void enter(Configuration config) {
26 private void startGrabberThread() {
27 assert frameConsumer != null;
28 thread = new Thread() {
30 try (FrameGrabber grabber = FrameGrabber.from(config)) {
31 while (!isInterrupted()) {
32 // Optional<Frame> frame = grabber.grabFrame();
33 grabber.grabFrame().ifPresent(frameConsumer);
34 // timeIt("frame", grabber::grabFrame);
35 // TODO: process frame
36 // TODO: save where the LedController can access it
38 } catch (IOException e) {
46 public void onFrame(Consumer<Frame> consumer) {
47 frameConsumer = consumer;