Guarantee that the first key in the queue is an undetermined qukey (#34)

This will make a few tests simpler because we can assume that if the queue isn't empty, the head of the queue is a valid Qukey (or DualUse Key).
pull/389/head
Michael Richters 7 years ago committed by GitHub
parent 8adc1d94a9
commit 1828c9fa2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,12 +32,21 @@
namespace kaleidoscope {
inline
bool isDualUse(Key k) {
if (k.raw < ranges::DU_FIRST || k.raw > ranges::DU_LAST)
return false;
return true;
}
inline
bool isDualUse(byte key_addr) {
byte row = addr::row(key_addr);
byte col = addr::col(key_addr);
Key k = Layer.lookup(row, col);
return isDualUse(k);
}
Key getDualUsePrimaryKey(Key k) {
if (k.raw >= ranges::DUM_FIRST && k.raw <= ranges::DUM_LAST) {
k.raw -= ranges::DUM_FIRST;
@ -195,9 +204,10 @@ void Qukeys::flushQueue(int8_t index) {
}
// Flush all the non-qukey keys from the front of the queue
void Qukeys::flushQueue(void) {
void Qukeys::flushQueue() {
// flush keys until we find a qukey:
while (key_queue_length_ > 0 &&
! isDualUse(key_queue_[0].addr) &&
lookupQukey(key_queue_[0].addr) == QUKEY_NOT_FOUND) {
flushKey(QUKEY_STATE_PRIMARY, IS_PRESSED | WAS_PRESSED);
}
@ -266,6 +276,7 @@ Key Qukeys::keyScanHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
return mapped_key;
}
flushQueue(queue_index);
flushQueue();
return Key_NoKey;
}
@ -301,20 +312,13 @@ Key Qukeys::keyScanHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
void Qukeys::preReportHook(void) {
// If the qukey has been held longer than the time limit, set its
// state to the alternate keycode and add it to the report
uint16_t current_time = (uint16_t)millis();
while (key_queue_length_ > 0) {
byte row = addr::row(key_queue_[0].addr);
byte col = addr::col(key_queue_[0].addr);
Key keycode = Layer.lookup(row, col);
bool is_dual_use = isDualUse(keycode);
if (lookupQukey(key_queue_[0].addr) != QUKEY_NOT_FOUND || is_dual_use) {
if ((current_time - key_queue_[0].start_time) > time_limit_) {
flushKey(QUKEY_STATE_ALTERNATE, IS_PRESSED | WAS_PRESSED);
} else {
break;
}
uint16_t current_time = millis();
if ((current_time - key_queue_[0].start_time) > time_limit_) {
flushKey(QUKEY_STATE_ALTERNATE, IS_PRESSED | WAS_PRESSED);
flushQueue();
} else {
flushKey(QUKEY_STATE_PRIMARY, IS_PRESSED | WAS_PRESSED);
break;
}
}
}

Loading…
Cancel
Save