From bf1575b92870bd4d80b2f0087cb3610b2f49a08f Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 6 Nov 2013 17:38:06 -0600 Subject: [PATCH] switch to a more robust mechanism of looking for key release --- ArduinoKeyboard.ino | 111 +++++++++++++++++++++++++++++++++----------- 1 file changed, 83 insertions(+), 28 deletions(-) diff --git a/ArduinoKeyboard.ino b/ArduinoKeyboard.ino index 450727a7..99a89af8 100644 --- a/ArduinoKeyboard.ino +++ b/ArduinoKeyboard.ino @@ -15,14 +15,22 @@ static const int ROWS = 5; static int colPins[COLS] = { 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; static int rowPins[ROWS] = { A2, A3, A4, A5, 15 }; -byte matrixState[ROWS][COLS]; +byte matrixState[ROWS][COLS]; +// if we're sticking to boot protocol, these could all be 6 + mods +// but *mumble* +// + + +#define KEYS_HELD_BUFFER 12 +byte charsBeingReported[KEYS_HELD_BUFFER]; // A bit vector for the 256 keys we might conceivably be holding down +byte charsReportedLastTime[KEYS_HELD_BUFFER]; // A bit vector for the 256 keys we might conceivably be holding down -long counter = 0; -static const int LAYERS = 2; +long reporting_counter = 0; +static const int LAYERS = 2; int current_layer = 0; -int previous_keymap = 0; + static const Key keymaps[LAYERS][ROWS][COLS] = { { @@ -44,6 +52,45 @@ static const Key keymaps[LAYERS][ROWS][COLS] = { }; +void release_keys_not_being_pressed() { + + // we use charsReportedLastTime to figure out what we might not be holding anymore and can now release. this is destructive to charsReportedLastTime + + for (int i=0; i> 4)) ^ B00001111 ) { return false; @@ -109,6 +156,10 @@ void reset_matrix() { matrixState[row][col] <<= 1; } } + for (int i=0; i