Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 500ffc25fc
commit 6602b30d0a

@ -73,9 +73,12 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE; return MACRO_NONE;
} }
void setup() { KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
Kaleidoscope.use(&EEPROMKeymapProgrammer, &EEPROMKeymap, &Macros); EEPROMKeymapProgrammer,
EEPROMKeymap,
Macros);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
Layer.getKey = EEPROMKeymap.getKey; Layer.getKey = EEPROMKeymap.getKey;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap. * Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap.
* 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
@ -17,11 +17,12 @@
*/ */
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
#include <Kaleidoscope-EEPROM-Keymap-Programmer.h> #include <Kaleidoscope-EEPROM-Keymap-Programmer.h>
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Macros.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
(M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, (M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
@ -34,12 +35,13 @@ 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_NoKey), Key_NoKey),
}; };
// *INDENT-ON*
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 0 && keyToggledOff(keyState)) { if (macroIndex == 0 && keyToggledOff(keyState)) {
@ -49,11 +51,14 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE; return MACRO_NONE;
} }
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
EEPROMKeymapProgrammer,
EEPROMKeymap,
Macros);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&EEPROMKeymapProgrammer, &EEPROMKeymap, &Macros);
Kaleidoscope.setup(); Kaleidoscope.setup();
Layer.getKey = EEPROMKeymap.getKey; Layer.getKey = EEPROMKeymap.getKey;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap. * Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap.
* 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
@ -24,13 +24,6 @@ EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state_;
EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode; EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode;
Key EEPROMKeymapProgrammer::new_key_; Key EEPROMKeymapProgrammer::new_key_;
EEPROMKeymapProgrammer::EEPROMKeymapProgrammer(void) {
}
void EEPROMKeymapProgrammer::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void EEPROMKeymapProgrammer::nextState(void) { void EEPROMKeymapProgrammer::nextState(void) {
switch (state_) { switch (state_) {
case INACTIVE: case INACTIVE:
@ -56,9 +49,9 @@ void EEPROMKeymapProgrammer::cancel(void) {
state_ = INACTIVE; state_ = INACTIVE;
} }
Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult EEPROMKeymapProgrammer::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (state_ == INACTIVE) if (state_ == INACTIVE)
return mapped_key; return EventHandlerResult::OK;
if (state_ == WAIT_FOR_KEY) { if (state_ == WAIT_FOR_KEY) {
if (keyToggledOn(key_state)) { if (keyToggledOn(key_state)) {
@ -68,7 +61,7 @@ Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col,
if ((uint16_t)(Layer.top() * ROWS * COLS + row * COLS + col) == update_position_) if ((uint16_t)(Layer.top() * ROWS * COLS + row * COLS + col) == update_position_)
nextState(); nextState();
} }
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
if (state_ == WAIT_FOR_SOURCE_KEY) { if (state_ == WAIT_FOR_SOURCE_KEY) {
@ -79,16 +72,17 @@ Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col,
if (new_key_ == Layer.getKeyFromPROGMEM(Layer.top(), row, col)) if (new_key_ == Layer.getKeyFromPROGMEM(Layer.top(), row, col))
nextState(); nextState();
} }
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
// WAIT_FOR_CODE state // WAIT_FOR_CODE state
if (mapped_key < Key_1 || mapped_key > Key_0) if (mapped_key < Key_1 || mapped_key > Key_0)
return mapped_key; return EventHandlerResult::OK;
if (!keyToggledOn(key_state)) if (!keyToggledOn(key_state)) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
}
uint8_t n; uint8_t n;
if (mapped_key.keyCode == Key_0.keyCode) if (mapped_key.keyCode == Key_0.keyCode)
@ -98,7 +92,7 @@ Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col,
new_key_.raw = new_key_.raw * 10 + n; new_key_.raw = new_key_.raw * 10 + n;
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
bool EEPROMKeymapProgrammer::focusHook(const char *command) { bool EEPROMKeymapProgrammer::focusHook(const char *command) {
@ -113,6 +107,20 @@ bool EEPROMKeymapProgrammer::focusHook(const char *command) {
return true; return true;
} }
// Legacy API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void EEPROMKeymapProgrammer::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key EEPROMKeymapProgrammer::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::EEPROMKeymapProgrammer.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
} }
kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer; kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap. * Kaleidoscope-EEPROM-Keymap-Programmer -- On-the-fly reprogrammable keymap.
* 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
@ -22,7 +22,7 @@
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
namespace kaleidoscope { namespace kaleidoscope {
class EEPROMKeymapProgrammer : public KaleidoscopePlugin { class EEPROMKeymapProgrammer : public kaleidoscope::Plugin {
public: public:
typedef enum { typedef enum {
CODE, CODE,
@ -30,9 +30,7 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
} mode_t; } mode_t;
static mode_t mode; static mode_t mode;
EEPROMKeymapProgrammer(void); EEPROMKeymapProgrammer(void) {}
void begin(void) final;
static void activate(void) { static void activate(void) {
nextState(); nextState();
@ -42,6 +40,14 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
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);
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
private: private:
typedef enum { typedef enum {
INACTIVE, INACTIVE,
@ -53,8 +59,6 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
static uint16_t update_position_; // layer, row, col static uint16_t update_position_; // layer, row, col
static Key new_key_; static Key new_key_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
} }

Loading…
Cancel
Save