borrwoed a lot code from https://github.com/foriequal0/devterm_keyboard in order to optimize the trackball

This commit is contained in:
cuu
2021-12-16 20:41:37 +08:00
parent 1a1be01dbb
commit b1370d2124
18 changed files with 538 additions and 118 deletions

View File

@@ -0,0 +1,30 @@
#ifndef TICKWAITER_H
#define TICKWAITER_H
#include <cstdint>
#include "math.h"
template<uint32_t TargetInterval>
class TickWaiter {
public:
uint8_t waitForNextTick() {
const auto last = this->last;
const auto now = millis();
this->last = now;
const auto delta = getDelta(last, now, 255);
if (delta >= TargetInterval) {
return delta;
}
delay(TargetInterval - delta);
const auto now2 = millis();
return getDelta(last, now2, 255);
}
private:
uint32_t last = 0;
};
#endif