-
Notifications
You must be signed in to change notification settings - Fork 10
/
timeObj.h
executable file
·42 lines (31 loc) · 1.43 KB
/
timeObj.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef timeObj_h
#define timeObj_h
//****************************************************************************************
// Insanely handy for doing things in the background. Set the timer and wait 'till it goes
// "ding". Great for blinking LEDs, updating readings, etc.
// *** Takes care of roll over issues ***
//
// NOTE: Once the timer expires, every call to ding() will return true until its been
// reset or restarted.
//****************************************************************************************
class timeObj {
public:
timeObj(float inMs=10,bool startNow=true);
virtual ~timeObj(void);
void setTime(float inMs,bool startNow=true); // Change the time duration for next start..
virtual void start(void); // Start the timer "now".
virtual void stepTime(void); // Restart the timer from last end time.
bool ding(void); // Timer has expired.
float getTime(void); // How long does this go for?
float getFraction(void); // Fuel gauge. What fraction of time is left.
void reset(void); // Reset to the preStart state.
//void printState(void); // Debugging.
private :
enum timeObjStates { preStart, running, expired };
bool useMilli;
timeObjStates ourState;
unsigned long waitTime;
unsigned long startTime;
unsigned long endTime;
};
#endif