From 3e982ba5f67cefea6eca644c2537585417ede2b9 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 3 Jun 2017 07:53:31 +0200 Subject: [PATCH] Kaleidoscope Style Guide conformance Rearranged both in style, and in naming conventions to match the Kaleidoscope Style Guide, and please the linter too. Signed-off-by: Gergely Nagy --- README.md | 33 ++++++++++++------------ examples/Colormap/Colormap.ino | 46 ++++++++++++++++------------------ src/Kaleidoscope/Colormap.cpp | 43 +++++++++++++++++++------------ src/Kaleidoscope/Colormap.h | 20 ++++++++------- 4 files changed, 76 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 099bbcd4..ee24d6c7 100644 --- a/README.md +++ b/README.md @@ -12,34 +12,32 @@ The `Colormap` extension provides an easier way to set up a different - static - color map per-layer. This means that we can set up a map of colors for each key, on a per-layer basis, and whenever a layer becomes active, the color map for -that layer is applied on top of everything else. The extension supports -transparent colors, to make things easier. - -Both the palette and the color map is stored in EEPROM, and the palette is -limited to 15 colors (with the 16th being the transparent color). The plugin can -work together with the [Focus][plugin:focus] plugin, to make it easier to update -the palette or the color map itself. +that layer is applied on top of everything else. Colors are picked from a +15-color palette (or 16, if we disable transparency), provided by +the [LED-Palette-Theme][plugin:l-p-t] plugin. The color map is stored in +`EEPROM`, and can be easily changed via the [Focus][plugin:focus] plugin, which +also provides palette editing capabilities. [plugin:focus]: https://github.com/keyboardio/Kaleidoscope-Focus + [plugin:l-p-t]: https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme ## Using the extension To use the extension, include the header, tell it the number of layers you have, -and it will do the rest. +register the `Focus` hooks, and it will do the rest. ```c++ #include -#include #include #include -void setup (void) { - Kaleidoscope.setup (); - USE_PLUGINS (&ColormapEffect, &Focus); +void setup(void) { + Kaleidoscope.setup(); + USE_PLUGINS(&ColormapEffect, &Focus); - ColormapEffect.configure (1); - Focus.addHook (FOCUS_HOOK_LEDPALETTETHEME); - Focus.addHook (FOCUS_HOOK_COLORMAP); + ColormapEffect.max_layers(1); + Focus.addHook(FOCUS_HOOK_LEDPALETTETHEME); + Focus.addHook(FOCUS_HOOK_COLORMAP); } ``` @@ -47,9 +45,10 @@ void setup (void) { The extension provides an `ColormapEffect` singleton object, with a single method: -### `.configure(maxLayers)` +### `.max_layers(max)` -> Tells the extension to reserve space in EEPROM for up to `maxLayers` layers. +> Tells the extension to reserve space in EEPROM for up to `max` layers. Can +> only be called once, any subsequent call will be a no-op. ## Dependencies diff --git a/examples/Colormap/Colormap.ino b/examples/Colormap/Colormap.ino index 27d16a79..392424e9 100644 --- a/examples/Colormap/Colormap.ino +++ b/examples/Colormap/Colormap.ino @@ -21,33 +21,31 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED - ( - Key_LEDEffectNext, 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_NoKey, - - 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_NoKey - ), + (Key_LEDEffectNext, 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_NoKey, + + 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_NoKey), }; -void setup () { - Kaleidoscope.use (&ColormapEffect, NULL); +void setup() { + USE_PLUGINS(&ColormapEffect); - Kaleidoscope.setup (); - ColormapEffect.configure (1); - ColormapEffect.activate (); + Kaleidoscope.setup(); + ColormapEffect.max_layers(1); + ColormapEffect.activate(); } -void loop () { - Kaleidoscope.loop (); +void loop() { + Kaleidoscope.loop(); } diff --git a/src/Kaleidoscope/Colormap.cpp b/src/Kaleidoscope/Colormap.cpp index 84bd6ea0..9372ea3f 100644 --- a/src/Kaleidoscope/Colormap.cpp +++ b/src/Kaleidoscope/Colormap.cpp @@ -16,42 +16,53 @@ * along with this program. If not, see . */ + #include + +#include + #include #include -#include -namespace KaleidoscopePlugins { +namespace kaleidoscope { -uint16_t ColormapEffect::mapBase; -uint8_t ColormapEffect::maxLayers; +uint16_t ColormapEffect::map_base_; +uint8_t ColormapEffect::max_layers_; + +ColormapEffect::ColormapEffect(void) { +} + +void +ColormapEffect::begin(void) { + LEDMode::begin(); -ColormapEffect::ColormapEffect (void) { + USE_PLUGINS(&::EEPROMSettings, &::LEDPaletteTheme); } void -ColormapEffect::configure (uint8_t maxLayers_) { - USE_PLUGINS (&::EEPROMSettings, &::LEDPaletteTheme); +ColormapEffect::max_layers(uint8_t max_) { + if (map_base_ != 0) + return; - maxLayers = maxLayers_; - mapBase = ::LEDPaletteTheme.reserveThemes (maxLayers); + max_layers_ = max_; + map_base_ = ::LEDPaletteTheme.reserveThemes(max_layers_); } void -ColormapEffect::update (void) { +ColormapEffect::update(void) { for (uint8_t l = 0; l < 32; l++) { - if (!Layer.isOn (l)) + if (!Layer.isOn(l)) continue; - ::LEDPaletteTheme.update (mapBase, l); + ::LEDPaletteTheme.update(map_base_, l); } } bool -ColormapEffect::focusHook (const char *command) { - return ::LEDPaletteTheme.themeFocusHandler (command, PSTR("colormap.map"), mapBase, maxLayers); +ColormapEffect::focusHook(const char *command) { + return ::LEDPaletteTheme.themeFocusHandler(command, PSTR("colormap.map"), map_base_, max_layers_); } -}; +} // namespace kaleidoscope -KaleidoscopePlugins::ColormapEffect ColormapEffect; +kaleidoscope::ColormapEffect ColormapEffect; diff --git a/src/Kaleidoscope/Colormap.h b/src/Kaleidoscope/Colormap.h index 14c4d056..ed98cb7f 100644 --- a/src/Kaleidoscope/Colormap.h +++ b/src/Kaleidoscope/Colormap.h @@ -21,23 +21,25 @@ #include #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { class ColormapEffect : public LEDMode { public: - ColormapEffect (void); + ColormapEffect(void); - virtual void update (void) final; - void configure (uint8_t maxLayers); + void begin(void) final; + void update(void) final; - static bool focusHook (const char *command); + void max_layers(uint8_t max_); + + static bool focusHook(const char *command); private: - static uint8_t maxLayers; - static uint16_t mapBase; -}; + static uint8_t max_layers_; + static uint16_t map_base_; }; +} // namespace kaleidoscope -extern KaleidoscopePlugins::ColormapEffect ColormapEffect; +extern kaleidoscope::ColormapEffect ColormapEffect; #define FOCUS_HOOK_COLORMAP FOCUS_HOOK(ColormapEffect.focusHook, \ "colormap.map")