Fix Qukeys minimum prior interval problem

The code for guarding against integer overflow on the prior interval timestamp
was in the wrong place, and wouldn't get executed on cycles when the keyboard
was idle, leading to a very slim chance of getting the wrong qukey value if all
keys were idle long enough (65 seconds).

Also fixed the same problem in the first quarter-second after the keyboard power
on. Not likely to ever be observed, but costs nothing extra to fix.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/971/head
Michael Richters 4 years ago
parent 9e1aaac3d8
commit 0d788bb718
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -118,6 +118,14 @@ EventHandlerResult Qukeys::beforeReportingState() {
}
}
// Next, if there hasn't been a keypress in a while, update the prior keypress
// timestamp to avoid integer overflow issues:
if (Runtime.hasTimeExpired(prior_keypress_timestamp_,
minimum_prior_interval_)) {
prior_keypress_timestamp_ =
Runtime.millisAtCycleStart() - (minimum_prior_interval_ + 1);
}
// If any events get flushed from the queue, stop there; we can only safely
// send the one report per cycle.
if (processQueue()) {
@ -134,14 +142,6 @@ EventHandlerResult Qukeys::beforeReportingState() {
queue_head_.primary_key : queue_head_.alternate_key;
flushEvent(event_key);
}
// Last, if there hasn't been a keypress in a while, update the prior keypress
// timestamp to avoid integer overflow issues:
if (Runtime.hasTimeExpired(prior_keypress_timestamp_,
minimum_prior_interval_)) {
prior_keypress_timestamp_ =
Runtime.millisAtCycleStart() - (minimum_prior_interval_ + 1);
}
return EventHandlerResult::OK;
}

@ -202,7 +202,10 @@ class Qukeys : public kaleidoscope::Plugin {
uint8_t minimum_prior_interval_{75};
// Timestamp of the keypress event immediately prior to the queue head event.
uint16_t prior_keypress_timestamp_{0};
// The initial value is 256 to ensure that it won't trigger an error if a
// qukey is pressed before `minimum_prior_interval_` milliseconds after the
// keyboard powers on, and that value can only be as high as 255.
uint16_t prior_keypress_timestamp_{256};
// This is a guard against re-processing events when qukeys flushes them from
// its event queue. We can't just use an "injected" key state flag, because

Loading…
Cancel
Save