Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent d515f0088b
commit 9e6b7e22f6

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-AlphaSquare.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-AlphaSquare
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52
[st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
An alphabet for your per-key LEDs, `AlphaSquare` provides a way to display 4x4
"pixel" symbols on your keyboard. With this building block, one can build some
@ -22,10 +22,10 @@ the `display` method.
#include <Kaleidoscope.h>
#include <Kaleidoscope-LED-AlphaSquare.h>
void setup () {
Kaleidoscope.setup ();
void setup() {
USE_PLUGINS(&AlphaSquare);
USE_PLUGINS (&AlphaSquare);
Kaleidoscope.setup();
AlphaSquare.display (Key_A);
}
@ -78,6 +78,16 @@ The plugin provides the `AlphaSquare` object, which has the following methods:
> values, a 4x4 square of zeroes and ones. Zeroes are transparent pixels, ones
> will be colored.
## Extra symbols
There is a growing number of extra symbols available in the
`kaleidoscope::alpha_square::symbols` namespace. Ok, growing may have been an
exaggeration, there is only one as of this writing:
### `Lambda`
> A lambda (`λ`) symbol.
## Dependencies
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)

@ -41,11 +41,11 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip),
};
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (!key_toggled_on(keyState))
const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (!key_toggled_on(key_state))
return MACRO_NONE;
if (macroIndex == 0) {
if (macro_index == 0) {
for (uint8_t i = Key_A.keyCode; i <= Key_0.keyCode; i++) {
LEDControl.set_all_leds_to(0, 0, 0);
LEDControl.led_sync();
@ -74,15 +74,15 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
for (uint8_t step = 0; step <= 0xf0; step += 8) {
AlphaSquare.color = { step, step, step };
AlphaSquare.display(KaleidoscopePlugins::AlphaSquareSymbols::Lambda, 2);
AlphaSquare.display(KaleidoscopePlugins::AlphaSquareSymbols::Lambda, 10);
AlphaSquare.display(kaleidoscope::alpha_square::symbols::Lambda, 2);
AlphaSquare.display(kaleidoscope::alpha_square::symbols::Lambda, 10);
delay(10);
}
for (uint8_t step = 0xff; step >= 8; step -= 8) {
AlphaSquare.color = { step, step, step };
AlphaSquare.display(KaleidoscopePlugins::AlphaSquareSymbols::Lambda, 2);
AlphaSquare.display(KaleidoscopePlugins::AlphaSquareSymbols::Lambda, 10);
AlphaSquare.display(kaleidoscope::alpha_square::symbols::Lambda, 2);
AlphaSquare.display(kaleidoscope::alpha_square::symbols::Lambda, 10);
delay(10);
}
delay(100);
@ -94,9 +94,10 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
}
void setup() {
USE_PLUGINS(&AlphaSquare, &AlphaSquareEffect, &Macros);
Kaleidoscope.setup();
USE_PLUGINS(&AlphaSquare, &AlphaSquareEffect, &Macros);
AlphaSquare.color = { 0xcb, 0xc0, 0xff };
}

@ -18,12 +18,12 @@
#include <Kaleidoscope-LED-AlphaSquare.h>
namespace KaleidoscopePlugins {
namespace LEDEffects {
namespace kaleidoscope {
uint16_t AlphaSquareEffect::length = 1000;
uint32_t AlphaSquareEffect::endTimeLeft, AlphaSquareEffect::endTimeRight;
Key AlphaSquareEffect::lastKeyLeft, AlphaSquareEffect::lastKeyRight;
uint8_t AlphaSquareEffect::us;
uint32_t AlphaSquareEffect::end_time_left_, AlphaSquareEffect::end_time_right_;
Key AlphaSquareEffect::last_key_left_, AlphaSquareEffect::last_key_right_;
uint8_t AlphaSquareEffect::us_;
AlphaSquareEffect::AlphaSquareEffect(void) {
}
@ -32,54 +32,54 @@ void
AlphaSquareEffect::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
Kaleidoscope.use(&LEDControl, NULL);
us = LEDControl.mode_add(this);
us_ = LEDControl.mode_add(this);
}
void
AlphaSquareEffect::update(void) {
if (endTimeLeft && millis() > endTimeLeft) {
::AlphaSquare.clear(lastKeyLeft);
endTimeLeft = 0;
if (end_time_left_ && millis() > end_time_left_) {
::AlphaSquare.clear(last_key_left_);
end_time_left_ = 0;
}
if (endTimeRight && millis() > endTimeRight) {
::AlphaSquare.clear(lastKeyRight, 10);
endTimeRight = 0;
if (end_time_right_ && millis() > end_time_right_) {
::AlphaSquare.clear(last_key_right_, 10);
end_time_right_ = 0;
}
}
Key
AlphaSquareEffect::eventHandlerHook(Key key, byte row, byte col, uint8_t keyState) {
if (LEDControl.get_mode() != us)
AlphaSquareEffect::eventHandlerHook(Key key, byte row, byte col, uint8_t key_state) {
if (LEDControl.get_mode() != us_)
return key;
if (keyState & INJECTED)
if (key_state & INJECTED)
return key;
if (key < Key_A || key > Key_0)
return key;
if (!key_is_pressed(keyState))
if (!key_is_pressed(key_state))
return key;
uint8_t displayCol = 2;
Key prevKey = lastKeyLeft;
uint8_t display_col = 2;
Key prev_key = last_key_left_;
if (col < COLS / 2) {
lastKeyLeft = key;
endTimeLeft = millis() + length;
last_key_left_ = key;
end_time_left_ = millis() + length;
} else {
prevKey = lastKeyRight;
lastKeyRight = key;
endTimeRight = millis() + length;
displayCol = 10;
prev_key = last_key_right_;
last_key_right_ = key;
end_time_right_ = millis() + length;
display_col = 10;
}
if (prevKey != key)
::AlphaSquare.clear(prevKey, displayCol);
::AlphaSquare.display(key, displayCol);
if (prev_key != key)
::AlphaSquare.clear(prev_key, display_col);
::AlphaSquare.display(key, display_col);
return key;
}
};
};
KaleidoscopePlugins::LEDEffects::AlphaSquareEffect AlphaSquareEffect;
}
kaleidoscope::AlphaSquareEffect AlphaSquareEffect;

@ -21,8 +21,7 @@
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins {
namespace LEDEffects {
namespace kaleidoscope {
class AlphaSquareEffect : public LEDMode {
public:
AlphaSquareEffect(void);
@ -32,13 +31,12 @@ class AlphaSquareEffect : public LEDMode {
static uint16_t length;
private:
static uint32_t endTimeLeft, endTimeRight;
static Key lastKeyLeft, lastKeyRight;
static uint8_t us;
static uint32_t end_time_left_, end_time_right_;
static Key last_key_left_, last_key_right_;
static uint8_t us_;
static Key eventHandlerHook(Key key, uint8_t row, uint8_t col, uint8_t keyState);
};
};
static Key eventHandlerHook(Key key, uint8_t row, uint8_t col, uint8_t key_state);
};
}
extern KaleidoscopePlugins::LEDEffects::AlphaSquareEffect AlphaSquareEffect;
extern kaleidoscope::AlphaSquareEffect AlphaSquareEffect;

@ -20,12 +20,15 @@
#include <Kaleidoscope/LED-AlphaSquare.h>
namespace KaleidoscopePlugins {
namespace AlphaSquareSymbols {
namespace kaleidoscope {
namespace alpha_square {
namespace symbols {
/* λ */
static constexpr uint16_t Lambda = SYM4x4(1, 0, 0, 0,
0, 1, 0, 0,
0, 1, 1, 0,
1, 0, 0, 1);
};
};
}
}
}

@ -18,7 +18,7 @@
#include <Kaleidoscope-LED-AlphaSquare.h>
namespace KaleidoscopePlugins {
namespace kaleidoscope {
static const uint16_t alphabet[] PROGMEM = {
SYM4x4(1, 1, 1, 1,
@ -173,45 +173,41 @@ cRGB AlphaSquare::color = {0x80, 0x80, 0x80};
AlphaSquare::AlphaSquare(void) {
}
void
AlphaSquare::begin(void) {
void AlphaSquare::begin(void) {
}
void
AlphaSquare::display(Key key, uint8_t row, uint8_t col, cRGB keyColor) {
void AlphaSquare::display(Key key, uint8_t row, uint8_t col, cRGB key_color) {
if (key < Key_A || key > Key_0)
return;
uint8_t index = key.keyCode - Key_A.keyCode;
uint16_t symbol = pgm_read_word(&alphabet[index]);
display(symbol, row, col, keyColor);
display(symbol, row, col, key_color);
}
void
AlphaSquare::display(Key key, uint8_t row, uint8_t col) {
void AlphaSquare::display(Key key, uint8_t row, uint8_t col) {
display(key, row, col, color);
}
void
AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col, cRGB keyColor) {
void AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col, cRGB key_color) {
for (uint8_t r = 0; r < 4; r++) {
for (uint8_t c = 0; c < 4; c++) {
uint8_t pixel = bitRead(symbol, r * 4 + c);
if (!pixel)
continue;
LEDControl.led_set_crgb_at(row + r, col + c, keyColor);
LEDControl.led_set_crgb_at(row + r, col + c, key_color);
}
}
LEDControl.led_sync();
}
void
AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col) {
void AlphaSquare::display(uint16_t symbol, uint8_t row, uint8_t col) {
display(symbol, row, col, color);
}
};
KaleidoscopePlugins::AlphaSquare AlphaSquare;
}
kaleidoscope::AlphaSquare AlphaSquare;

@ -32,14 +32,14 @@
p20 << 8 | p21 << 9 | p22 << 10 | p23 << 11 | \
p30 << 12 | p31 << 13 | p32 << 14 | p33 << 15 )
namespace KaleidoscopePlugins {
namespace kaleidoscope {
class AlphaSquare : public KaleidoscopePlugin {
public:
AlphaSquare(void);
void begin(void) final;
static void display(Key key, uint8_t row, uint8_t col, cRGB keyColor);
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);
static void display(Key key) {
display(key, 0, 2);
@ -48,7 +48,7 @@ class AlphaSquare : public KaleidoscopePlugin {
display(key, 0, col);
}
static void display(uint16_t symbol, uint8_t row, uint8_t col, cRGB keyColor);
static void display(uint16_t symbol, uint8_t row, uint8_t col, cRGB key_color);
static void display(uint16_t symbol, uint8_t row, uint8_t col);
static void display(uint16_t symbol) {
display(symbol, 0, 2);
@ -79,6 +79,7 @@ class AlphaSquare : public KaleidoscopePlugin {
static cRGB color;
};
};
extern KaleidoscopePlugins::AlphaSquare AlphaSquare;
}
extern kaleidoscope::AlphaSquare AlphaSquare;

Loading…
Cancel
Save