mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2026-03-21 19:32:37 +01:00
borrwoed a lot code from https://github.com/foriequal0/devterm_keyboard in order to optimize the trackball
This commit is contained in:
30
Code/devterm_keyboard/tickwaiter.h
Normal file
30
Code/devterm_keyboard/tickwaiter.h
Normal 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
|
||||
Reference in New Issue
Block a user