Update to use the new onFocusEvent APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent d6a00e9b78
commit bed79996ae

@ -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 <Kaleidoscope.h>
@ -28,7 +27,7 @@ and register the `Focus` hooks:
#include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Focus.h>
#include <Kaleidoscope-FocusSerial.h>
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)

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

@ -18,7 +18,7 @@
#include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h>
#include <Kaleidoscope-FocusSerial.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
@ -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;
}
}

@ -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")

Loading…
Cancel
Save