63 lines
1.1 KiB
C++
63 lines
1.1 KiB
C++
/*
|
|
* Timer.cpp
|
|
*
|
|
* Created on: 20 äåê. 2017 ã.
|
|
* Author: titov
|
|
*/
|
|
|
|
#include "Timer.hh"
|
|
|
|
float systemic::Timer::system_tick_frequency_khz = 0.0f;
|
|
|
|
systemic::Timer::Timer() : state(off), time_stamp(0ull), time_delay(0ull) {}
|
|
|
|
void systemic::Timer::start( time_t delay ) {
|
|
time_stamp = std::clock();
|
|
time_delay = delay * system_tick_frequency_khz;
|
|
|
|
//todo memory-order
|
|
|
|
state = active;
|
|
}
|
|
|
|
void systemic::Timer::stop() {
|
|
state = off;
|
|
}
|
|
|
|
bool systemic::Timer::delayElapsed() const {
|
|
if( state == active
|
|
&& ( std::clock() - time_stamp ) >= time_delay ) {
|
|
state = elapsed;
|
|
}
|
|
|
|
return state == elapsed;
|
|
}
|
|
|
|
bool systemic::Timer::delayFinished() {
|
|
bool result = delayElapsed();
|
|
|
|
if( result ) stop();
|
|
|
|
return result;
|
|
}
|
|
|
|
bool systemic::Timer::isActive() const {
|
|
return state != off;
|
|
}
|
|
|
|
void systemic::Timer::setSystemTickFrequency( unsigned long frequency ) {
|
|
system_tick_frequency_khz = frequency / 1000.0f;
|
|
}
|
|
|
|
systemic::time_t systemic::seconds2time( float time_in_secods ) {
|
|
|
|
return time_in_secods * 1000.0f;
|
|
|
|
}
|
|
|
|
float systemic::time2seconds( time_t time_ ) {
|
|
|
|
return time_ * 0.001f;
|
|
|
|
}
|