Migrate to LED-Palette-Theme

Fixes #3.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent 517636d479
commit f7196ef26d

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-EEPROM-Colormap.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-EEPROM-Colormap.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-EEPROM-Colormap [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-EEPROM-Colormap
[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
The `EEPROM-ColorMap` extension provides an easier way to set up a different - The `EEPROM-ColorMap` extension provides an easier way to set up a different -
static - color map per-layer. This means that we can set up a map of colors for static - color map per-layer. This means that we can set up a map of colors for
@ -29,19 +29,19 @@ and it will do the rest.
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-EEPROM-Colormap.h> #include <Kaleidoscope-EEPROM-Colormap.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
void setup (void) { void setup (void) {
Kaleidoscope.setup (); Kaleidoscope.setup ();
USE_PLUGINS (&EEPROMColormapEffect, &Focus); USE_PLUGINS (&EEPROMColormapEffect, &Focus);
EEPROMColormapEffect.configure (1); EEPROMColormapEffect.configure (1);
Focus.addHook (FOCUS_HOOK_LEDPALETTETHEME);
Focus.addHook (FOCUS_HOOK_COLORMAP); Focus.addHook (FOCUS_HOOK_COLORMAP);
} }
``` ```
## Extension methods ## Extension methods
@ -55,6 +55,7 @@ The extension provides an `EEPROMColormapEffect` singleton object, with a single
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) * [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings)
* [Kaleidoscope-Focus](https://github.com/keyboardio/Kaleidoscope-Focus) * [Kaleidoscope-Focus](https://github.com/keyboardio/Kaleidoscope-Focus)
* [Kaleidoscope-LED-Palette-Theme](https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme)
## Further reading ## Further reading

@ -23,7 +23,6 @@
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
uint16_t EEPROMColormapEffect::paletteBase;
uint16_t EEPROMColormapEffect::mapBase; uint16_t EEPROMColormapEffect::mapBase;
uint8_t EEPROMColormapEffect::maxLayers; uint8_t EEPROMColormapEffect::maxLayers;
@ -32,11 +31,10 @@ EEPROMColormapEffect::EEPROMColormapEffect (void) {
void void
EEPROMColormapEffect::configure (uint8_t maxLayers_) { EEPROMColormapEffect::configure (uint8_t maxLayers_) {
USE_PLUGINS (&::EEPROMSettings); USE_PLUGINS (&::EEPROMSettings, &::LEDPaletteTheme);
maxLayers = maxLayers_; maxLayers = maxLayers_;
paletteBase = ::EEPROMSettings.requestSlice (15 * sizeof (cRGB)); mapBase = ::LEDPaletteTheme.reserveThemes (maxLayers);
mapBase = ::EEPROMSettings.requestSlice (maxLayers * ROWS * COLS / 2);
} }
void void
@ -45,120 +43,13 @@ EEPROMColormapEffect::update (void) {
if (!Layer.isOn (l)) if (!Layer.isOn (l))
continue; continue;
for (uint8_t r = 0; r < ROWS; r++) { ::LEDPaletteTheme.update (mapBase, l);
for (uint8_t c = 0; c < COLS; c++) {
cRGB color;
if (!lookupColor (l, r, c, &color))
continue;
LEDControl.led_set_crgb_at (r, c, color);
}
}
} }
} }
const bool
EEPROMColormapEffect::lookupColor (uint8_t layer, uint8_t row, uint8_t column, cRGB *color) {
uint8_t colorIndex;
uint16_t mapIndex = (layer * ROWS * COLS / 2 + row * COLS / 2 + column / 2);
colorIndex = EEPROM.read (mapBase + mapIndex);
if (column % 2)
colorIndex &= ~0xf0;
else
colorIndex >>= 4;
if (colorIndex == Transparent)
return false;
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), *color);
return true;
}
bool bool
EEPROMColormapEffect::focusHook (const char *command) { EEPROMColormapEffect::focusHook (const char *command) {
enum { return ::LEDPaletteTheme.themeFocusHandler (command, PSTR("colormap.map"), mapBase, maxLayers);
PALETTE,
MAP,
} subCommand;
if (strncmp_P (command, PSTR ("colormap."), 9) != 0)
return false;
if (strcmp_P (command + 9, PSTR ("palette")) == 0)
subCommand = PALETTE;
else if (strcmp_P (command + 9, PSTR ("map")) == 0)
subCommand = MAP;
else
return false;
switch (subCommand) {
case PALETTE: {
if (Serial.peek () == '\n') {
for (uint8_t i = 0; i < 15; i++) {
cRGB color;
EEPROM.get (paletteBase + i * sizeof (color), color);
::Focus.printColor (color.r, color.g, color.b);
::Focus.printSpace ();
}
Serial.println ();
break;
}
uint8_t i = 0;
while (i < 15 && 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++;
}
break;
}
case MAP: {
if (Serial.peek () == '\n') {
for (uint8_t layer = 0; layer < maxLayers; layer++) {
for (uint8_t row = 0; row < ROWS; row++) {
for (uint8_t col = 0; col < COLS / 2; col++) {
uint8_t indexes;
uint16_t loc = (layer * ROWS * COLS / 2 + row * COLS / 2 + col);
indexes = EEPROM.read (mapBase + loc);
::Focus.printNumber (indexes >> 4);
::Focus.printSpace ();
::Focus.printNumber (indexes & ~0xf0);
::Focus.printSpace ();
}
}
}
Serial.println ();
break;
}
uint16_t maxIndex = (maxLayers * ROWS * COLS) / 2;
uint8_t loc = 0;
while ((Serial.peek () != '\n') && (loc < maxIndex)) {
uint8_t idx1 = Serial.parseInt ();
uint8_t idx2 = Serial.parseInt ();
uint8_t indexes = (idx1 << 4) + idx2;
EEPROM.update (mapBase + loc, indexes);
loc++;
}
break;
}
}
return true;
} }
}; };

@ -19,23 +19,20 @@
#pragma once #pragma once
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
namespace KaleidoscopePlugins { namespace KaleidoscopePlugins {
class EEPROMColormapEffect : public LEDMode { class EEPROMColormapEffect : public LEDMode {
public: public:
static const uint8_t Transparent = 15;
EEPROMColormapEffect (void); EEPROMColormapEffect (void);
virtual void update (void) final; virtual void update (void) final;
void configure (uint8_t maxLayers); void configure (uint8_t maxLayers);
virtual const bool lookupColor (uint8_t layer, uint8_t row, uint8_t column, cRGB *color) final;
static bool focusHook (const char *command); static bool focusHook (const char *command);
private: private:
static uint8_t maxLayers; static uint8_t maxLayers;
static uint16_t paletteBase;
static uint16_t mapBase; static uint16_t mapBase;
}; };
}; };
@ -43,5 +40,4 @@ class EEPROMColormapEffect : public LEDMode {
extern KaleidoscopePlugins::EEPROMColormapEffect EEPROMColormapEffect; extern KaleidoscopePlugins::EEPROMColormapEffect EEPROMColormapEffect;
#define FOCUS_HOOK_COLORMAP FOCUS_HOOK(EEPROMColormapEffect.focusHook, \ #define FOCUS_HOOK_COLORMAP FOCUS_HOOK(EEPROMColormapEffect.focusHook, \
"colormap.palette\n" \
"colormap.map") "colormap.map")

Loading…
Cancel
Save