Add a way to display symbols in different colors

While it is possible to play with the ->color property, sometimes one
just wants to override the color once. In this case, saving the previous
value, and changing it back would be an overkill.

Instead, add a few functions that take a color argument as well, and
make the color-less arities use the global property.

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

@ -23,9 +23,9 @@ the `display` method.
#include <Kaleidoscope-LED-AlphaSquare.h>
void setup () {
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.setup ();
Kaleidoscope.use (&AlphaSquare, NULL);
USE_PLUGINS (&AlphaSquare);
AlphaSquare.display (Key_A);
}
@ -38,16 +38,19 @@ The plugin provides the `AlphaSquare` object, which has the following methods:
### `.display(key)`
### `.display(key, row, col)`
### `.display(key, col)`
### `.display(key, row, col, color)`
> Display the symbol for `key` at the given row or column. If `row` is omitted,
> the first row - `0` is assumed. If the column is omitted too, then the third -
> `2` - column is used by default.
> Display the symbol for `key` at the given row or column, with pixels set to
> the specified `color`. If `row` is omitted, the first row - `0` is assumed. If
> the column is omitted too, then the third - `2` - column is used by default.
> If the `color` is omitted, the plugin will use the global `.color` property.
>
> The plugin can display the English alphabet, and the numbers from 0 to 9.
### `.display(symbol)`
### `.display(symbol, row, col)`
### `.display(symbol, col)`
### `.display(symbol, row, col, color)`
> Almost the same as the previous function, but instead of a key, it expects a
> 4x4 bitmap.

@ -178,30 +178,40 @@ namespace KaleidoscopePlugins {
}
void
AlphaSquare::display (Key key, uint8_t row, uint8_t col) {
AlphaSquare::display (Key key, uint8_t row, uint8_t col, cRGB keyColor) {
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);
display (symbol, row, col, keyColor);
}
void
AlphaSquare::display (uint16_t symbol, uint8_t row, uint8_t col) {
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) {
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, color);
LEDControl.led_set_crgb_at (row + r, col + c, keyColor);
}
}
LEDControl.led_sync ();
}
void
AlphaSquare::display (uint16_t symbol, uint8_t row, uint8_t col) {
display (symbol, row, col, color);
}
};
KaleidoscopePlugins::AlphaSquare AlphaSquare;

@ -39,10 +39,12 @@ namespace KaleidoscopePlugins {
virtual 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);
static void display (Key key) { display (key, 0, 2); };
static void display (Key key, uint8_t 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);
static void display (uint16_t symbol) { display (symbol, 0, 2); };
static void display (uint16_t symbol, uint8_t col) { display (symbol, 0, col); };

Loading…
Cancel
Save