diff --git a/examples/FingerPainter/FingerPainter.ino b/examples/FingerPainter/FingerPainter.ino index 0973a2c4..53f43506 100644 --- a/examples/FingerPainter/FingerPainter.ino +++ b/examples/FingerPainter/FingerPainter.ino @@ -25,49 +25,49 @@ #include "LED-Off.h" const Key keymaps[][ROWS][COLS] PROGMEM = { - [0] = KEYMAP_STACKED - ( - M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, - Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, - Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, - Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, + [0] = KEYMAP_STACKED + ( + M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, + Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, + Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, + Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - Key_skip, + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + Key_skip, - Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, - Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, - Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, + Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, + Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, - Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_skip - ), + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + Key_skip + ), }; const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { - if (macroIndex == 0 && key_toggled_off (keyState)) { - FingerPainter.toggleEdit (); - } + if (macroIndex == 0 && key_toggled_off (keyState)) { + FingerPainter.toggleEdit (); + } - return MACRO_NONE; + return MACRO_NONE; } void setup () { - Serial.begin (9600); + Serial.begin (9600); - Kaleidoscope.setup (); + Kaleidoscope.setup (); - USE_PLUGINS (&LEDOff, &EEPROMSettings, &FingerPainter, &Macros); + USE_PLUGINS (&LEDOff, &EEPROMSettings, &FingerPainter, &Macros); - FingerPainter.configure (); - FingerPainter.defaultPalette = FINGERPAINTER_PALETTE_EGA; + FingerPainter.configure (); + FingerPainter.defaultPalette = FINGERPAINTER_PALETTE_EGA; - EEPROMSettings.seal (); + EEPROMSettings.seal (); - FingerPainter.activate (); + FingerPainter.activate (); } void loop () { - Kaleidoscope.loop (); + Kaleidoscope.loop (); } diff --git a/src/Kaleidoscope/FingerPainter.cpp b/src/Kaleidoscope/FingerPainter.cpp index 39ef215e..37f4c540 100644 --- a/src/Kaleidoscope/FingerPainter.cpp +++ b/src/Kaleidoscope/FingerPainter.cpp @@ -21,155 +21,155 @@ #include namespace KaleidoscopePlugins { - uint16_t FingerPainter::paletteBase; - uint16_t FingerPainter::colorBase; - bool FingerPainter::editMode; - const cRGB *FingerPainter::defaultPalette; +uint16_t FingerPainter::paletteBase; +uint16_t FingerPainter::colorBase; +bool FingerPainter::editMode; +const cRGB *FingerPainter::defaultPalette; - FingerPainter::FingerPainter (void) { - } +FingerPainter::FingerPainter (void) { +} - void - FingerPainter::begin (void) { +void +FingerPainter::begin (void) { LEDMode::begin (); event_handler_hook_use (eventHandlerHook); - } +} - void - FingerPainter::configure (void) { +void +FingerPainter::configure (void) { paletteBase = ::EEPROMSettings.requestSlice (16 * sizeof (cRGB)); colorBase = ::EEPROMSettings.requestSlice (ROWS * COLS); - } +} - cRGB - FingerPainter::lookupColor (uint8_t row, uint8_t column) { +cRGB +FingerPainter::lookupColor (uint8_t row, uint8_t column) { uint16_t location = row * COLS + column; uint8_t colorIndex = EEPROM.read (colorBase + location); if (colorIndex == 0xff) - colorIndex = 0; + colorIndex = 0; cRGB color; EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), color); return color; - } +} - void - FingerPainter::update (void) { +void +FingerPainter::update (void) { for (uint8_t r = 0; r < ROWS; r++) { - for (uint8_t c = 0; c < COLS; c++) { - cRGB color = lookupColor (r, c); - LEDControl.led_set_crgb_at (r, c, color); - } + for (uint8_t c = 0; c < COLS; c++) { + cRGB color = lookupColor (r, c); + LEDControl.led_set_crgb_at (r, c, color); + } } - } +} - void - FingerPainter::toggleEdit (void) { +void +FingerPainter::toggleEdit (void) { editMode = !editMode; - } +} - Key - FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { +Key +FingerPainter::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { if (!editMode) - return mappedKey; + return mappedKey; if (row >= ROWS || col >= COLS) - return Key_NoKey; + return Key_NoKey; if (!key_toggled_on (keyState)) - return Key_NoKey; + return Key_NoKey; cRGB oldColor, newColor; uint16_t location = row * COLS + col; uint8_t colorIndex = EEPROM.read (colorBase + location); if (colorIndex == 255) - colorIndex = 0; + colorIndex = 0; EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), oldColor); colorIndex++; if (colorIndex > 15) - colorIndex = 0; + colorIndex = 0; EEPROM.get (paletteBase + colorIndex * sizeof (cRGB), newColor); if (memcmp (&oldColor, &newColor, sizeof (cRGB)) == 0) - colorIndex = 0; + colorIndex = 0; EEPROM.update (colorBase + location, colorIndex); return Key_NoKey; - } +} - bool - FingerPainter::focusHook (const char *command) { +bool +FingerPainter::focusHook (const char *command) { enum { - PALETTE, - TOGGLE, - CLEAR, + PALETTE, + TOGGLE, + CLEAR, } subCommand; if (strncmp_P (command, PSTR ("fingerpainter."), 14) != 0) - return false; + return false; if (strcmp_P (command + 14, PSTR ("palette")) == 0) - subCommand = PALETTE; + subCommand = PALETTE; else if (strcmp_P (command + 14, PSTR ("toggle")) == 0) - subCommand = TOGGLE; + subCommand = TOGGLE; else if (strcmp_P (command + 14, PSTR ("clear")) == 0) - subCommand = CLEAR; + subCommand = CLEAR; else - return false; + return false; if (subCommand == TOGGLE) { - ::FingerPainter.activate (); - toggleEdit (); - return true; + ::FingerPainter.activate (); + toggleEdit (); + return true; } if (subCommand == CLEAR) { - for (uint16_t i = 0; i < ROWS * COLS; i++) { - EEPROM.update (colorBase + i, 0); - } - return true; + for (uint16_t i = 0; i < ROWS * COLS; i++) { + EEPROM.update (colorBase + i, 0); + } + return true; } if (Serial.peek () == '\n') { - for (uint8_t i = 0; i < 16; i++) { - cRGB color; + for (uint8_t i = 0; i < 16; i++) { + cRGB color; - EEPROM.get (paletteBase + i * sizeof (color), color); - ::Focus.printColor (color.r, color.g, color.b); - ::Focus.printSpace (); - } + EEPROM.get (paletteBase + i * sizeof (color), color); + ::Focus.printColor (color.r, color.g, color.b); + ::Focus.printSpace (); + } - Serial.println (); - return true; + Serial.println (); + return true; } if (Serial.peek() == 'd') { - Serial.read (); - if (!defaultPalette) - return true; + Serial.read (); + if (!defaultPalette) + return true; - for (uint8_t i = 0; i < 16; i++) { - EEPROM.put (paletteBase + i * sizeof (cRGB), defaultPalette[i]); - } - return true; + for (uint8_t i = 0; i < 16; i++) { + EEPROM.put (paletteBase + i * sizeof (cRGB), defaultPalette[i]); + } + return true; } uint8_t i = 0; while (i < 16 && Serial.peek() != '\n') { - cRGB color; + cRGB color; - color.r = Serial.parseInt (); - color.g = Serial.parseInt (); - color.b = Serial.parseInt (); + color.r = Serial.parseInt (); + color.g = Serial.parseInt (); + color.b = Serial.parseInt (); - EEPROM.put (paletteBase + i * sizeof (color), color); - i++; + EEPROM.put (paletteBase + i * sizeof (color), color); + i++; } return true; - } +} }; KaleidoscopePlugins::FingerPainter FingerPainter; diff --git a/src/Kaleidoscope/FingerPainter.h b/src/Kaleidoscope/FingerPainter.h index 989311ef..15ea8287 100644 --- a/src/Kaleidoscope/FingerPainter.h +++ b/src/Kaleidoscope/FingerPainter.h @@ -22,7 +22,7 @@ #include namespace KaleidoscopePlugins { - class FingerPainter : public LEDMode { +class FingerPainter : public LEDMode { public: FingerPainter (void); @@ -42,7 +42,7 @@ namespace KaleidoscopePlugins { static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static cRGB lookupColor (uint8_t row, uint8_t column); - }; +}; }; extern KaleidoscopePlugins::FingerPainter FingerPainter;