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: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 [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 ## 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++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h> #include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Focus.h>
void setup() { void setup() {
USE_PLUGINS(&EEPROMSettings, &FingerPainter, &Focus);
Kaleidoscope.setup(); Kaleidoscope.setup();
USE_PLUGINS (&EEPROMSettings, &FingerPainter); EEPROMSettings.seal();
// TODO Focus.addHook(FOCUS_HOOK_FINGERPAINTER);
} }
``` ```
## Plugin methods ## 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 ## Dependencies
* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) * [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) * [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl)
[plugin:l-p-t]: https://github.com/keyboardio/Kaleidoscope-LED-Palette-Theme
## Further reading ## Further reading
Starting from the [example][plugin:example] is the recommended way of getting Starting from the [example][plugin:example] is the recommended way of getting

@ -20,14 +20,13 @@
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FingerPainter.h> #include <Kaleidoscope-FingerPainter.h>
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Focus.h>
#include "LED-Off.h" #include "LED-Off.h"
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
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_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,
@ -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_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_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() { void setup() {
Serial.begin(9600); USE_PLUGINS(&LEDOff, &EEPROMSettings, &FingerPainter, &Focus);
Kaleidoscope.setup(); Kaleidoscope.setup();
USE_PLUGINS(&LEDOff, &EEPROMSettings, &FingerPainter, &Macros);
EEPROMSettings.seal(); EEPROMSettings.seal();
Focus.addHook(FOCUS_HOOK_FINGERPAINTER);
FingerPainter.activate(); FingerPainter.activate();
} }

@ -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;

@ -20,26 +20,26 @@
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class FingerPainter : public LEDMode { class FingerPainter : public LEDMode {
public: public:
FingerPainter(void); FingerPainter(void);
void begin(void) final; 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); static bool focusHook(const char *command);
private: private:
static uint16_t colorBase; static uint16_t color_base_;
static bool editMode; 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, \ #define FOCUS_HOOK_FINGERPAINTER FOCUS_HOOK(FingerPainter.focusHook, \
"fingerpainter.toggle\n" \ "fingerpainter.toggle\n" \

Loading…
Cancel
Save