Port over to LED-Palette-Theme

Fixes #6.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent 849c87606f
commit 09ba7dd756

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-FingerPainter.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-FingerPainter
[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
TODO
@ -38,6 +38,7 @@ The plugin provides the `FingerPainter` object, which has the following methods:
## Dependencies
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings)
* [Kaleidoscope-LED-Palette-Theme](https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme)
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)
## Further reading
@ -46,15 +47,3 @@ Starting from the [example][plugin:example] is the recommended way of getting
started with the plugin.
[plugin:example]: https://github.com/keyboardio/Kaleidoscope-FingerPainter/blob/master/examples/FingerPainter/FingerPainter.ino
## Notice
While the code is under the GPL-3, the `FINGERPAINTER_PALETTE_PASTEL` palette
was created by [Conache][conache], and is under a [CC-BY-SA][license:cc-by-sa]
license; the `FINGERPAINTER_PALETTE_SOLARIZED` palette was created
by [Ethan Schoonover][solarized], and is under the [MIT][license:mit] license.
[solarized]: http://ethanschoonover.com/solarized
[conache]: http://www.colourlovers.com/lover/Conache/loveNote
[license:cc-by-sa]: http://creativecommons.org/licenses/by-sa/3.0/
[license:mit]: https://github.com/altercation/solarized/blob/master/LICENSE

@ -60,9 +60,6 @@ void setup () {
USE_PLUGINS (&LEDOff, &EEPROMSettings, &FingerPainter, &Macros);
FingerPainter.configure ();
FingerPainter.defaultPalette = FINGERPAINTER_PALETTE_EGA;
EEPROMSettings.seal ();
FingerPainter.activate ();

@ -17,52 +17,33 @@
*/
#include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
namespace KaleidoscopePlugins {
uint16_t FingerPainter::paletteBase;
uint16_t FingerPainter::colorBase;
bool FingerPainter::editMode;
const cRGB *FingerPainter::defaultPalette;
FingerPainter::FingerPainter (void) {
}
void
FingerPainter::begin (void) {
USE_PLUGINS (&::LEDPaletteTheme);
LEDMode::begin ();
event_handler_hook_use (eventHandlerHook);
}
void
FingerPainter::configure (void) {
paletteBase = ::EEPROMSettings.requestSlice (16 * sizeof (cRGB));
colorBase = ::EEPROMSettings.requestSlice (ROWS * COLS);
}
cRGB
FingerPainter::lookupColor (uint8_t row, uint8_t column) {
uint16_t location = row * COLS + column;
uint8_t colorIndex = EEPROM.read (colorBase + location);
if (colorIndex == 0xff)
colorIndex = 0;
cRGB color;
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), color);
return color;
colorBase = ::LEDPaletteTheme.reserveThemes (1);
}
void
FingerPainter::update (void) {
for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) {
cRGB color = lookupColor (r, c);
LEDControl.led_set_crgb_at (r, c, color);
}
}
::LEDPaletteTheme.update (colorBase, 0);
}
void
@ -75,26 +56,30 @@ FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyS
if (!editMode)
return mappedKey;
if (row >= ROWS || col >= COLS)
if (!key_toggled_on (keyState))
return Key_NoKey;
if (!key_toggled_on (keyState))
if (row >= ROWS || col >= COLS)
return Key_NoKey;
cRGB oldColor, newColor;
uint16_t location = row * COLS + col;
uint8_t colorIndex = EEPROM.read (colorBase + location);
if (colorIndex == 255)
colorIndex = 0;
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), oldColor);
colorIndex++;
if (colorIndex > 15)
colorIndex = 0;
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), newColor);
if (memcmp (&oldColor, &newColor, sizeof (cRGB)) == 0)
colorIndex = 0;
EEPROM.update (colorBase + location, colorIndex);
uint8_t colorIndex = ::LEDPaletteTheme.lookupColorIndex (colorBase, KeyboardHardware.get_led_index (row, col));
// Find the next color in the palette that is different.
// But do not loop forever!
bool turnAround = false;
cRGB oldColor = ::LEDPaletteTheme.lookupColor (colorIndex), newColor = oldColor;
while (memcmp (&oldColor, &newColor, sizeof (cRGB)) == 0) {
colorIndex++;
if (colorIndex > 15) {
colorIndex = 0;
if (turnAround)
break;
turnAround = true;
}
newColor = ::LEDPaletteTheme.lookupColor (colorIndex);
}
::LEDPaletteTheme.updateColor (colorBase, KeyboardHardware.get_led_index (row, col), colorIndex);
return Key_NoKey;
}
@ -102,7 +87,6 @@ FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyS
bool
FingerPainter::focusHook (const char *command) {
enum {
PALETTE,
TOGGLE,
CLEAR,
} subCommand;
@ -110,63 +94,22 @@ FingerPainter::focusHook (const char *command) {
if (strncmp_P (command, PSTR ("fingerpainter."), 14) != 0)
return false;
if (strcmp_P (command + 14, PSTR ("palette")) == 0)
subCommand = PALETTE;
else if (strcmp_P (command + 14, PSTR ("toggle")) == 0)
if (strcmp_P (command + 14, PSTR ("toggle")) == 0)
subCommand = TOGGLE;
else if (strcmp_P (command + 14, PSTR ("clear")) == 0)
subCommand = CLEAR;
else
return false;
if (subCommand == TOGGLE) {
::FingerPainter.activate ();
toggleEdit ();
return true;
}
if (subCommand == CLEAR) {
for (uint16_t i = 0; i < ROWS * COLS; i++) {
for (uint16_t i = 0; i < ROWS * COLS / 2; i++) {
EEPROM.update (colorBase + i, 0);
}
return true;
}
if (Serial.peek () == '\n') {
for (uint8_t i = 0; i < 16; i++) {
cRGB color;
EEPROM.get (paletteBase + i * sizeof (color), color);
::Focus.printColor (color.r, color.g, color.b);
::Focus.printSpace ();
}
Serial.println ();
return true;
}
if (Serial.peek() == 'd') {
Serial.read ();
if (!defaultPalette)
return true;
for (uint8_t i = 0; i < 16; i++) {
EEPROM.put (paletteBase + i * sizeof (cRGB), defaultPalette[i]);
}
return true;
}
uint8_t i = 0;
while (i < 16 && Serial.peek() != '\n') {
cRGB color;
color.r = Serial.parseInt ();
color.g = Serial.parseInt ();
color.b = Serial.parseInt ();
EEPROM.put (paletteBase + i * sizeof (color), color);
i++;
}
::FingerPainter.activate ();
toggleEdit ();
return true;
}

@ -19,7 +19,6 @@
#pragma once
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-EEPROM-Settings.h>
namespace KaleidoscopePlugins {
class FingerPainter : public LEDMode {
@ -29,83 +28,19 @@ class FingerPainter : public LEDMode {
virtual void begin (void) final;
virtual void update (void) final;
static void configure (void);
static void toggleEdit (void);
static bool focusHook (const char *command);
static const cRGB *defaultPalette;
private:
static uint16_t paletteBase;
static uint16_t colorBase;
static bool editMode;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState);
static cRGB lookupColor (uint8_t row, uint8_t column);
};
};
extern KaleidoscopePlugins::FingerPainter FingerPainter;
#define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \
"fingerpainter.palette\n" \
"fingerpainter.toggle\n" \
"fingerpainter.clear")
#define FINGERPAINTER_PALETTE_EGA (const cRGB[]) { \
CRGB (0x00, 0x00, 0x00), \
CRGB (0x00, 0x00, 0xaa), \
CRGB (0x00, 0xaa, 0x00), \
CRGB (0x00, 0xaa, 0xaa), \
CRGB (0xaa, 0x00, 0x00), \
CRGB (0xaa, 0x00, 0xaa), \
CRGB (0xaa, 0x55, 0x00), \
CRGB (0xaa, 0xaa, 0xaa), \
\
CRGB (0x55, 0x55, 0x55), \
CRGB (0x55, 0x55, 0xff), \
CRGB (0x55, 0xff, 0x55), \
CRGB (0x55, 0xff, 0xff), \
CRGB (0xff, 0x55, 0x55), \
CRGB (0xff, 0x55, 0xff), \
CRGB (0xff, 0xff, 0x55), \
CRGB (0xff, 0xff, 0xff) \
}
#define FINGERPAINTER_PALETTE_PASTEL (const cRGB[]) { \
CRGB (0, 0, 0), \
CRGB (230, 119, 107), \
CRGB (229, 154, 67), \
CRGB (242, 228, 110), \
CRGB (155, 243, 150), \
CRGB (150, 221, 243), \
CRGB (255, 255, 255), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
}
#define FINGERPAINTER_PALETTE_SOLARIZED (const cRGB[]) { \
CRGB (0, 0, 0), \
CRGB (181, 137, 0), \
CRGB (203, 75, 22), \
CRGB (220, 50, 47), \
CRGB (211, 54, 130), \
CRGB (108, 113, 196), \
CRGB (38, 139, 210), \
CRGB (42, 161, 152), \
CRGB (133, 153, 0), \
CRGB (238, 232, 213), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
CRGB (0, 0, 0), \
}

Loading…
Cancel
Save