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

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

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

Loading…
Cancel
Save