WIP
[kaka/cakelight.git] / src / kaka / cakelight / VideoMode.java
1 package kaka.cakelight;
2
3 import java.io.IOException;
4 import java.util.Optional;
5
6 import static kaka.cakelight.Main.log;
7 import static kaka.cakelight.Main.timeIt;
8
9 public class VideoMode implements Mode {
10     private Configuration config;
11     private Thread thread;
12
13     @Override
14     public void enter(Configuration config) {
15         this.config = config;
16         startGrabberThread();
17     }
18
19     @Override
20     public void exit() {
21         thread.interrupt();
22     }
23
24     private void startGrabberThread() {
25         thread = new Thread() {
26             public void run() {
27                 try (FrameGrabber grabber = FrameGrabber.from(config)) {
28                     while (!isInterrupted()) {
29 //                        Optional<Frame> frame = grabber.grabFrame();
30                         timeIt("frame", grabber::grabFrame);
31                         // TODO: process frame
32                         // TODO: save where the LedController can access it
33                     }
34                 } catch (IOException e) {
35                     e.printStackTrace();
36                 }
37             }
38         };
39         thread.start();
40     }
41 }