X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FCakeLight.java;h=4b37bd7dc80af51f92b9616ad9bb9655012f3fe7;hb=67b0a75891f19e91cc35e23fa56915cfd7cd52de;hp=9b32c026b34649b3bae075542f2b32d7837788ec;hpb=01ee91e7622bbdf6a940b2d8ca9efc1f133cbe97;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/CakeLight.java b/src/kaka/cakelight/CakeLight.java index 9b32c02..4b37bd7 100644 --- a/src/kaka/cakelight/CakeLight.java +++ b/src/kaka/cakelight/CakeLight.java @@ -1,13 +1,22 @@ package kaka.cakelight; +import kaka.cakelight.mode.Mode; +import org.jnativehook.GlobalScreen; +import org.jnativehook.NativeHookException; +import org.jnativehook.keyboard.NativeKeyAdapter; +import org.jnativehook.keyboard.NativeKeyEvent; +import org.jnativehook.mouse.NativeMouseEvent; +import org.jnativehook.mouse.NativeMouseMotionAdapter; + 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 = new LedController(config); + this.ledController = ledController; + Color.calculateGammaCorrection(config.gamma); } public void setMode(Mode mode) { @@ -19,15 +28,18 @@ public class CakeLight { 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); + initNativeHook(); // 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()); @@ -37,4 +49,29 @@ public class CakeLight { // byte[] data = frame.getData(); // saveFile(data, "/home/kaka/test.img"); } + + private void initNativeHook() { + try { + GlobalScreen.registerNativeHook(); + GlobalScreen.addNativeKeyListener(new NativeKeyAdapter() { + @Override + public void nativeKeyPressed(NativeKeyEvent e) { + System.out.println("key code = " + e.getKeyCode() + ", key text = '" + NativeKeyEvent.getKeyText(e.getKeyCode()) + "'"); + } + }); + GlobalScreen.addNativeMouseMotionListener(new NativeMouseMotionAdapter() { + @Override + public void nativeMouseMoved(NativeMouseEvent e) { + System.out.println("mouse point = " + e.getPoint()); + } + }); + } catch (NativeHookException e) { + e.printStackTrace(); + } + } + + public void turnOff() { + cleanup(); + ledController.onFrame(LedFrame.from(config).fillColor(0, 0, 0)); + } }