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 <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent a3f7ab082d
commit 684db7bd02

@ -23,12 +23,14 @@
namespace kaleidoscope { namespace kaleidoscope {
uint8_t TopsyTurvy::mod_state_; uint8_t TopsyTurvy::mod_state_;
bool TopsyTurvy::is_active_;
TopsyTurvy::TopsyTurvy(void) { TopsyTurvy::TopsyTurvy(void) {
} }
void TopsyTurvy::begin(void) { void TopsyTurvy::begin(void) {
event_handler_hook_use(eventHandlerHook); event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
} }
Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { 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) if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST)
return mapped_key; return mapped_key;
if (is_active_)
return Key_NoKey;
is_active_ = true;
Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST}; Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST};
if (new_key.raw == Key_NoKey.raw) if (new_key.raw == Key_NoKey.raw)
return mapped_key; return mapped_key;
@ -75,6 +82,10 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
return Key_NoKey; return Key_NoKey;
} }
void TopsyTurvy::loopHook(bool is_post_clear) {
is_active_ = false;
}
} }
kaleidoscope::TopsyTurvy TopsyTurvy; kaleidoscope::TopsyTurvy TopsyTurvy;

@ -32,8 +32,10 @@ class TopsyTurvy: public KaleidoscopePlugin {
void begin(void) final; void begin(void) final;
private: private:
static uint8_t mod_state_; static uint8_t mod_state_;
static bool is_active_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
static void loopHook(bool is_post_clear);
}; };
} }

Loading…
Cancel
Save