Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent 50073dc27b
commit ee5cc576a0

@ -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>
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
AlphaSquare,
AlphaSquareEffect);
void setup() {
Kaleidoscope.use(&AlphaSquare, &AlphaSquareEffect);
Kaleidoscope.setup();
AlphaSquare.display (Key_A);
@ -59,8 +62,8 @@ methods or properties other than those provided by all LED modes.
### `.display(symbol, row, col)`
### `.display(symbol, row, col, color)`
> As the previous function, but instead of a key, it expects a 4x4 bitmap in
> the form of a 16-bit unsigned integer, where the low bit is the top-right
> As the previous function, but instead of a key, it expects a 4x4 bitmap in
> the form of a 16-bit unsigned integer, where the low bit is the top-right
> corner, the second-lowest bit is to the right of that, and so on.
>
> The `SYM4x4` macro can be used to simplify creating these bitmaps.

@ -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
(
@ -34,12 +35,13 @@ 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,
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