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
LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
const uint8_t
LEDPaletteTheme::lookupColorIndex (uint16_t mapBase, uint16_t loc) {
uint8_t colorIndex;
colorIndex = EEPROM.read (mapBase + loc / 2);
@ -66,6 +66,13 @@ LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
else
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)
return false;
@ -74,6 +81,29 @@ LEDPaletteTheme::lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color) {
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
LEDPaletteTheme::paletteFocusHook (const char *command) {
if (strcmp_P (command, PSTR ("palette")) != 0)

@ -31,6 +31,11 @@ class LEDPaletteTheme : public KaleidoscopePlugin {
static uint16_t reserveThemes (uint8_t maxThemes);
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 themeFocusHandler (const char *command, const char *expectedCommand,
uint16_t themeBase, uint8_t maxThemes);
@ -39,8 +44,6 @@ class LEDPaletteTheme : public KaleidoscopePlugin {
private:
static uint16_t paletteBase;
static const bool lookupColor (uint16_t mapBase, uint16_t loc, cRGB *color);
};
};

Loading…
Cancel
Save