summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/timer.cpp12
-rw-r--r--src/utils/timer.hpp4
2 files changed, 9 insertions, 7 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index 540cfe0d..a35a3e9f 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -51,19 +51,19 @@ long long int system_time_s()
}
frequency_clock_t::frequency_clock_t()
- : frequency_{10.0}, last_tick_{0}, time_function_{nullptr}
+ : unit_{1000000}, frequency_{10.0}, last_tick_{0}, time_function_{nullptr}
{}
frequency_clock_t::frequency_clock_t(float frequency)
- : frequency_{frequency}, last_tick_{0}, time_function_{nullptr}
+ : unit_{1000000}, frequency_{frequency}, last_tick_{0}, time_function_{nullptr}
{}
/// @brief Return the period in ms given the frequency in hertz.
-/// @param[in] frequency - Frequency to convert, in Hertz
-float frequency_clock_t::frequency_to_period(float frequency)
+/// @param[in] frequency - Frequency to convert, in hertz
+float frequency_clock_t::frequency_to_period()
{
- return 1 / frequency;
+ return 1 / frequency_ * unit_;
}
bool frequency_clock_t::started()
@@ -78,7 +78,7 @@ time_function_t frequency_clock_t::get_time_function()
bool frequency_clock_t::elapsed(bool stagger)
{
- float period = frequency_to_period(frequency_);
+ float period = frequency_to_period();
float elapsed_time = 0;
if(!started() && stagger)
last_tick_ = get_time_function()() - (rand() % int(period));
diff --git a/src/utils/timer.hpp b/src/utils/timer.hpp
index 5be0e3cd..f5659044 100644
--- a/src/utils/timer.hpp
+++ b/src/utils/timer.hpp
@@ -32,6 +32,7 @@ long long int system_time_s();
class frequency_clock_t
{
private:
+ float unit_; ///< unit_ - multiplicator to make operation to be in the right unit (milli, micro, nano, etc)
float frequency_; ///< the clock frequency in Hz.
unsigned long last_tick_; ///< the last time (in milliseconds since startup) that the clock ticked.
time_function_t time_function_; ///< a function returning current time
@@ -42,7 +43,8 @@ public:
frequency_clock_t(float frequency, unsigned long last_tick, time_function_t time_function);
float get_frequency() const;
- static float frequency_to_period(float frequency);
+
+ float frequency_to_period();
bool started();
time_function_t get_time_function();
bool elapsed(bool stagger);