Renamed Frame to VideoFrame
[kaka/cakelight.git] / src / kaka / cakelight / CakeLight.java
CommitLineData
4a2d6056
TW
1package kaka.cakelight;
2
4a2d6056
TW
3public class CakeLight {
4 private Configuration config;
5 private Mode mode;
03b67a73 6 private LedController ledController;
4a2d6056 7
6b569670 8 public CakeLight(Configuration config, LedController ledController) {
4a2d6056 9 this.config = config;
6b569670 10 this.ledController = ledController;
38c759f8 11 Color.calculateGammaCorrection(config.gamma);
4a2d6056
TW
12 }
13
14 public void setMode(Mode mode) {
15 cleanup();
16 this.mode = mode;
d182b8cc 17 mode.setFrameListener(ledController::onFrame);
4a2d6056
TW
18 mode.enter(config);
19 }
20
21 public void cleanup() {
22 if (this.mode != null) {
6e568391 23 this.mode.setFrameListener(ledFrame -> {}); // To avoid any frame being sent to the controller while the thread is exiting
4a2d6056
TW
24 this.mode.exit();
25 }
26 }
27
28 public void startLoop() {
cd28f68c 29 Console.start(this, config);
4a2d6056
TW
30 // TODO
31// FrameGrabber grabber = FrameGrabber.from(config);
32// grabber.prepare();
adc29b9a 33// VideoFrame frame = grabber.grabFrame();
4a2d6056
TW
34// double time = 0;
35// for (int i = 0; i < 100; i++) {
36// time += timeIt("frame", () -> grabber.grabFrame());
37// }
38// System.out.println("time = " + time);
39// grabber.close();
40// byte[] data = frame.getData();
41// saveFile(data, "/home/kaka/test.img");
42 }
a276d5ab
TW
43
44 public void turnOff() {
45 cleanup();
6e568391 46 ledController.onFrame(LedFrame.from(config).fillColor(0, 0, 0));
a276d5ab 47 }
4a2d6056 48}