X-Git-Url: http://dolda2000.com/gitweb/?p=kaka%2Fcakelight.git;a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FMain.java;h=9786aac5ac430e50d31142a51b3fd2d4716db708;hp=474683ea66e241560224c08c73a5cbd35941db59;hb=4a2d60564647052562fad28644904298ba83667b;hpb=e59e98fcf77a104e31dd97641b0ceea6d0a79e00 diff --git a/src/kaka/cakelight/Main.java b/src/kaka/cakelight/Main.java index 474683e..9786aac 100644 --- a/src/kaka/cakelight/Main.java +++ b/src/kaka/cakelight/Main.java @@ -4,26 +4,25 @@ import org.opencv.core.Core; import java.io.FileOutputStream; import java.io.IOException; +import java.util.HashMap; public class Main { - public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Configuration config = Configuration.from("config.properties"); - System.out.println("Running with config:\n" + config); - - FrameGrabber grabber = FrameGrabber.from(config); - grabber.prepare(); - Frame frame = grabber.grabFrame(); - double time = 0; - for (int i = 0; i < 100; i++) { - time += timeIt("frame", () -> grabber.grabFrame()); - } - System.out.println("time = " + time); - grabber.close(); -// byte[] data = frame.getData(); -// saveFile(data, "/home/kaka/test.img"); + log("Running with config:\n" + config); + + CakeLight cakelight = new CakeLight(config); + cakelight.setMode(new VideoMode()); + cakelight.startLoop(); +// try { +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// cakelight.setMode(null); + Runtime.getRuntime().addShutdownHook(new Thread(Main::printTimeStats)); } public static void saveFile(byte[] data, String filepath) { @@ -36,19 +35,39 @@ public class Main { } } + public static void log(String msg, Object... args) { + System.out.println(String.format(msg, args)); + } + + private static HashMap timeDurations = new HashMap<>(); + private static HashMap timeCounts = new HashMap<>(); public static double timeIt(String tag, Runnable lambda) { long start = System.nanoTime(); lambda.run(); long end = System.nanoTime(); double duration = (end - start) * 0.000001; - System.out.println("duration (ms): " + tag + " = " + duration); +// log("duration (ms): " + tag + " = " + duration); + + if (!timeDurations.containsKey(tag)) { + timeDurations.put(tag, 0.0); + timeCounts.put(tag, 0); + } + timeDurations.put(tag, timeDurations.get(tag) + duration); + timeCounts.put(tag, timeCounts.get(tag) + 1); return duration; } + + private static void printTimeStats() { + log("Average times in ms:"); + timeDurations.forEach((tag, duration) -> { + log("%s: %s", tag, duration / timeCounts.get(tag)); + }); + } } /* FrameGrabber läser frames asynkront skickar frame till FrameConverter sparas i huvudklassen -läses av FrameProcessor/LedController - */ \ No newline at end of file +läses av FrameProcessor/CakeLight + */