From 407a30f5fd4de0591c573ebf622826b9763eb004 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 4 Jun 2017 11:05:55 +0200 Subject: [PATCH] Add an optional Focus hook Fixes #4. Signed-off-by: Gergely Nagy --- README.md | 9 +++++++++ src/Kaleidoscope/EEPROM-Keymap-Programmer.cpp | 12 ++++++++++++ src/Kaleidoscope/EEPROM-Keymap-Programmer.h | 9 ++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4668040a..fae5226a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,15 @@ The plugin provides the `EEPROMKeymapProgrammer` object, which has the following > > Defaults to `kaleidoscope::EEPROMKeymapProgrammer::CODE`. +## Focus commands + +The plugin provides a single `Focus` hook: `FOCUS_HOOK_KEYMAP_PROGRAMMER`, which +in turn provides the following command: + +### `keymap.toggleProgrammer` + +> Toggles the programmer mode on or off. + ## Dependencies * [Kaleidoscope-EEPROM-Keymap][plugin:eeprom-keymap] diff --git a/src/Kaleidoscope/EEPROM-Keymap-Programmer.cpp b/src/Kaleidoscope/EEPROM-Keymap-Programmer.cpp index 95ccff76..5a453449 100644 --- a/src/Kaleidoscope/EEPROM-Keymap-Programmer.cpp +++ b/src/Kaleidoscope/EEPROM-Keymap-Programmer.cpp @@ -101,6 +101,18 @@ Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col, return Key_NoKey; } +bool EEPROMKeymapProgrammer::focusHook(const char *command) { + if (strcmp_P(command, PSTR("keymap.toggleProgrammer")) != 0) + return false; + + if (state_ == INACTIVE) + activate(); + else + cancel(); + + return true; +} + } kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer; diff --git a/src/Kaleidoscope/EEPROM-Keymap-Programmer.h b/src/Kaleidoscope/EEPROM-Keymap-Programmer.h index 8032c6a9..d19d41b5 100644 --- a/src/Kaleidoscope/EEPROM-Keymap-Programmer.h +++ b/src/Kaleidoscope/EEPROM-Keymap-Programmer.h @@ -34,10 +34,14 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin { void begin(void) final; - static void activate(void) { nextState(); } + static void activate(void) { + nextState(); + } static void nextState(void); static void cancel(void); + static bool focusHook(const char *command); + private: typedef enum { INACTIVE, @@ -55,3 +59,6 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin { } extern kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer; + +#define FOCUS_HOOK_KEYMAP_PROGRAMMER FOCUS_HOOK(EEPROMKeymapProgrammer.focusHook, \ + "keymap.toggleProgrammer")