Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent 1e95cf1429
commit 3da1061e19

@ -68,9 +68,9 @@ illustrated with an example:
// Somewhere in the keymap: // Somewhere in the keymap:
S(S1), S(S2), etc S(S1), S(S2), etc
void setup() { KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
Kaleidoscope.use(&GeminiPR);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
``` ```

@ -1,7 +1,7 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope * Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* Copyright (C) 2017 Joseph Wasson * Copyright (C) 2017 Joseph Wasson
* 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
@ -20,6 +20,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-Steno.h> #include <Kaleidoscope-Steno.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_NoKey, (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
@ -55,11 +56,12 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
S(E), S(U), XXX, S(RE2), S(E), S(U), XXX, S(RE2),
___), ___),
}; };
// *INDENT-ON*
KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&GeminiPR);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -1,6 +1,6 @@
/* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope /* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* Copyright (C) 2017 Joseph Wasson * Copyright (C) 2017 Joseph Wasson
* 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,21 +24,17 @@ namespace steno {
uint8_t GeminiPR::keys_held_; uint8_t GeminiPR::keys_held_;
uint8_t GeminiPR::state_[6]; uint8_t GeminiPR::state_[6];
void GeminiPR::begin(void) { EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
Key GeminiPR::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
if (mapped_key < geminipr::START || if (mapped_key < geminipr::START ||
mapped_key > geminipr::END) mapped_key > geminipr::END)
return mapped_key; return EventHandlerResult::OK;
if (keyToggledOn(key_state)) { if (keyToggledOn(keyState)) {
uint8_t key = mapped_key.raw - geminipr::START; uint8_t key = mapped_key.raw - geminipr::START;
++keys_held_; ++keys_held_;
state_[key / 7] |= 1 << (6 - (key % 7)); state_[key / 7] |= 1 << (6 - (key % 7));
} else if (keyToggledOff(key_state)) { } else if (keyToggledOff(keyState)) {
--keys_held_; --keys_held_;
if (keys_held_ == 0) { if (keys_held_ == 0) {
@ -48,8 +44,24 @@ Key GeminiPR::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_s
} }
} }
return EventHandlerResult::EVENT_CONSUMED;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void GeminiPR::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key GeminiPR::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::GeminiPR.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey; return Key_NoKey;
} }
#endif
} }
} }

@ -1,6 +1,6 @@
/* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope /* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* Copyright (C) 2017 Joseph Wasson * Copyright (C) 2017 Joseph Wasson
* 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
@ -25,17 +25,21 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace steno { namespace steno {
class GeminiPR : public KaleidoscopePlugin { class GeminiPR : public kaleidoscope::Plugin {
public: public:
GeminiPR(void) {} GeminiPR(void) {}
void begin(void); EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState);
#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:
static uint8_t keys_held_; static uint8_t keys_held_;
static uint8_t state_[6]; static uint8_t state_[6];
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
namespace geminipr { namespace geminipr {

Loading…
Cancel
Save