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

This commit is contained in:
Brad Miller (WPI)
2014-12-03 11:06:58 -08:00
committed by Gerrit Code Review
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;
}
}
}