2020-06-01 03:39:08 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
#include "../../ClockReceiver/TimeTypes.hpp"
|
|
|
|
|
2020-06-03 04:21:37 +00:00
|
|
|
#include <algorithm>
|
2020-06-01 03:39:08 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
Timer::Timer(QObject *parent) : QObject(parent) {}
|
|
|
|
|
2020-06-03 04:21:37 +00:00
|
|
|
void Timer::setMachine(MachineTypes::TimedMachine *machine) {
|
|
|
|
this->machine = machine;
|
|
|
|
}
|
|
|
|
|
2020-06-01 03:39:08 +00:00
|
|
|
void Timer::tick() {
|
2020-06-03 04:21:37 +00:00
|
|
|
const auto now = Time::nanos_now();
|
|
|
|
const auto duration = std::min(now - lastTickNanos, int64_t(500'000));
|
|
|
|
lastTickNanos = now;
|
|
|
|
|
|
|
|
machine->run_for(double(duration) / 1e9);
|
2020-06-01 03:39:08 +00:00
|
|
|
}
|