From 0e573229031cc92845c2a1e19652231b200c2bbc Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 9 Jun 2018 21:18:02 +0200 Subject: [PATCH] Implement getKeyswitchStateAtPosition Signed-off-by: Gergely Nagy --- src/kaleidoscope/hardware/ErgoDox.cpp | 9 +++++++++ src/kaleidoscope/hardware/ErgoDox.h | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/kaleidoscope/hardware/ErgoDox.cpp b/src/kaleidoscope/hardware/ErgoDox.cpp index 7fc5728e..5b1ae01f 100644 --- a/src/kaleidoscope/hardware/ErgoDox.cpp +++ b/src/kaleidoscope/hardware/ErgoDox.cpp @@ -225,6 +225,15 @@ void ErgoDox::attachToHost() { UDCON &= ~(1 << DETACH); } +uint8_t ErgoDox::getKeyswitchStateAtPosition(byte row, byte col) { + return bitRead(keyState_[row], col); +} + +uint8_t ErgoDox::getKeyswitchStateAtPosition(uint8_t keyIndex) { + keyIndex--; + return getKeyswitchStateAtPosition(keyIndex / COLS, keyIndex % COLS); +} + } } diff --git a/src/kaleidoscope/hardware/ErgoDox.h b/src/kaleidoscope/hardware/ErgoDox.h index f46f3cf1..fbf63d80 100644 --- a/src/kaleidoscope/hardware/ErgoDox.h +++ b/src/kaleidoscope/hardware/ErgoDox.h @@ -87,6 +87,18 @@ class ErgoDox { void unMaskKey(byte row, byte col); bool isKeyMasked(byte row, byte col); + /** Key switch state + * + * These two methods return the state of the keyswitch at any given position, + * regardless of which half they are on. This is a hardware-agnostic access to + * the key switch states. + * + * The first variant requires a row and a column, the second an index, as + * returned by `keyIndex`. + */ + uint8_t getKeyswitchStateAtPosition(byte row, byte col); + uint8_t getKeyswitchStateAtPosition(uint8_t keyIndex); + // ErgoDox-specific stuff void setStatusLED(uint8_t led, bool state = true); void setStatusLEDBrightness(uint8_t led, uint8_t brightness);