Use standard timeout checker for OneShot

Also, change timestamp from four bytes to two.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/642/head
Michael Richters 6 years ago
parent 196ac09629
commit 0b0e061563

@ -22,7 +22,7 @@ namespace plugin {
// ---- state ---------
uint32_t OneShot::start_time_ = 0;
uint16_t OneShot::start_time_ = 0;
uint16_t OneShot::time_out = 2500;
uint16_t OneShot::hold_time_out = 250;
int16_t OneShot::double_tap_time_out = -1;
@ -113,7 +113,7 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, byte row, byte col
} else {
if (keyToggledOff(keyState)) {
state_[idx].pressed = false;
if ((Kaleidoscope.millisAtCycleStart() - start_time_) >= hold_time_out) {
if (Kaleidoscope.hasTimeExpired(start_time_, hold_time_out)) {
cancelOneShot(idx);
should_cancel_ = false;
}
@ -123,8 +123,8 @@ EventHandlerResult OneShot::onKeyswitchEvent(Key &mapped_key, byte row, byte col
state_[idx].pressed = true;
if (prev_key_ == mapped_key && isStickable(mapped_key)) {
if ((Kaleidoscope.millisAtCycleStart() - start_time_) <=
uint16_t((double_tap_time_out == -1) ? time_out : double_tap_time_out)) {
uint16_t dtto = (double_tap_time_out == -1) ? time_out : double_tap_time_out;
if (!Kaleidoscope.hasTimeExpired(start_time_, dtto)) {
state_[idx].sticky = true;
prev_key_ = mapped_key;
}

@ -90,7 +90,7 @@ class OneShot : public kaleidoscope::Plugin {
} key_state_t;
static key_state_t state_[ONESHOT_KEY_COUNT];
static uint32_t start_time_;
static uint16_t start_time_;
static Key prev_key_;
static bool should_cancel_;
static bool should_cancel_stickies_;
@ -103,7 +103,7 @@ class OneShot : public kaleidoscope::Plugin {
return key.raw >= ranges::OS_FIRST && key.raw <= ranges::OS_LAST;
}
static bool hasTimedOut() {
return Kaleidoscope.millisAtCycleStart() - start_time_ >= time_out;
return Kaleidoscope.hasTimeExpired(start_time_, time_out);
}
};
}

Loading…
Cancel
Save