|
|
@ -23,96 +23,92 @@
|
|
|
|
#include <Kaleidoscope-LEDControl.h>
|
|
|
|
#include <Kaleidoscope-LEDControl.h>
|
|
|
|
#include <Kaleidoscope-LED-Palette-Theme.h>
|
|
|
|
#include <Kaleidoscope-LED-Palette-Theme.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t FingerPainter::colorBase;
|
|
|
|
uint16_t FingerPainter::color_base_;
|
|
|
|
bool FingerPainter::editMode;
|
|
|
|
bool FingerPainter::edit_mode_;
|
|
|
|
|
|
|
|
|
|
|
|
FingerPainter::FingerPainter(void) {
|
|
|
|
FingerPainter::FingerPainter(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void FingerPainter::begin(void) {
|
|
|
|
FingerPainter::begin(void) {
|
|
|
|
|
|
|
|
USE_PLUGINS(&::LEDPaletteTheme);
|
|
|
|
USE_PLUGINS(&::LEDPaletteTheme);
|
|
|
|
|
|
|
|
|
|
|
|
LEDMode::begin();
|
|
|
|
LEDMode::begin();
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
|
|
|
|
|
|
|
|
colorBase = ::LEDPaletteTheme.reserveThemes(1);
|
|
|
|
color_base_ = ::LEDPaletteTheme.reserveThemes(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void FingerPainter::update(void) {
|
|
|
|
FingerPainter::update(void) {
|
|
|
|
::LEDPaletteTheme.update(color_base_, 0);
|
|
|
|
::LEDPaletteTheme.update(colorBase, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void FingerPainter::toggle(void) {
|
|
|
|
FingerPainter::toggleEdit(void) {
|
|
|
|
edit_mode_ = !edit_mode_;
|
|
|
|
editMode = !editMode;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
Key FingerPainter::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
FingerPainter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
if (!edit_mode_)
|
|
|
|
if (!editMode)
|
|
|
|
return mapped_key;
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!key_toggled_on(keyState))
|
|
|
|
if (!key_toggled_on(key_state))
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
if (row >= ROWS || col >= COLS)
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t colorIndex = ::LEDPaletteTheme.lookupColorIndex(colorBase, KeyboardHardware.get_led_index(row, col));
|
|
|
|
uint8_t color_index = ::LEDPaletteTheme.lookupColorIndex(color_base_, KeyboardHardware.get_led_index(row, col));
|
|
|
|
|
|
|
|
|
|
|
|
// Find the next color in the palette that is different.
|
|
|
|
// Find the next color in the palette that is different.
|
|
|
|
// But do not loop forever!
|
|
|
|
// But do not loop forever!
|
|
|
|
bool turnAround = false;
|
|
|
|
bool turn_around = false;
|
|
|
|
cRGB oldColor = ::LEDPaletteTheme.lookupColor(colorIndex), newColor = oldColor;
|
|
|
|
cRGB old_color = ::LEDPaletteTheme.lookupColor(color_index), new_color = old_color;
|
|
|
|
while (memcmp(&oldColor, &newColor, sizeof(cRGB)) == 0) {
|
|
|
|
while (memcmp(&old_color, &new_color, sizeof(cRGB)) == 0) {
|
|
|
|
colorIndex++;
|
|
|
|
color_index++;
|
|
|
|
if (colorIndex > 15) {
|
|
|
|
if (color_index > 15) {
|
|
|
|
colorIndex = 0;
|
|
|
|
color_index = 0;
|
|
|
|
if (turnAround)
|
|
|
|
if (turn_around)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
turnAround = true;
|
|
|
|
turn_around = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newColor = ::LEDPaletteTheme.lookupColor(colorIndex);
|
|
|
|
new_color = ::LEDPaletteTheme.lookupColor(color_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::LEDPaletteTheme.updateColor(colorBase, KeyboardHardware.get_led_index(row, col), colorIndex);
|
|
|
|
::LEDPaletteTheme.updateColor(color_base_, KeyboardHardware.get_led_index(row, col), color_index);
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool FingerPainter::focusHook(const char *command) {
|
|
|
|
FingerPainter::focusHook(const char *command) {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
enum {
|
|
|
|
TOGGLE,
|
|
|
|
TOGGLE,
|
|
|
|
CLEAR,
|
|
|
|
CLEAR,
|
|
|
|
} subCommand;
|
|
|
|
} sub_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("toggle")) == 0)
|
|
|
|
if (strcmp_P(command + 14, PSTR("toggle")) == 0)
|
|
|
|
subCommand = TOGGLE;
|
|
|
|
sub_command = TOGGLE;
|
|
|
|
else if (strcmp_P(command + 14, PSTR("clear")) == 0)
|
|
|
|
else if (strcmp_P(command + 14, PSTR("clear")) == 0)
|
|
|
|
subCommand = CLEAR;
|
|
|
|
sub_command = CLEAR;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (subCommand == CLEAR) {
|
|
|
|
if (sub_command == CLEAR) {
|
|
|
|
for (uint16_t i = 0; i < ROWS * COLS / 2; i++) {
|
|
|
|
for (uint16_t i = 0; i < ROWS * COLS / 2; i++) {
|
|
|
|
EEPROM.update(colorBase + i, 0);
|
|
|
|
EEPROM.update(color_base_ + i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
::FingerPainter.activate();
|
|
|
|
::FingerPainter.activate();
|
|
|
|
toggleEdit();
|
|
|
|
toggle();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::FingerPainter FingerPainter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::FingerPainter FingerPainter;
|
|
|
|