Updated to use the new plugin APIs

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

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

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -17,11 +17,12 @@
*/
#include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-EEPROM-Keymap.h>
#include <Kaleidoscope-EEPROM-Keymap-Programmer.h>
#include <Kaleidoscope-Macros.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
@ -40,6 +41,7 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey),
};
// *INDENT-ON*
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 0 && keyToggledOff(keyState)) {
@ -49,11 +51,14 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
return MACRO_NONE;
}
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
EEPROMKeymapProgrammer,
EEPROMKeymap,
Macros);
void setup() {
Serial.begin(9600);
Kaleidoscope.use(&EEPROMKeymapProgrammer, &EEPROMKeymap, &Macros);
Kaleidoscope.setup();
Layer.getKey = EEPROMKeymap.getKey;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* 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;
Key EEPROMKeymapProgrammer::new_key_;
EEPROMKeymapProgrammer::EEPROMKeymapProgrammer(void) {
}
void EEPROMKeymapProgrammer::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void EEPROMKeymapProgrammer::nextState(void) {
switch (state_) {
case INACTIVE:
@ -56,9 +49,9 @@ void EEPROMKeymapProgrammer::cancel(void) {
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)
return mapped_key;
return EventHandlerResult::OK;
if (state_ == WAIT_FOR_KEY) {
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_)
nextState();
}
return Key_NoKey;
return EventHandlerResult::EVENT_CONSUMED;
}
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))
nextState();
}
return Key_NoKey;
return EventHandlerResult::EVENT_CONSUMED;
}
// WAIT_FOR_CODE state
if (mapped_key < Key_1 || mapped_key > Key_0)
return mapped_key;
return EventHandlerResult::OK;
if (!keyToggledOn(key_state))
return Key_NoKey;
if (!keyToggledOn(key_state)) {
return EventHandlerResult::EVENT_CONSUMED;
}
uint8_t n;
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;
return Key_NoKey;
return EventHandlerResult::EVENT_CONSUMED;
}
bool EEPROMKeymapProgrammer::focusHook(const char *command) {
@ -113,6 +107,20 @@ bool EEPROMKeymapProgrammer::focusHook(const char *command) {
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;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -22,7 +22,7 @@
#include <Kaleidoscope-EEPROM-Keymap.h>
namespace kaleidoscope {
class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
class EEPROMKeymapProgrammer : public kaleidoscope::Plugin {
public:
typedef enum {
CODE,
@ -30,9 +30,7 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
} mode_t;
static mode_t mode;
EEPROMKeymapProgrammer(void);
void begin(void) final;
EEPROMKeymapProgrammer(void) {}
static void activate(void) {
nextState();
@ -42,6 +40,14 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
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:
typedef enum {
INACTIVE,
@ -53,8 +59,6 @@ class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
static uint16_t update_position_; // layer, row, col
static Key new_key_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
}

Loading…
Cancel
Save