From bed79996aef214ec0d6f8f1d669252b7245b0179 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 5 Oct 2018 14:27:36 +0200 Subject: [PATCH] Update to use the new onFocusEvent APIs Signed-off-by: Gergely Nagy --- README.md | 14 +++----------- examples/FingerPainter/FingerPainter.ino | 2 +- src/Kaleidoscope/FingerPainter.cpp | 15 +++++++++------ src/Kaleidoscope/FingerPainter.h | 6 +----- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index bb613727..2523f793 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,7 @@ software (except to toggle edit mode on and off). ## Using the plugin -To use the plugin, just include the header, add it to the list of used plugins, -and register the `Focus` hooks: +To use the plugin, just include the header, add it to the list of used plugins. ```c++ #include @@ -28,7 +27,7 @@ and register the `Focus` hooks: #include #include #include -#include +#include KALEIDOSCOPE_INIT_PLUGINS(LEDControl, EEPromSettings, @@ -38,10 +37,6 @@ KALEIDOSCOPE_INIT_PLUGINS(LEDControl, void setup() { Kaleidoscope.setup(); - - EEPROMSettings.seal(); - - Focus.addHook(FOCUS_HOOK_FINGERPAINTER); } ``` @@ -51,9 +46,6 @@ The plugin provides the `FingerPainter` object, which provides no public methods ## Focus commands -The plugin provides a single `Focus` hook: `FOCUS_HOOK_FINGERPAINTER`, which -in turn provides the following commands: - ### `fingerpainter.clear` > Clears the canvas, so that one can start a new painting. @@ -65,7 +57,7 @@ in turn provides the following commands: ## Dependencies * [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) -* [Kaleidoscope-Focus](https://github.com/keyboardio/Kaleidoscope-Focus) +* [Kaleidoscope-FocusSerial](https://github.com/keyboardio/Kaleidoscope-FocusSerial) * [Kaleidoscope-LED-Palette-Theme][plugin:l-p-t] * [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl) diff --git a/examples/FingerPainter/FingerPainter.ino b/examples/FingerPainter/FingerPainter.ino index 5b9b132b..c5a13f66 100644 --- a/examples/FingerPainter/FingerPainter.ino +++ b/examples/FingerPainter/FingerPainter.ino @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include "LED-Off.h" diff --git a/src/Kaleidoscope/FingerPainter.cpp b/src/Kaleidoscope/FingerPainter.cpp index cefb8757..c9d72cea 100644 --- a/src/Kaleidoscope/FingerPainter.cpp +++ b/src/Kaleidoscope/FingerPainter.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -78,33 +78,36 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, byte row, by return EventHandlerResult::EVENT_CONSUMED; } -bool FingerPainter::focusHook(const char *command) { +EventHandlerResult FingerPainter::onFocusEvent(const char *command) { enum { TOGGLE, CLEAR, } sub_command; + if (::Focus.handleHelp(command, PSTR("fingerpainter.toggle\nfingerpainter.clear"))) + return EventHandlerResult::OK; + if (strncmp_P(command, PSTR("fingerpainter."), 14) != 0) - return false; + return EventHandlerResult::OK; if (strcmp_P(command + 14, PSTR("toggle")) == 0) sub_command = TOGGLE; else if (strcmp_P(command + 14, PSTR("clear")) == 0) sub_command = CLEAR; else - return false; + return EventHandlerResult::OK; if (sub_command == CLEAR) { for (uint16_t i = 0; i < ROWS * COLS / 2; i++) { EEPROM.update(color_base_ + i, 0); } - return true; + return EventHandlerResult::OK; } ::FingerPainter.activate(); toggle(); - return true; + return EventHandlerResult::OK; } } diff --git a/src/Kaleidoscope/FingerPainter.h b/src/Kaleidoscope/FingerPainter.h index 6a9fd8dd..78e099ca 100644 --- a/src/Kaleidoscope/FingerPainter.h +++ b/src/Kaleidoscope/FingerPainter.h @@ -25,9 +25,9 @@ class FingerPainter : public LEDMode { FingerPainter(void) {} static void toggle(void); - static bool focusHook(const char *command); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state); + EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onSetup(); protected: @@ -41,7 +41,3 @@ class FingerPainter : public LEDMode { }; extern kaleidoscope::FingerPainter FingerPainter; - -#define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \ - "fingerpainter.toggle\n" \ - "fingerpainter.clear")