!7 module RecognizeScreen > DynPrintLogAndEnabled { switchable int x1; switchable int y1; switchable int w = screenWidth(); switchable int h = screenHeight(); switchable double maxFPS = 10; transient WithTimestamp> lastScreen; transient new Average screenShotTime; transient new Average iiTime; transient Timestamp loopStarted; transient new RestartableCountdown screenShotCountdown; transient BWIntegralImage ii; Rect area() { ret rect(x1, y1, w, h); } start-thread { dm_doEvery(10.0, 60.0, r { if (enabled) printStats(); }); loopStarted = tsNow(); shoot(); } void shoot enter { if (!enabled) ret; long targetTime = sysNow()+iround(1000/maxFPS); long time = nanoTime(); lastScreen = withTimestamp(okOrError(-> screenshot(area()))); screenShotTime.add(nanosToSeconds(nanoTime()-time)); if (lastScreen->isOK()) { time = nanoTime(); ii = BWIntegralImage(lastScreen!!); iiTime.add(nanosToSeconds(nanoTime()-time)); } screenShotCountdown.setTargetTime(targetTime, r shoot); } void printStats() { print(stats()); } S stats() { var screen = lastScreen?!; ret formatColonProperties_noNulls( "Monitored area", area(), "Error", screen?.getError(), "Last screenshot taken", lastScreen?.timeStamp(), "Average time to take a screenshot", screenShotTime, "Average time to make integral image", iiTime, "Capacity left in first core", percentRatioStrOneDigit( toSeconds(screenShotCountdown.totalSleepTime), elapsedSeconds(loopStarted)) ); } }