Skip to content

Commit

Permalink
Added a delay() method
Browse files Browse the repository at this point in the history
  • Loading branch information
sofian committed Apr 28, 2015
1 parent b099dc8 commit 3dae490
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions SuperChrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ bool SuperChrono::isRunning() const {
return (_isRunning);
}

void SuperChrono::delay(unsigned long time) {
time += elapsed();
while (!passed(time));
}

unsigned long SuperChrono::elapsed() const {
return _offset + _isRunning ? (_getTime() - _startTime) : 0;
}
Expand Down
5 changes: 4 additions & 1 deletion SuperChrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SuperChrono
// Different sorts of ways to get time.
enum Resolution { MILLIS, MICROS, SECONDS };

private:
public:
// Keeps track of start time (in milliseconds).
unsigned long _startTime;

Expand Down Expand Up @@ -100,6 +100,9 @@ class SuperChrono
/// Returns true iff the chronometer is currently running.
bool isRunning() const;

// Blocks execution for a given time.
void delay(unsigned long time);

/// Returns the time in seconds (millis() / 1000).
static unsigned long seconds();
};
Expand Down

0 comments on commit 3dae490

Please sign in to comment.