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