#include <time.h>
#include <stdlib.h>
+#include <cmath>
#include "timer.hpp"
: unit_{1000000}, frequency_{10.0}, last_tick_{0}, time_function_{nullptr}
{}
-
frequency_clock_t::frequency_clock_t(float frequency)
: unit_{1000000}, frequency_{frequency}, last_tick_{0}, time_function_{nullptr}
{}
return frequency_ == 0 ? 0 : 1 / frequency_ * unit_;
}
+const struct timeval frequency_clock_t::get_timeval_from_period() const
+{
+ struct timeval freq = {0, 0};
+ float f;
+ freq.tv_usec = (long int)std::modf(frequency_, &f);
+ freq.tv_sec = (time_t)f;
+
+ return freq;
+}
+
bool frequency_clock_t::started()
{
return last_tick_ != 0;