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:image]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-AlphaSquare.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-AlphaSquare [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: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.png?style=flat&colorA=e05d44&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.png?style=flat&colorA=dfb317&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 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 "pixel" symbols on your keyboard. With this building block, one can build some
@ -22,11 +22,11 @@ the `display` method.
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LED-AlphaSquare.h> #include <Kaleidoscope-LED-AlphaSquare.h>
void setup () { void setup() {
Kaleidoscope.setup (); USE_PLUGINS(&AlphaSquare);
USE_PLUGINS (&AlphaSquare);
Kaleidoscope.setup();
AlphaSquare.display (Key_A); 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 > values, a 4x4 square of zeroes and ones. Zeroes are transparent pixels, ones
> will be colored. > 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 ## Dependencies
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl) * [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)

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

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

@ -21,8 +21,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace LEDEffects {
class AlphaSquareEffect : public LEDMode { class AlphaSquareEffect : public LEDMode {
public: public:
AlphaSquareEffect(void); AlphaSquareEffect(void);
@ -32,13 +31,12 @@ class AlphaSquareEffect : public LEDMode {
static uint16_t length; static uint16_t length;
private: private:
static uint32_t endTimeLeft, endTimeRight; static uint32_t end_time_left_, end_time_right_;
static Key lastKeyLeft, lastKeyRight; static Key last_key_left_, last_key_right_;
static uint8_t us; 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> #include <Kaleidoscope/LED-AlphaSquare.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace AlphaSquareSymbols { namespace alpha_square {
namespace symbols {
/* λ */ /* λ */
static constexpr uint16_t Lambda = SYM4x4(1, 0, 0, 0, static constexpr uint16_t Lambda = SYM4x4(1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0,
0, 1, 1, 0, 0, 1, 1, 0,
1, 0, 0, 1); 1, 0, 0, 1);
}; }
}; }
}

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

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

Loading…
Cancel
Save