Updated to use the new plugin APIs

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

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

@ -1,7 +1,7 @@
/* -*- mode: c++ -*-
* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* 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
* it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
#include <Kaleidoscope.h>
#include <Kaleidoscope-Steno.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(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_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_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(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(E), S(U), XXX, S(RE2),
___),
};
// *INDENT-ON*
KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
void setup() {
Serial.begin(9600);
Kaleidoscope.use(&GeminiPR);
Kaleidoscope.setup();
}

@ -1,6 +1,6 @@
/* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* 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
* 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::state_[6];
void GeminiPR::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
Key GeminiPR::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
if (mapped_key < geminipr::START ||
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;
++keys_held_;
state_[key / 7] |= 1 << (6 - (key % 7));
} else if (keyToggledOff(key_state)) {
} else if (keyToggledOff(keyState)) {
--keys_held_;
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;
}
#endif
}
}

@ -1,6 +1,6 @@
/* Kaleidoscope-Steno -- Steno protocols for Kaleidoscope
* 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
* it under the terms of the GNU General Public License as published by
@ -25,17 +25,21 @@
namespace kaleidoscope {
namespace steno {
class GeminiPR : public KaleidoscopePlugin {
class GeminiPR : public kaleidoscope::Plugin {
public:
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:
static uint8_t keys_held_;
static uint8_t state_[6];
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
namespace geminipr {

Loading…
Cancel
Save