Don't abort early on partial matches

If we find a partial match, do not abort, but continue until we either find a
full match, a mismatch, or until we time out. This make it possible to have gaps
in the sequence, where a partial sequence has no explicit handler.

Fixes #1.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 4070116b2a
commit 0abf80a499

@ -30,6 +30,9 @@ namespace Akela {
// --- helpers ---
#define PARTIAL_MATCH -1
#define NO_MATCH -2
#define isLeader(k) (k.raw >= LEAD_FIRST && k.raw <= LEAD_LAST)
#define isActive() (sequence[0].raw != Key_NoKey.raw)
@ -60,10 +63,12 @@ namespace Akela {
seqKey.raw = pgm_read_word (&(dictionary[seqIndex].sequence[sequencePos + 1].raw));
if (seqKey.raw == Key_NoKey.raw) {
return seqIndex;
} else {
return PARTIAL_MATCH;
}
}
return -1;
return NO_MATCH;
}
// --- api ---
@ -136,22 +141,20 @@ namespace Akela {
sequence[sequencePos].raw = mappedKey.raw;
actionIndex = lookup ();
if (actionIndex < 0) {
// No match, abort and pass it through.
reset ();
return mappedKey;
}
return Key_NoKey;
if (actionIndex >= 0)
return Key_NoKey;
} else if (key_is_pressed (keyState)) {
// held, no need for anything here.
return Key_NoKey;
}
if (actionIndex < 0) {
// No match, abort and pass it through.
if (actionIndex == NO_MATCH) {
reset ();
return mappedKey;
}
if (actionIndex == PARTIAL_MATCH) {
return Key_NoKey;
}
action_t leaderAction = (action_t) pgm_read_ptr (&(dictionary[actionIndex].action));
(*leaderAction) (actionIndex);

Loading…
Cancel
Save