← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #214163]: ObserveScanRate

 

Question #214163 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/214163

RaiMan proposed the following answer:
-- no, you just have to believe it ;-)

here is the java code that scans:

    boolean repeat(double timeout) throws Exception {

      int MaxTimePerScan = (int) (1000.0 / Settings.WaitScanRate);
      long begin_t = (new Date()).getTime();
      do {
        long before_find = (new Date()).getTime();
        run(); // the search 
        if (ifSuccessful()) {
          return true; // return if found
        } else if (timeout < MaxTimePerScan) {
          return false; // return immediately if not found and short timeout 
        }

	long after_find = (new Date()).getTime();
        if (after_find - before_find < MaxTimePerScan) {
          // wait until time give by scan rate is exceeded
          getScreen().getActionRobot().delay((int) (MaxTimePerScan - (after_find - before_find)));
        } else {
          getScreen().getActionRobot().delay(10);
        }
      } while (begin_t + timeout * 1000 > (new Date()).getTime()); // loop until timeout

      return false;
    }

--- But if you want full control:

use exists(image, 0), which searches only once.

def myScanner(img, max, scan):
    maxTime = max # seconds
    scanTime = scan # seconds
    endTime = time.time() + maxTime
    while time.time < maxTime:
        start = time.time()
        if exists(image, 0): return getLastMatch()
        used = time.time - start
        if used < scanTime: wait(scanTime-used)
    return None

usage:
if myScanner("some-image.png", 60, 5): print "found"
else: print "not found"

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.