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 <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 947019733d
commit 3e982ba5f6

@ -12,24 +12,22 @@
The `Colormap` extension provides an easier way to set up a different - static - 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, 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 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 that layer is applied on top of everything else. Colors are picked from a
transparent colors, to make things easier. 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
Both the palette and the color map is stored in EEPROM, and the palette is `EEPROM`, and can be easily changed via the [Focus][plugin:focus] plugin, which
limited to 15 colors (with the 16th being the transparent color). The plugin can also provides palette editing capabilities.
work together with the [Focus][plugin:focus] plugin, to make it easier to update
the palette or the color map itself.
[plugin:focus]: https://github.com/keyboardio/Kaleidoscope-Focus [plugin:focus]: https://github.com/keyboardio/Kaleidoscope-Focus
[plugin:l-p-t]: https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme
## Using the extension ## Using the extension
To use the extension, include the header, tell it the number of layers you have, 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++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-Colormap.h> #include <Kaleidoscope-Colormap.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
@ -37,7 +35,7 @@ void setup (void) {
Kaleidoscope.setup(); Kaleidoscope.setup();
USE_PLUGINS(&ColormapEffect, &Focus); USE_PLUGINS(&ColormapEffect, &Focus);
ColormapEffect.configure (1); ColormapEffect.max_layers(1);
Focus.addHook(FOCUS_HOOK_LEDPALETTETHEME); Focus.addHook(FOCUS_HOOK_LEDPALETTETHEME);
Focus.addHook(FOCUS_HOOK_COLORMAP); Focus.addHook(FOCUS_HOOK_COLORMAP);
} }
@ -47,9 +45,10 @@ void setup (void) {
The extension provides an `ColormapEffect` singleton object, with a single method: 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 ## Dependencies

@ -21,8 +21,7 @@
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (Key_LEDEffectNext, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
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_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_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_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
@ -36,15 +35,14 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey),
),
}; };
void setup() { void setup() {
Kaleidoscope.use (&ColormapEffect, NULL); USE_PLUGINS(&ColormapEffect);
Kaleidoscope.setup(); Kaleidoscope.setup();
ColormapEffect.configure (1); ColormapEffect.max_layers(1);
ColormapEffect.activate(); ColormapEffect.activate();
} }

@ -16,25 +16,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope-Colormap.h> #include <Kaleidoscope-Colormap.h>
#include <EEPROM.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Focus.h> #include <Kaleidoscope-Focus.h>
#include <EEPROM.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
uint16_t ColormapEffect::mapBase; uint16_t ColormapEffect::map_base_;
uint8_t ColormapEffect::maxLayers; uint8_t ColormapEffect::max_layers_;
ColormapEffect::ColormapEffect(void) { ColormapEffect::ColormapEffect(void) {
} }
void void
ColormapEffect::configure (uint8_t maxLayers_) { ColormapEffect::begin(void) {
LEDMode::begin();
USE_PLUGINS(&::EEPROMSettings, &::LEDPaletteTheme); USE_PLUGINS(&::EEPROMSettings, &::LEDPaletteTheme);
}
void
ColormapEffect::max_layers(uint8_t max_) {
if (map_base_ != 0)
return;
maxLayers = maxLayers_; max_layers_ = max_;
mapBase = ::LEDPaletteTheme.reserveThemes (maxLayers); map_base_ = ::LEDPaletteTheme.reserveThemes(max_layers_);
} }
void void
@ -43,15 +54,15 @@ ColormapEffect::update (void) {
if (!Layer.isOn(l)) if (!Layer.isOn(l))
continue; continue;
::LEDPaletteTheme.update (mapBase, l); ::LEDPaletteTheme.update(map_base_, l);
} }
} }
bool bool
ColormapEffect::focusHook(const char *command) { ColormapEffect::focusHook(const char *command) {
return ::LEDPaletteTheme.themeFocusHandler (command, PSTR("colormap.map"), mapBase, maxLayers); return ::LEDPaletteTheme.themeFocusHandler(command, PSTR("colormap.map"), map_base_, max_layers_);
} }
}; } // namespace kaleidoscope
KaleidoscopePlugins::ColormapEffect ColormapEffect; kaleidoscope::ColormapEffect ColormapEffect;

@ -21,23 +21,25 @@
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h> #include <Kaleidoscope-LED-Palette-Theme.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class ColormapEffect : public LEDMode { class ColormapEffect : public LEDMode {
public: public:
ColormapEffect(void); ColormapEffect(void);
virtual void update (void) final; void begin(void) final;
void configure (uint8_t maxLayers); void update(void) final;
void max_layers(uint8_t max_);
static bool focusHook(const char *command); static bool focusHook(const char *command);
private: private:
static uint8_t maxLayers; static uint8_t max_layers_;
static uint16_t mapBase; static uint16_t map_base_;
};
}; };
} // namespace kaleidoscope
extern KaleidoscopePlugins::ColormapEffect ColormapEffect; extern kaleidoscope::ColormapEffect ColormapEffect;
#define FOCUS_HOOK_COLORMAP FOCUS_HOOK(ColormapEffect.focusHook, \ #define FOCUS_HOOK_COLORMAP FOCUS_HOOK(ColormapEffect.focusHook, \
"colormap.map") "colormap.map")

Loading…
Cancel
Save