From 741793c29827b650d15a23cad271633bec25e48f Mon Sep 17 00:00:00 2001 From: KemoNine Date: Tue, 8 Sep 2020 22:14:28 -0400 Subject: [PATCH] Refine keyboard handling lightly --- serial_debugger.ino | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/serial_debugger.ino b/serial_debugger.ino index 3e7a71b..f2d6703 100644 --- a/serial_debugger.ino +++ b/serial_debugger.ino @@ -59,6 +59,13 @@ BBQ10Keyboard keyboard; #define KBD_SW_RT 0x04 #define KBD_SW_OK 0x05 +// Upstream keyboard definitions that will be really important later +#define _REG_CFG 2 +#define CFG_OVERFLOW_INT (1 << 1) +#define CFG_KEY_INT (1 << 4) +#define CFG_USE_MODS (1 << 7) // Should Alt, Sym and Shifts modify the keys reported +#define CFG_REPORT_MODS (1 << 6) // Should Alt, Sym and Shifts be reported as well + // NeoPixels #define PIXELS_NUM_BOARD 1 #define PIXELS_NUM_WING 1 @@ -133,6 +140,8 @@ void setup() { // Setup BBQ10Keyboard Wire.begin(); keyboard.begin(); + keyboard.writeRegister(_REG_CFG, CFG_OVERFLOW_INT | CFG_KEY_INT | CFG_USE_MODS | CFG_REPORT_MODS); + keyboard.setBacklight(0.5f); // GUI Slice (TFT is setup through GUI Slice) @@ -172,8 +181,13 @@ void processRingBuffer() { // Keyboard handler void handlerKeyboard() { - // Check if keys were pressed - if (keyboard.keyCount()) { + // Don't do anything if there are no key presses to process + if (keyboard.keyCount() == 0) { + return; + } + + // Check if keys were pressed and drain queue of pressed keys + while (keyboard.keyCount() > 0) { // Get keyboard event const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent();