Class PreciseTimer#

Class Documentation#

class PreciseTimer#

creates an interruptable, precise sleep timer object

This is a utility class to create a reasonably accurate interruptable sleep timer (precision approx 100 microseconds). This is done by making repeated calls to precise_sleep(), while checking for a cancel flag. The timer can also be modified.

Units are in microseconds except for the inputs, delay(ms) and modify(ms), and outputs, get_remaining() and stop(&ms), which are in milliseconds.

Public Functions

inline PreciseTimer()#
inline long delay(long milliseconds)#

This is the entry point to create a blocking delay, which

won’t return until milliseconds have elapsed unless stopped

or modified.

inline long get_remaining()#

Returns the time remaining in milliseconds

inline void modify(long milliseconds)#

Modifies the delay time to new value in milliseconds

inline void progress(long &remaintime, long &delaytime)#

Returns by reference remaining and delay times in msec

inline bool is_held() const#

Returns true if the timer is currently on hold

inline void hold()#

Hold/pause the delay timer at the next short-sleep boundary

inline void resume()#

Removes the hold and resumes the delay after a hold

inline void stop()#

Stops the delay at the next short-sleep boundary

inline void stop(long &milliseconds)#

Stops the delay at the next short-sleep boundary, returns

remaining time in milliseconds by reference.

inline void reset()#

For internal use only, resets class variables