Merge pull request #8 from keyboardio/f/plugin-v2

Updated to use the new plugin APIs
pull/389/head
Gergely Nagy 6 years ago committed by GitHub
commit 4934c4e2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,13 +24,19 @@ and register the `Focus` hooks:
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.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-Focus.h>
void setup() { KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
Kaleidoscope.use(&EEPROMSettings, &FingerPainter, &Focus); EEPromSettings,
LEDPaletteTheme,
FingerPainter,
Focus);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
EEPROMSettings.seal(); EEPROMSettings.seal();

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-FingerPainter -- On-the-fly keyboard painting. * Kaleidoscope-FingerPainter -- On-the-fly keyboard painting.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,12 +18,14 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.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-Focus.h>
#include "LED-Off.h" #include "LED-Off.h"
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
(Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
@ -36,16 +38,22 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip), Key_skip),
}; };
// *INDENT-ON*
void setup() { KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
Kaleidoscope.use(&LEDOff, &EEPROMSettings, &FingerPainter, &Focus); LEDOff,
EEPROMSettings,
LEDPaletteTheme,
FingerPainter,
Focus);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
EEPROMSettings.seal(); EEPROMSettings.seal();

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-FingerPainter -- On-the-fly keyboard painting. * Kaleidoscope-FingerPainter -- On-the-fly keyboard painting.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,11 +28,9 @@ namespace kaleidoscope {
uint16_t FingerPainter::color_base_; uint16_t FingerPainter::color_base_;
bool FingerPainter::edit_mode_; bool FingerPainter::edit_mode_;
void FingerPainter::setup(void) { EventHandlerResult FingerPainter::onSetup() {
Kaleidoscope.use(&::LEDPaletteTheme);
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
color_base_ = ::LEDPaletteTheme.reserveThemes(1); color_base_ = ::LEDPaletteTheme.reserveThemes(1);
return EventHandlerResult::OK;
} }
void FingerPainter::update(void) { void FingerPainter::update(void) {
@ -47,15 +45,16 @@ void FingerPainter::toggle(void) {
edit_mode_ = !edit_mode_; edit_mode_ = !edit_mode_;
} }
Key FingerPainter::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (!edit_mode_) if (!edit_mode_)
return mapped_key; return EventHandlerResult::OK;
if (!keyToggledOn(key_state)) if (!keyToggledOn(key_state)) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
}
if (row >= ROWS || col >= COLS) if (row >= ROWS || col >= COLS)
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(row, col)); uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(row, col));
@ -76,7 +75,7 @@ Key FingerPainter::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t
::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(row, col), color_index); ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(row, col), color_index);
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
bool FingerPainter::focusHook(const char *command) { bool FingerPainter::focusHook(const char *command) {
@ -108,6 +107,20 @@ bool FingerPainter::focusHook(const char *command) {
return true; return true;
} }
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void FingerPainter::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key FingerPainter::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::FingerPainter.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
} }
kaleidoscope::FingerPainter FingerPainter; kaleidoscope::FingerPainter FingerPainter;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-FingerPainter -- On-the-fly keyboard painting. * Kaleidoscope-FingerPainter -- On-the-fly keyboard painting.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -28,16 +28,21 @@ class FingerPainter : public LEDMode {
static void toggle(void); static void toggle(void);
static bool focusHook(const char *command); static bool focusHook(const char *command);
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
EventHandlerResult onSetup();
protected: protected:
void setup(void) final;
void update(void) final; void update(void) final;
void refreshAt(byte row, byte col) final; void refreshAt(byte row, byte col) final;
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void begin();
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
private: private:
static uint16_t color_base_; static uint16_t color_base_;
static bool edit_mode_; static bool edit_mode_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
}; };

Loading…
Cancel
Save