Port over to LED-Palette-Theme

Fixes #6.

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

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-FingerPainter.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-FingerPainter.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-FingerPainter [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: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
TODO TODO
@ -38,6 +38,7 @@ The plugin provides the `FingerPainter` object, which has the following methods:
## Dependencies ## Dependencies
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) * [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) * [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)
## Further reading ## Further reading
@ -46,15 +47,3 @@ Starting from the [example][plugin:example] is the recommended way of getting
started with the plugin. started with the plugin.
[plugin:example]: https://github.com/keyboardio/Kaleidoscope-FingerPainter/blob/master/examples/FingerPainter/FingerPainter.ino [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); USE_PLUGINS (&LEDOff, &EEPROMSettings, &FingerPainter, &Macros);
FingerPainter.configure ();
FingerPainter.defaultPalette = FINGERPAINTER_PALETTE_EGA;
EEPROMSettings.seal (); EEPROMSettings.seal ();
FingerPainter.activate (); FingerPainter.activate ();

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

@ -19,7 +19,6 @@
#pragma once #pragma once
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-EEPROM-Settings.h>
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
class FingerPainter : public LEDMode { class FingerPainter : public LEDMode {
@ -29,83 +28,19 @@ class FingerPainter : public LEDMode {
virtual void begin (void) final; virtual void begin (void) final;
virtual void update (void) final; virtual void update (void) final;
static void configure (void);
static void toggleEdit (void); static void toggleEdit (void);
static bool focusHook (const char *command); static bool focusHook (const char *command);
static const cRGB *defaultPalette;
private: private:
static uint16_t paletteBase;
static uint16_t colorBase; static uint16_t colorBase;
static bool editMode; static bool editMode;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); 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; extern KaleidoscopePlugins::FingerPainter FingerPainter;
#define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \ #define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \
"fingerpainter.palette\n" \
"fingerpainter.toggle\n" \ "fingerpainter.toggle\n" \
"fingerpainter.clear") "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