summaryrefslogtreecommitdiffstats
path: root/src/utils/timer.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-04-02 23:46:56 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-04-11 12:41:42 +0200
commit745ff334267ab92051bc8261a7daa0165c700fac (patch)
tree34b32afe9fdad423118f3799c6dfb2e5d768f168 /src/utils/timer.cpp
parentdcc4af2d7e74762ec8d1caf04657b47fca560fed (diff)
Fix: wrong period operation without unit multiplicator
Possible divsion by 0. Don't know if it is good to keep different time unit instead having one unit for project... Change-Id: I73cfc1ab72d3420d337f10a9b79bdf305a3a2bc7 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/utils/timer.cpp')
-rw-r--r--src/utils/timer.cpp12
1 files changed, 6 insertions, 6 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));