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

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

@ -21,11 +21,14 @@ This can be done from a macro, or via the `AlphaSquareEffect` LED mode.
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-AlphaSquare.h>
void setup() {
Kaleidoscope.use(&AlphaSquare, &AlphaSquareEffect);
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
AlphaSquare,
AlphaSquareEffect);
void setup() {
Kaleidoscope.setup();
AlphaSquare.display (Key_A);

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-AlphaSquare -- 4x4 pixel LED alphabet
* 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
@ -21,6 +21,7 @@
#include <Kaleidoscope-LED-AlphaSquare.h>
#include <Kaleidoscope-Macros.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
@ -40,6 +41,7 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip),
};
// *INDENT-ON*
const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (!keyToggledOn(key_state))
@ -93,9 +95,12 @@ const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
return MACRO_NONE;
}
void setup() {
Kaleidoscope.use(&AlphaSquare, &AlphaSquareEffect, &Macros);
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
AlphaSquare,
AlphaSquareEffect,
Macros);
void setup() {
Kaleidoscope.setup();
AlphaSquare.color = { 0xcb, 0xc0, 0xff };

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-AlphaSquare -- 4x4 pixel LED alphabet
* 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,10 +24,6 @@ uint16_t AlphaSquareEffect::length = 1000;
uint32_t AlphaSquareEffect::end_time_left_, AlphaSquareEffect::end_time_right_;
Key AlphaSquareEffect::last_key_left_, AlphaSquareEffect::last_key_right_;
void AlphaSquareEffect::setup(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
void AlphaSquareEffect::update(void) {
if (end_time_left_ && millis() > end_time_left_) {
::AlphaSquare.clear(last_key_left_);
@ -39,37 +35,52 @@ void AlphaSquareEffect::update(void) {
}
}
Key AlphaSquareEffect::eventHandlerHook(Key key, byte row, byte col, uint8_t key_state) {
EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState) {
if (::LEDControl.get_mode() != &::AlphaSquareEffect)
return key;
return EventHandlerResult::OK;
if (key_state & INJECTED)
return key;
if (keyState & INJECTED)
return EventHandlerResult::OK;
if (key < Key_A || key > Key_0)
return key;
if (mappedKey < Key_A || mappedKey > Key_0)
return EventHandlerResult::OK;
if (!keyIsPressed(key_state))
return key;
if (!keyIsPressed(keyState))
return EventHandlerResult::OK;
uint8_t display_col = 2;
Key prev_key = last_key_left_;
if (col < COLS / 2) {
last_key_left_ = key;
last_key_left_ = mappedKey;
end_time_left_ = millis() + length;
} else {
prev_key = last_key_right_;
last_key_right_ = key;
last_key_right_ = mappedKey;
end_time_right_ = millis() + length;
display_col = 10;
}
if (prev_key != key)
if (prev_key != mappedKey)
::AlphaSquare.clear(prev_key, display_col);
::AlphaSquare.display(key, display_col);
return key;
::AlphaSquare.display(mappedKey, display_col);
return EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void AlphaSquareEffect::setup(void) {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key AlphaSquareEffect::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::AlphaSquareEffect.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
}

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-LED-AlphaSquare -- 4x4 pixel LED alphabet
* 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
@ -27,15 +27,19 @@ class AlphaSquareEffect : public LEDMode {
AlphaSquareEffect(void) {}
static uint16_t length;
EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState);
protected:
void setup(void) final;
void update(void) final;
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void setup(void) final;
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
private:
static uint32_t end_time_left_, end_time_right_;
static Key last_key_left_, last_key_right_;
static Key eventHandlerHook(Key key, uint8_t row, uint8_t col, uint8_t key_state);
};
}

@ -63,12 +63,6 @@ static const uint16_t alphabet[] PROGMEM = {
cRGB AlphaSquare::color = {0x80, 0x80, 0x80};
AlphaSquare::AlphaSquare(void) {
}
void AlphaSquare::begin(void) {
}
void AlphaSquare::display(Key key, uint8_t row, uint8_t col, cRGB key_color) {
if (key < Key_A || key > Key_0)
return;

@ -33,11 +33,9 @@
p30 << 12 | p31 << 13 | p32 << 14 | p33 << 15 )
namespace kaleidoscope {
class AlphaSquare : public KaleidoscopePlugin {
class AlphaSquare : public kaleidoscope::Plugin {
public:
AlphaSquare(void);
void begin(void) final;
AlphaSquare(void) {}
static void display(Key key, uint8_t row, uint8_t col, cRGB key_color);
static void display(Key key, uint8_t row, uint8_t col);

Loading…
Cancel
Save