From 684db7bd02ff25480bca031d17f06b0513cb31dc Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 8 Jun 2017 15:08:16 +0200 Subject: [PATCH] Handle one TopsyTurvy key / cycle To avoid duplicating keys, handle only one TopsyTurvy key / cycle. We handle the one with the highest index for the time being. Fixes #4. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TopsyTurvy.cpp | 11 +++++++++++ src/Kaleidoscope/TopsyTurvy.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/Kaleidoscope/TopsyTurvy.cpp b/src/Kaleidoscope/TopsyTurvy.cpp index 73295939..4d0ce21f 100644 --- a/src/Kaleidoscope/TopsyTurvy.cpp +++ b/src/Kaleidoscope/TopsyTurvy.cpp @@ -23,12 +23,14 @@ namespace kaleidoscope { uint8_t TopsyTurvy::mod_state_; +bool TopsyTurvy::is_active_; TopsyTurvy::TopsyTurvy(void) { } void TopsyTurvy::begin(void) { event_handler_hook_use(eventHandlerHook); + loop_hook_use(loopHook); } Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { @@ -46,6 +48,11 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST) return mapped_key; + if (is_active_) + return Key_NoKey; + + is_active_ = true; + Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST}; if (new_key.raw == Key_NoKey.raw) return mapped_key; @@ -75,6 +82,10 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key return Key_NoKey; } +void TopsyTurvy::loopHook(bool is_post_clear) { + is_active_ = false; +} + } kaleidoscope::TopsyTurvy TopsyTurvy; diff --git a/src/Kaleidoscope/TopsyTurvy.h b/src/Kaleidoscope/TopsyTurvy.h index be085c44..d3441399 100644 --- a/src/Kaleidoscope/TopsyTurvy.h +++ b/src/Kaleidoscope/TopsyTurvy.h @@ -32,8 +32,10 @@ class TopsyTurvy: public KaleidoscopePlugin { void begin(void) final; private: static uint8_t mod_state_; + static bool is_active_; static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); + static void loopHook(bool is_post_clear); }; }