Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head^2
Gergely Nagy 8 years ago
parent a0db8238ff
commit 8d00a83a44

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-ShapeShifter.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-ShapeShifter
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52
[st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&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
`ShapeShifter` is a plugin that makes it considerably easier to change what
symbol is input when a key is pressed together with `Shift`. If one wants to
@ -28,17 +28,18 @@ configure the provided `ShapeShifter` object to use the dictionary:
#include <Kaleidoscope.h>
#include <Kaleidoscope-ShapeShifter.h>
static const KaleidoscopePlugins::ShapeShifter::dictionary_t shapeShiftDictionary[] PROGMEM = {
static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = {
{Key_1, Key_4},
{Key_4, Key_1},
{Key_NoKey, Key_NoKey},
};
void setup() {
ShapeShifter.configure (shapeShiftDictionary);
USE_PLUGINS(&ShapeShifter);
Kaleidoscope.setup();
USE_PLUGINS (&ShapeShifter);
ShapeShifter.dictionary = shape_shift_dictionary;
}
```
@ -48,12 +49,13 @@ Key_NoKey}` pair, and **must** reside in `PROGMEM`.
## Plugin methods
The plugin provides the `ShapeShifter` object, with the following methods:
The plugin provides the `ShapeShifter` object, with the following methods and
properties:
### `.configure(dictionary)`
### `.dictionary`
> Tells `ShapeShifter` to use the specified dictionary. The dictionary is an
> array of `KaleidoscopePlugins::ShapeShifter::dictionary_t` elements, which is
> Set this property to the dictionary `ShapeShifter` should use. The dictionary
> is an array of `kaleidoscope::ShapeShifter::dictionary_t` elements, which is
> just a very verbose way of saying that its a pair of keys. The first one is
> the one to replace, and the other is to replace it with.
>

@ -19,8 +19,6 @@
#include <Kaleidoscope.h>
#include <Kaleidoscope-ShapeShifter.h>
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
@ -38,24 +36,21 @@ 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_NoKey
),
Key_NoKey),
};
static const KaleidoscopePlugins::ShapeShifter::dictionary_t shapeShiftDictionary[] PROGMEM = {
static const kaleidoscope::ShapeShifter::dictionary_t shape_shift_dictionary[] PROGMEM = {
{Key_1, Key_2},
{Key_2, Key_1},
{Key_NoKey, Key_NoKey},
};
void setup() {
ShapeShifter.configure(shapeShiftDictionary);
USE_PLUGINS(&ShapeShifter);
Kaleidoscope.setup();
USE_PLUGINS(&ShapeShifter);
ShapeShifter.dictionary = shape_shift_dictionary;
}
void loop() {

@ -18,42 +18,35 @@
#include <Kaleidoscope-ShapeShifter.h>
namespace KaleidoscopePlugins {
namespace kaleidoscope {
const ShapeShifter::dictionary_t *ShapeShifter::dictionary = NULL;
bool ShapeShifter::modActive;
bool ShapeShifter::mod_active_;
ShapeShifter::ShapeShifter(void) {
}
void
ShapeShifter::begin(void) {
event_handler_hook_use(this->eventHandlerHook);
loop_hook_use(this->loopHook);
void ShapeShifter::begin(void) {
event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
}
void
ShapeShifter::configure(const dictionary_t dictionary_[]) {
dictionary = (const dictionary_t *)dictionary_;
}
void
ShapeShifter::loopHook(bool postClear) {
if (postClear)
void ShapeShifter::loopHook(bool is_post_clear) {
if (is_post_clear)
return;
modActive = Keyboard.isModifierActive(Key_LeftShift.keyCode) ||
mod_active_ = Keyboard.isModifierActive(Key_LeftShift.keyCode) ||
Keyboard.isModifierActive(Key_RightShift.keyCode);
}
Key
ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
ShapeShifter::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
if (!dictionary)
return mappedKey;
return mapped_key;
// If Shift is not active, bail out early.
if (!modActive)
return mappedKey;
if (!mod_active_)
return mapped_key;
Key orig, repl;
@ -63,12 +56,12 @@ ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta
orig.raw = pgm_read_word(&(dictionary[i].original.raw));
i++;
} while (orig.raw != Key_NoKey.raw &&
orig.raw != mappedKey.raw);
orig.raw != mapped_key.raw);
i--;
// If not found, bail out.
if (orig.raw == Key_NoKey.raw)
return mappedKey;
return mapped_key;
repl.raw = pgm_read_word(&(dictionary[i].replacement.raw));
@ -76,6 +69,6 @@ ShapeShifter::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keySta
return repl;
}
};
}
KaleidoscopePlugins::ShapeShifter ShapeShifter;
kaleidoscope::ShapeShifter ShapeShifter;

@ -20,7 +20,8 @@
#include <Kaleidoscope.h>
namespace KaleidoscopePlugins {
namespace kaleidoscope {
class ShapeShifter : public KaleidoscopePlugin {
public:
typedef struct {
@ -31,15 +32,14 @@ class ShapeShifter : public KaleidoscopePlugin {
void begin(void) final;
static void configure(const dictionary_t dictionary[]);
private:
static const dictionary_t *dictionary;
static bool modActive;
private:
static bool mod_active_;
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState);
static void loopHook(bool postClear);
};
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
static void loopHook(bool is_post_clear);
};
extern KaleidoscopePlugins::ShapeShifter ShapeShifter;
}
extern kaleidoscope::ShapeShifter ShapeShifter;

Loading…
Cancel
Save