From 7213f7577a1fc011f0f4c598862f2acc08fa0a50 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 15 Mar 2018 09:32:31 +0100 Subject: [PATCH] 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 --- src/Kaleidoscope-Hardware-Model01.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Kaleidoscope-Hardware-Model01.cpp b/src/Kaleidoscope-Hardware-Model01.cpp index 8e88f2da..2fc7df61 100644 --- a/src/Kaleidoscope-Hardware-Model01.cpp +++ b/src/Kaleidoscope-Hardware-Model01.cpp @@ -158,16 +158,13 @@ void Model01::readMatrix() { } void Model01::actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos) { - if ((colState == colPrevState) && (colState == 0)) { - for (byte col = 0; col < 8; col++) { - handleKeyswitchEvent(Key_NoKey, row, startPos - col, 0); - } - } else { + if ((colState != colPrevState) || (colState != 0)) { for (byte col = 0; col < 8; col++) { // Build up the key state for row, col uint8_t keyState = ((bitRead(colPrevState, 0) << 0) | (bitRead(colState, 0) << 1)); - handleKeyswitchEvent(Key_NoKey, row, startPos - col, keyState); + if (keyState) + handleKeyswitchEvent(Key_NoKey, row, startPos - col, keyState); // Throw away the data we've just used, so we can read the next column colState = colState >> 1;