|
|
@ -21,155 +21,155 @@
|
|
|
|
#include <Kaleidoscope-Focus.h>
|
|
|
|
#include <Kaleidoscope-Focus.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
uint16_t FingerPainter::paletteBase;
|
|
|
|
uint16_t FingerPainter::paletteBase;
|
|
|
|
uint16_t FingerPainter::colorBase;
|
|
|
|
uint16_t FingerPainter::colorBase;
|
|
|
|
bool FingerPainter::editMode;
|
|
|
|
bool FingerPainter::editMode;
|
|
|
|
const cRGB *FingerPainter::defaultPalette;
|
|
|
|
const cRGB *FingerPainter::defaultPalette;
|
|
|
|
|
|
|
|
|
|
|
|
FingerPainter::FingerPainter (void) {
|
|
|
|
FingerPainter::FingerPainter (void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
FingerPainter::begin (void) {
|
|
|
|
FingerPainter::begin (void) {
|
|
|
|
LEDMode::begin ();
|
|
|
|
LEDMode::begin ();
|
|
|
|
event_handler_hook_use (eventHandlerHook);
|
|
|
|
event_handler_hook_use (eventHandlerHook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
FingerPainter::configure (void) {
|
|
|
|
FingerPainter::configure (void) {
|
|
|
|
paletteBase = ::EEPROMSettings.requestSlice (16 * sizeof (cRGB));
|
|
|
|
paletteBase = ::EEPROMSettings.requestSlice (16 * sizeof (cRGB));
|
|
|
|
colorBase = ::EEPROMSettings.requestSlice (ROWS * COLS);
|
|
|
|
colorBase = ::EEPROMSettings.requestSlice (ROWS * COLS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cRGB
|
|
|
|
cRGB
|
|
|
|
FingerPainter::lookupColor (uint8_t row, uint8_t column) {
|
|
|
|
FingerPainter::lookupColor (uint8_t row, uint8_t column) {
|
|
|
|
uint16_t location = row * COLS + column;
|
|
|
|
uint16_t location = row * COLS + column;
|
|
|
|
uint8_t colorIndex = EEPROM.read (colorBase + location);
|
|
|
|
uint8_t colorIndex = EEPROM.read (colorBase + location);
|
|
|
|
|
|
|
|
|
|
|
|
if (colorIndex == 0xff)
|
|
|
|
if (colorIndex == 0xff)
|
|
|
|
colorIndex = 0;
|
|
|
|
colorIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
cRGB color;
|
|
|
|
cRGB color;
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), color);
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), color);
|
|
|
|
|
|
|
|
|
|
|
|
return color;
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
FingerPainter::update (void) {
|
|
|
|
FingerPainter::update (void) {
|
|
|
|
for (uint8_t r = 0; r < ROWS; r++) {
|
|
|
|
for (uint8_t r = 0; r < ROWS; r++) {
|
|
|
|
for (uint8_t c = 0; c < COLS; c++) {
|
|
|
|
for (uint8_t c = 0; c < COLS; c++) {
|
|
|
|
cRGB color = lookupColor (r, c);
|
|
|
|
cRGB color = lookupColor (r, c);
|
|
|
|
LEDControl.led_set_crgb_at (r, c, color);
|
|
|
|
LEDControl.led_set_crgb_at (r, c, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
FingerPainter::toggleEdit (void) {
|
|
|
|
FingerPainter::toggleEdit (void) {
|
|
|
|
editMode = !editMode;
|
|
|
|
editMode = !editMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key
|
|
|
|
FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
if (!editMode)
|
|
|
|
if (!editMode)
|
|
|
|
return mappedKey;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
if (!key_toggled_on (keyState))
|
|
|
|
if (!key_toggled_on (keyState))
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
cRGB oldColor, newColor;
|
|
|
|
cRGB oldColor, newColor;
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t location = row * COLS + col;
|
|
|
|
uint16_t location = row * COLS + col;
|
|
|
|
uint8_t colorIndex = EEPROM.read (colorBase + location);
|
|
|
|
uint8_t colorIndex = EEPROM.read (colorBase + location);
|
|
|
|
if (colorIndex == 255)
|
|
|
|
if (colorIndex == 255)
|
|
|
|
colorIndex = 0;
|
|
|
|
colorIndex = 0;
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), oldColor);
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), oldColor);
|
|
|
|
colorIndex++;
|
|
|
|
colorIndex++;
|
|
|
|
if (colorIndex > 15)
|
|
|
|
if (colorIndex > 15)
|
|
|
|
colorIndex = 0;
|
|
|
|
colorIndex = 0;
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), newColor);
|
|
|
|
EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), newColor);
|
|
|
|
if (memcmp (&oldColor, &newColor, sizeof (cRGB)) == 0)
|
|
|
|
if (memcmp (&oldColor, &newColor, sizeof (cRGB)) == 0)
|
|
|
|
colorIndex = 0;
|
|
|
|
colorIndex = 0;
|
|
|
|
EEPROM.update (colorBase + location, colorIndex);
|
|
|
|
EEPROM.update (colorBase + location, colorIndex);
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
FingerPainter::focusHook (const char *command) {
|
|
|
|
FingerPainter::focusHook (const char *command) {
|
|
|
|
enum {
|
|
|
|
enum {
|
|
|
|
PALETTE,
|
|
|
|
PALETTE,
|
|
|
|
TOGGLE,
|
|
|
|
TOGGLE,
|
|
|
|
CLEAR,
|
|
|
|
CLEAR,
|
|
|
|
} subCommand;
|
|
|
|
} subCommand;
|
|
|
|
|
|
|
|
|
|
|
|
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 ("palette")) == 0)
|
|
|
|
subCommand = PALETTE;
|
|
|
|
subCommand = PALETTE;
|
|
|
|
else if (strcmp_P (command + 14, PSTR ("toggle")) == 0)
|
|
|
|
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) {
|
|
|
|
if (subCommand == TOGGLE) {
|
|
|
|
::FingerPainter.activate ();
|
|
|
|
::FingerPainter.activate ();
|
|
|
|
toggleEdit ();
|
|
|
|
toggleEdit ();
|
|
|
|
return true;
|
|
|
|
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; i++) {
|
|
|
|
EEPROM.update (colorBase + i, 0);
|
|
|
|
EEPROM.update (colorBase + i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Serial.peek () == '\n') {
|
|
|
|
if (Serial.peek () == '\n') {
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
cRGB color;
|
|
|
|
cRGB color;
|
|
|
|
|
|
|
|
|
|
|
|
EEPROM.get (paletteBase + i * sizeof (color), color);
|
|
|
|
EEPROM.get (paletteBase + i * sizeof (color), color);
|
|
|
|
::Focus.printColor (color.r, color.g, color.b);
|
|
|
|
::Focus.printColor (color.r, color.g, color.b);
|
|
|
|
::Focus.printSpace ();
|
|
|
|
::Focus.printSpace ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println ();
|
|
|
|
Serial.println ();
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Serial.peek() == 'd') {
|
|
|
|
if (Serial.peek() == 'd') {
|
|
|
|
Serial.read ();
|
|
|
|
Serial.read ();
|
|
|
|
if (!defaultPalette)
|
|
|
|
if (!defaultPalette)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
for (uint8_t i = 0; i < 16; i++) {
|
|
|
|
EEPROM.put (paletteBase + i * sizeof (cRGB), defaultPalette[i]);
|
|
|
|
EEPROM.put (paletteBase + i * sizeof (cRGB), defaultPalette[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
uint8_t i = 0;
|
|
|
|
while (i < 16 && Serial.peek() != '\n') {
|
|
|
|
while (i < 16 && Serial.peek() != '\n') {
|
|
|
|
cRGB color;
|
|
|
|
cRGB color;
|
|
|
|
|
|
|
|
|
|
|
|
color.r = Serial.parseInt ();
|
|
|
|
color.r = Serial.parseInt ();
|
|
|
|
color.g = Serial.parseInt ();
|
|
|
|
color.g = Serial.parseInt ();
|
|
|
|
color.b = Serial.parseInt ();
|
|
|
|
color.b = Serial.parseInt ();
|
|
|
|
|
|
|
|
|
|
|
|
EEPROM.put (paletteBase + i * sizeof (color), color);
|
|
|
|
EEPROM.put (paletteBase + i * sizeof (color), color);
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::FingerPainter FingerPainter;
|
|
|
|
KaleidoscopePlugins::FingerPainter FingerPainter;
|
|
|
|