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 b1c4db4a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,11 +50,10 @@ void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
} }
} }
KALEIDOSCOPE_INIT_PLUGINS(Unicode, Syster);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&Unicode, &Syster);
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Syster -- Symbolic input system * Kaleidoscope-Syster -- Symbolic input system
* 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
@ -23,6 +23,7 @@
#include <Kaleidoscope-Unicode.h> #include <Kaleidoscope-Unicode.h>
#include <kaleidoscope/hid.h> #include <kaleidoscope/hid.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
@ -36,12 +37,13 @@ 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,
SYSTER), SYSTER),
}; };
// *INDENT-ON*
void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) { void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
switch (action) { switch (action) {
@ -64,9 +66,11 @@ void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
} }
} }
void setup() { KALEIDOSCOPE_INIT_PLUGINS(HostOS,
Kaleidoscope.use(&Unicode, &Syster); Unicode,
Syster);
void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Syster -- Symbolic input system * Kaleidoscope-Syster -- Symbolic input system
* 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
@ -32,14 +32,6 @@ bool Syster::is_active_;
#define isSyster(k) (k == kaleidoscope::ranges::SYSTER) #define isSyster(k) (k == kaleidoscope::ranges::SYSTER)
// --- api --- // --- api ---
Syster::Syster(void) {
}
void Syster::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void Syster::reset(void) { void Syster::reset(void) {
symbol_pos_ = 0; symbol_pos_ = 0;
symbol_[0] = 0; symbol_[0] = 0;
@ -51,28 +43,30 @@ bool Syster::is_active(void) {
} }
// --- hooks --- // --- hooks ---
Key Syster::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { EventHandlerResult Syster::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t keyState) {
if (!is_active_) { if (!is_active_) {
if (!isSyster(mapped_key)) if (!isSyster(mapped_key))
return mapped_key; return EventHandlerResult::OK;
if (keyToggledOn(key_state)) { if (keyToggledOn(keyState)) {
is_active_ = true; is_active_ = true;
systerAction(StartAction, NULL); systerAction(StartAction, NULL);
} }
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
if (key_state & INJECTED) if (keyState & INJECTED)
return mapped_key; return EventHandlerResult::OK;
if (isSyster(mapped_key)) if (isSyster(mapped_key)) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
}
if (mapped_key == Key_Backspace && symbol_pos_ == 0) if (mapped_key == Key_Backspace && symbol_pos_ == 0) {
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
}
if (keyToggledOff(key_state)) { if (keyToggledOff(keyState)) {
if (mapped_key == Key_Spacebar) { if (mapped_key == Key_Spacebar) {
for (uint8_t i = 0; i <= symbol_pos_; i++) { for (uint8_t i = 0; i <= symbol_pos_; i++) {
handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); handleKeyswitchEvent(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
@ -87,11 +81,11 @@ Key Syster::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_sta
systerAction(SymbolAction, symbol_); systerAction(SymbolAction, symbol_);
reset(); reset();
return Key_NoKey; return EventHandlerResult::EVENT_CONSUMED;
} }
} }
if (keyToggledOn(key_state)) { if (keyToggledOn(keyState)) {
if (mapped_key == Key_Backspace) { if (mapped_key == Key_Backspace) {
if (symbol_pos_ > 0) if (symbol_pos_ > 0)
symbol_pos_--; symbol_pos_--;
@ -102,8 +96,23 @@ Key Syster::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_sta
} }
} }
return mapped_key; return EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void Syster::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key Syster::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::Syster.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
} }
#endif
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-Syster -- Symbolic input system * Kaleidoscope-Syster -- Symbolic input system
* 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
@ -27,7 +27,7 @@
namespace kaleidoscope { namespace kaleidoscope {
class Syster : public KaleidoscopePlugin { class Syster : public kaleidoscope::Plugin {
public: public:
typedef enum { typedef enum {
StartAction, StartAction,
@ -35,19 +35,24 @@ class Syster : public KaleidoscopePlugin {
SymbolAction SymbolAction
} action_t; } action_t;
Syster(void); Syster(void) {}
void begin(void) final;
static void reset(void); static void reset(void);
bool is_active(void); bool is_active(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 char symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1]; static char symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1];
static uint8_t symbol_pos_; static uint8_t symbol_pos_;
static bool is_active_; static bool is_active_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
}; };

Loading…
Cancel
Save