Add hasPeriodPassed function to java, for parity with C++ Timer API

Change-Id: I0f9a2714f20deaaccce610bd3eec58409eac3104
This commit is contained in:
Dustin Spicuzza
2014-11-30 23:51:01 -05:00
parent b59f4141c4
commit 8e707169a1
3 changed files with 60 additions and 0 deletions

View File

@@ -120,5 +120,23 @@ public class HardwareTimer implements Timer.StaticInterface {
m_accumulatedTime = temp;
m_running = false;
}
/**
* Check if the period specified has passed and if it has, advance the start
* time by that period. This is useful to decide if it's time to do periodic
* work without drifting later by the time it took to get around to checking.
*
* @param period The period to check for (in seconds).
* @return If the period has passed.
*/
public synchronized boolean hasPeriodPassed(double period) {
if (get() > period) {
// Advance the start time by the period.
// Don't set it to the current time... we want to avoid drift.
m_startTime += period;
return true;
}
return false;
}
}
}