From 2ebf02d76a337c80168d4ec88fae6b8be0ab3651 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 26 Aug 2018 22:47:36 +0200 Subject: [PATCH] Simplify the shift tracking We do not need to track which shift is pressed, so lets use a bool instead of a bitfield. Makes the shift checking code smaller too! Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TopsyTurvy.cpp | 15 ++++++--------- src/Kaleidoscope/TopsyTurvy.h | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Kaleidoscope/TopsyTurvy.cpp b/src/Kaleidoscope/TopsyTurvy.cpp index a9831d2f..63b853ae 100644 --- a/src/Kaleidoscope/TopsyTurvy.cpp +++ b/src/Kaleidoscope/TopsyTurvy.cpp @@ -20,18 +20,15 @@ namespace kaleidoscope { -uint8_t TopsyTurvy::mod_state_; uint8_t TopsyTurvy::last_pressed_position_; +bool TopsyTurvy::is_shifted_; bool TopsyTurvy::is_active_; EventHandlerResult TopsyTurvy::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) { - if (mapped_key.raw == Key_LeftShift.raw) { - bitWrite(mod_state_, 0, keyIsPressed(key_state)); - if (is_active_) - return EventHandlerResult::EVENT_CONSUMED; - } - if (mapped_key.raw == Key_RightShift.raw) { - bitWrite(mod_state_, 1, keyIsPressed(key_state)); + + if (mapped_key == Key_LeftShift || + mapped_key == Key_RightShift) { + is_shifted_ = keyIsPressed(key_state); if (is_active_) return EventHandlerResult::EVENT_CONSUMED; } @@ -55,7 +52,7 @@ EventHandlerResult TopsyTurvy::onKeyswitchEvent(Key &mapped_key, byte row, byte is_active_ = keyIsPressed(key_state); // invert the shift state - if (!mod_state_) { + if (!is_shifted_) { mapped_key.raw = mapped_key.raw - ranges::TT_FIRST; mapped_key.flags |= SHIFT_HELD; return EventHandlerResult::OK; diff --git a/src/Kaleidoscope/TopsyTurvy.h b/src/Kaleidoscope/TopsyTurvy.h index 8ba92094..e97a9d64 100644 --- a/src/Kaleidoscope/TopsyTurvy.h +++ b/src/Kaleidoscope/TopsyTurvy.h @@ -31,8 +31,8 @@ class TopsyTurvy: public kaleidoscope::Plugin { EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); private: - static uint8_t mod_state_; static uint8_t last_pressed_position_; + static bool is_shifted_; static bool is_active_; };