mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2026-03-19 18:32:39 +01:00
borrwoed a lot code from https://github.com/foriequal0/devterm_keyboard in order to optimize the trackball
This commit is contained in:
23
Code/devterm_keyboard/math.ino
Normal file
23
Code/devterm_keyboard/math.ino
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <limits>
|
||||
|
||||
#include "math.h"
|
||||
|
||||
uint32_t getDelta(uint32_t prev, uint32_t now) {
|
||||
uint32_t delta;
|
||||
if (now >= prev) {
|
||||
delta = now - prev;
|
||||
} else {
|
||||
delta = std::numeric_limits<uint32_t>().max() - prev - now + 1;
|
||||
}
|
||||
return delta;
|
||||
}
|
||||
|
||||
uint32_t getDelta(uint32_t prev, uint32_t now, uint32_t max) {
|
||||
const auto delta = getDelta(prev, now);
|
||||
|
||||
if (delta < max) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
Reference in New Issue
Block a user