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:
S(S1), S(S2), etc
void setup() {
Kaleidoscope.use(&GeminiPR);
KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
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,
@ -55,11 +56,12 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
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