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

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

@ -68,10 +68,10 @@ 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);
Kaleidoscope.setup (); void 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,
@ -32,7 +33,7 @@ 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,
@ -49,17 +50,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
S(N7), XXX, XXX, XXX, XXX, XXX, XXX, S(N7), XXX, XXX, XXX, XXX, XXX, XXX,
S(ST3), S(N8), S(N9), S(NA), S(NB), S(NC), XXX, S(ST3), S(N8), S(N9), S(NA), S(NB), S(NC), XXX,
S(ST3), S(FR), S(PR), S(LR), S(TR), S(DR), S(ST3), S(FR), S(PR), S(LR), S(TR), S(DR),
S(ST4), S(ST4), S(RR), S(BR), S(GR), S(SR), S(ZR), S(ST4), S(ST4), S(RR), S(BR), S(GR), S(SR), S(ZR),
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