Merge pull request #10 from keyboardio/f/onFocusEvent

Update to use the new onFocusEvent APIs
pull/389/head
Jesse Vincent 6 years ago committed by GitHub
commit ccfb53bf4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,8 +19,7 @@ software (except to toggle edit mode on and off).
## Using the plugin ## Using the plugin
To use the plugin, just include the header, add it to the list of used plugins, To use the plugin, just include the header, add it to the list of used plugins.
and register the `Focus` hooks:
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
@ -28,7 +27,7 @@ and register the `Focus` hooks:
#include <Kaleidoscope-LED-Palette-Theme.h> #include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h> #include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-FocusSerial.h>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
EEPromSettings, EEPromSettings,
@ -38,10 +37,6 @@ KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
void setup() { void setup() {
Kaleidoscope.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 ## Focus commands
The plugin provides a single `Focus` hook: `FOCUS_HOOK_FINGERPAINTER`, which
in turn provides the following commands:
### `fingerpainter.clear` ### `fingerpainter.clear`
> Clears the canvas, so that one can start a new painting. > Clears the canvas, so that one can start a new painting.
@ -65,7 +57,7 @@ in turn provides the following commands:
## Dependencies ## Dependencies
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) * [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-LED-Palette-Theme][plugin:l-p-t]
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl) * [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)

@ -20,7 +20,7 @@
#include <Kaleidoscope-LED-Palette-Theme.h> #include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h> #include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-FocusSerial.h>
#include "LED-Off.h" #include "LED-Off.h"

@ -18,7 +18,7 @@
#include <Kaleidoscope-FingerPainter.h> #include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-FocusSerial.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h> #include <Kaleidoscope-LED-Palette-Theme.h>
@ -78,33 +78,36 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, byte row, by
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
bool FingerPainter::focusHook(const char *command) { EventHandlerResult FingerPainter::onFocusEvent(const char *command) {
enum { enum {
TOGGLE, TOGGLE,
CLEAR, CLEAR,
} sub_command; } sub_command;
if (::Focus.handleHelp(command, PSTR("fingerpainter.toggle\nfingerpainter.clear")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("fingerpainter."), 14) != 0) if (strncmp_P(command, PSTR("fingerpainter."), 14) != 0)
return false; return EventHandlerResult::OK;
if (strcmp_P(command + 14, PSTR("toggle")) == 0) if (strcmp_P(command + 14, PSTR("toggle")) == 0)
sub_command = TOGGLE; sub_command = TOGGLE;
else if (strcmp_P(command + 14, PSTR("clear")) == 0) else if (strcmp_P(command + 14, PSTR("clear")) == 0)
sub_command = CLEAR; sub_command = CLEAR;
else else
return false; return EventHandlerResult::OK;
if (sub_command == CLEAR) { if (sub_command == CLEAR) {
for (uint16_t i = 0; i < ROWS * COLS / 2; i++) { for (uint16_t i = 0; i < ROWS * COLS / 2; i++) {
EEPROM.update(color_base_ + i, 0); EEPROM.update(color_base_ + i, 0);
} }
return true; return EventHandlerResult::OK;
} }
::FingerPainter.activate(); ::FingerPainter.activate();
toggle(); toggle();
return true; return EventHandlerResult::OK;
} }
} }

@ -25,9 +25,9 @@ class FingerPainter : public LEDMode {
FingerPainter(void) {} FingerPainter(void) {}
static void toggle(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 onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onSetup(); EventHandlerResult onSetup();
protected: protected:
@ -41,7 +41,3 @@ class FingerPainter : public LEDMode {
}; };
extern kaleidoscope::FingerPainter FingerPainter; extern kaleidoscope::FingerPainter FingerPainter;
#define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \
"fingerpainter.toggle\n" \
"fingerpainter.clear")

Loading…
Cancel
Save