actOnHalfRow: Do not handle events on fully idle positions

When a keyswitch has been off in the previous cycle and is still off now, do not
call `handleKeyswitchEvent` on it. As an extension, when the whole column is
idle, skip the whole thing.

In practice, handling fully idle keys is not useful. There are many plugins
which explicitly look for this case and return early, because it isn't an
interesting event. As such, not calling the event handler in this case makes
sense, as we save not only a few needless checks in plugins, but our performance
improves greatly too.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 7 years ago
parent 766c61ec96
commit 7213f7577a

@ -158,15 +158,12 @@ void Model01::readMatrix() {
} }
void Model01::actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos) { void Model01::actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos) {
if ((colState == colPrevState) && (colState == 0)) { if ((colState != colPrevState) || (colState != 0)) {
for (byte col = 0; col < 8; col++) {
handleKeyswitchEvent(Key_NoKey, row, startPos - col, 0);
}
} else {
for (byte col = 0; col < 8; col++) { for (byte col = 0; col < 8; col++) {
// Build up the key state for row, col // Build up the key state for row, col
uint8_t keyState = ((bitRead(colPrevState, 0) << 0) | uint8_t keyState = ((bitRead(colPrevState, 0) << 0) |
(bitRead(colState, 0) << 1)); (bitRead(colState, 0) << 1));
if (keyState)
handleKeyswitchEvent(Key_NoKey, row, startPos - col, keyState); handleKeyswitchEvent(Key_NoKey, row, startPos - col, keyState);
// Throw away the data we've just used, so we can read the next column // Throw away the data we've just used, so we can read the next column

Loading…
Cancel
Save