Merge pull request #17 from speedypotato/bugfix/rollover_cleanup

Cleanup of encoder rollover logic for mouse
This commit is contained in:
Nick G
2021-10-02 13:00:45 -07:00
committed by GitHub
2 changed files with 1 additions and 18 deletions
Binary file not shown.
+1 -18
View File
@@ -261,24 +261,7 @@ void key_mode() {
// find the delta between previous and current enc_val
int delta[ENC_GPIO_SIZE] = {0};
for (int i = 0; i < ENC_GPIO_SIZE; i++) {
int changeType; // -1 for negative 1 for positive
if (enc_val[i] > prev_enc_val[i]) { // if the new value is bigger its
// a positive change
delta[i] = enc_val[i] - prev_enc_val[i];
changeType = 1;
} else { // otherwise its a negative change
delta[i] = prev_enc_val[i] - enc_val[i];
changeType = -1;
}
// Overflow / Underflow
if (delta[i] > ENC_ROLLOVER) {
// Reverse the change type due to overflow / underflow
changeType *= -1;
delta[i] =
UINT32_MAX - delta[i] + 1; // this should give us how much we
// overflowed / underflowed by
}
delta[i] *= changeType * (ENC_REV[i] ? 1 : -1); // set direction
delta[i] = (enc_val[i] - prev_enc_val[i]) * (ENC_REV[i] ? 1 : -1);
prev_enc_val[i] = enc_val[i];
}
tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta[0], delta[1], 0, 0);