Add a number of helper functions

Added `lookupColor(index)`, which looks up a color in the palette, by index.
Made the `row, col` variant public, and added an `updateColor` method.

These are there to help porting FingerPainter.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 9e10c9e686
commit 0fc32dbd94

@ -56,8 +56,8 @@ LEDPaletteTheme::update (uint16_t themeBase, uint8_t theme) {
} }
} }
const bool const uint8_t
LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) { LEDPaletteTheme::lookupColorIndex (uint16_t mapBase, uint16_t loc) {
uint8_t colorIndex; uint8_t colorIndex;
colorIndex = EEPROM.read (mapBase + loc / 2); colorIndex = EEPROM.read (mapBase + loc / 2);
@ -66,6 +66,13 @@ LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
else else
colorIndex >>= 4; colorIndex >>= 4;
return colorIndex;
}
const bool
LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
uint8_t colorIndex = lookupColorIndex (mapBase, loc);
if (colorIndex == transparentIndex) if (colorIndex == transparentIndex)
return false; return false;
@ -74,6 +81,29 @@ LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
return true; return true;
} }
const cRGB
LEDPaletteTheme::lookupColor (uint8_t index) {
cRGB color;
EEPROM.get (paletteBase + index * sizeof (cRGB), color);
return color;
}
void
LEDPaletteTheme::updateColor (uint16_t mapBase, uint16_t loc, uint8_t index) {
uint8_t indexes;
indexes = EEPROM.read (mapBase + loc / 2);
if (loc % 2) {
uint8_t other = indexes >> 4;
indexes = (other << 4) + index;
} else {
uint8_t other = indexes & ~0xf0;
indexes = (index << 4) + other;
}
EEPROM.update (mapBase + loc / 2, indexes);
}
bool bool
LEDPaletteTheme::paletteFocusHook (const char *command) { LEDPaletteTheme::paletteFocusHook (const char *command) {
if (strcmp_P (command, PSTR ("palette")) != 0) if (strcmp_P (command, PSTR ("palette")) != 0)

@ -31,6 +31,11 @@ class LEDPaletteTheme : public KaleidoscopePlugin {
static uint16_t reserveThemes (uint8_t maxThemes); static uint16_t reserveThemes (uint8_t maxThemes);
static void update (uint16_t themeBase, uint8_t theme); static void update (uint16_t themeBase, uint8_t theme);
static const uint8_t lookupColorIndex (uint16_t mapBase, uint16_t loc);
static const cRGB lookupColor (uint8_t index);
static const bool lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color);
static void updateColor (uint16_t mapBase, uint16_t loc, uint8_t index);
static bool paletteFocusHook (const char *command); static bool paletteFocusHook (const char *command);
static bool themeFocusHandler (const char *command, const char *expectedCommand, static bool themeFocusHandler (const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes); uint16_t themeBase, uint8_t maxThemes);
@ -39,8 +44,6 @@ class LEDPaletteTheme : public KaleidoscopePlugin {
private: private:
static uint16_t paletteBase; static uint16_t paletteBase;
static const bool lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color);
}; };
}; };

Loading…
Cancel
Save