2020-11-20 15:32:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
namespace common2
|
2020-11-20 15:32:35 +00:00
|
|
|
{
|
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
class Speed
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Speed(const bool fixedSpeed);
|
2020-12-06 18:03:41 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
void reset();
|
2020-11-20 15:32:35 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
// calculate the number of cycles to execute in the current period
|
|
|
|
// assuming the next call will happen in x microseconds
|
2021-05-16 18:44:16 +01:00
|
|
|
uint64_t getCyclesTillNext(const size_t microseconds) const;
|
2021-05-28 19:07:58 +01:00
|
|
|
uint64_t getCyclesAtFixedSpeed(const size_t microseconds) const;
|
2020-11-20 15:32:35 +00:00
|
|
|
|
2021-02-25 16:04:50 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
const bool myFixedSpeed;
|
|
|
|
std::chrono::time_point<std::chrono::steady_clock> myStartTime;
|
|
|
|
uint64_t myStartCycles;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|