Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 24cbb5fcb4
commit 3a1342b38b

@ -9,38 +9,62 @@
[st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
TODO
The `FingerPainter` plugin provides an elaborate `LED` mode, in which one's able
to paint with their fingers: when edit mode is toggled on, keys will - instead
of performing their normal function - cycle through the global palette - as
provided by the [LED-Palette-Theme][plugin:l-p-t] plugin -, one by one for each tap.
This allows us to edit the theme with the keyboard only, without any special
software (except to toggle edit mode on and off).
## Using the plugin
TODO
To use the plugin, just include the header, add it to the list of used plugins,
and register the `Focus` hooks:
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Focus.h>
void setup() {
USE_PLUGINS(&EEPROMSettings, &FingerPainter, &Focus);
void setup () {
Kaleidoscope.setup ();
Kaleidoscope.setup();
USE_PLUGINS (&EEPROMSettings, &FingerPainter);
EEPROMSettings.seal();
// TODO
Focus.addHook(FOCUS_HOOK_FINGERPAINTER);
}
```
## Plugin methods
The plugin provides the `FingerPainter` object, which has the following methods:
The plugin provides the `FingerPainter` object, which provides no public methods.
## Focus commands
The plugin provides a single `Focus` hook: `FOCUS_HOOK_FINGERPAINTER`, which
in turn provides the following commands:
**TODO**
### `fingerpainter.clear`
> Clears the canvas, so that one can start a new painting.
### `fingerpainter.toggle`
> Toggles the painting mode on and off.
## Dependencies
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings)
* [Kaleidoscope-LED-Palette-Theme](https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme)
* [Kaleidoscope-Focus](https://github.com/keyboardio/Kaleidoscope-Focus)
* [Kaleidoscope-LED-Palette-Theme][plugin:l-p-t]
* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)
[plugin:l-p-t]: https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme
## Further reading
Starting from the [example][plugin:example] is the recommended way of getting

@ -20,14 +20,13 @@
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Macros.h>
#include <Kaleidoscope-Focus.h>
#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_NoKey, 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,
@ -41,27 +40,17 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
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_skip),
};
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 0 && key_toggled_off(keyState)) {
FingerPainter.toggleEdit();
}
return MACRO_NONE;
}
void setup() {
Serial.begin(9600);
USE_PLUGINS(&LEDOff, &EEPROMSettings, &FingerPainter, &Focus);
Kaleidoscope.setup();
USE_PLUGINS(&LEDOff, &EEPROMSettings, &FingerPainter, &Macros);
EEPROMSettings.seal();
Focus.addHook(FOCUS_HOOK_FINGERPAINTER);
FingerPainter.activate();
}

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

@ -20,26 +20,26 @@
#include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins {
namespace kaleidoscope {
class FingerPainter : public LEDMode {
public:
FingerPainter(void);
void begin(void) final;
virtual void update(void) final;
void update(void) final;
static void toggleEdit(void);
static void toggle(void);
static bool focusHook(const char *command);
private:
static uint16_t colorBase;
static bool editMode;
static uint16_t color_base_;
static bool edit_mode_;
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
};
extern KaleidoscopePlugins::FingerPainter FingerPainter;
extern kaleidoscope::FingerPainter FingerPainter;
#define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \
"fingerpainter.toggle\n" \

Loading…
Cancel
Save