Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 14d236ed39
commit 38cf866870

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Cycle.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Cycle
[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
If you ever wanted a key that works like keys on old cell phones, when you press
a key and it cycles through a number of options in a sequence, then the cycling
@ -33,16 +33,15 @@ each time the cycling key triggers.
Key_Cycle
// later in the Sketch:
void cycleAction (Key previousKey, uint8_t cycleCount) {
if (previousKey.raw == Key_A.raw) {
void cycleAction(Key previous_key, uint8_t cycle_count) {
if (previous_key.raw == Key_A.raw) {
cycleThrough (Key_B, Key_C, Key_D);
}
}
void setup(void) {
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&Cycle, NULL);
USE_PLUGINS(&Cycle);
Kaleidoscope.setup();
}
```
@ -83,7 +82,7 @@ method explained below.
## Overrideable methods
### `cycleAction(previousKey, cycleCount)`
### `cycleAction(previous_key, cycle_count)`
> The heart and soul of the plugin, that must be defined in the Sketch. It will
> be called whenever the cycling key triggers, and the two arguments are the

@ -21,8 +21,7 @@
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
(Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
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,
@ -36,27 +35,26 @@ 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_Cycle
),
Key_Cycle),
};
void cycleAction (Key previousKey, uint8_t cycleCount) {
if (previousKey.raw == Key_E.raw) {
if (cycleCount == 1) {
void cycleAction(Key previous_key, uint8_t cycle_count) {
if (previous_key.raw == Key_E.raw) {
if (cycle_count == 1) {
Cycle.replace(Key_F);
} else if (cycleCount == 2) {
} else if (cycle_count == 2) {
Cycle.replace(Key_G);
}
}
if (previousKey.raw == Key_A.raw) {
if (previous_key.raw == Key_A.raw) {
cycleThrough(Key_A, Key_B, Key_C, Key_D);
}
}
void setup() {
Kaleidoscope.setup (KEYMAP_SIZE);
USE_PLUGINS(&Cycle);
Kaleidoscope.use (&Cycle, NULL);
Kaleidoscope.setup();
}
void loop() {

@ -19,29 +19,25 @@
#include <Kaleidoscope.h>
#include <Kaleidoscope-Cycle.h>
using namespace KaleidoscopePlugins::Ranges;
namespace KaleidoscopePlugins {
namespace kaleidoscope {
// --- state ---
Key Cycle::lastNonCycleKey;
uint8_t Cycle::cycleCount;
Key Cycle::last_non_cycle_key_;
uint8_t Cycle::cycle_count_;
// --- helpers ---
#define isCycle(k) (k.raw == CYCLE)
#define isCycle(k) (k.raw == KaleidoscopePlugins::Ranges::CYCLE)
// --- api ---
Cycle::Cycle(void) {
}
void
Cycle::begin (void) {
event_handler_hook_use (this->eventHandlerHook);
void Cycle::begin(void) {
event_handler_hook_use(eventHandlerHook);
}
void
Cycle::replace (Key key) {
void Cycle::replace(Key key) {
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
@ -53,48 +49,45 @@ Cycle::replace (Key key) {
Keyboard.sendReport();
}
void
Cycle::replace (uint8_t cycleSize, const Key cycleSteps[]) {
uint8_t idx = cycleCount % cycleSize;
void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {
uint8_t idx = cycle_count_ % cycle_size;
Key key;
key.raw = pgm_read_word (cycleSteps + idx);
key.raw = pgm_read_word(cycle_steps + idx);
replace(key);
}
// --- hooks ---
Key
Cycle::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
if (keyState & INJECTED)
return mappedKey;
Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
if (key_state & INJECTED)
return mapped_key;
if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) {
if (isCycle (mappedKey))
if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) {
if (isCycle(mapped_key))
return Key_NoKey;
return mappedKey;
return mapped_key;
}
if (!isCycle (mappedKey)) {
if (key_toggled_on (keyState)) {
lastNonCycleKey.raw = mappedKey.raw;
cycleCount = 0;
if (!isCycle(mapped_key)) {
if (key_toggled_on(key_state)) {
last_non_cycle_key_.raw = mapped_key.raw;
cycle_count_ = 0;
}
return mappedKey;
return mapped_key;
}
if (!key_toggled_off (keyState))
if (!key_toggled_off(key_state))
return Key_NoKey;
cycleCount++;
cycleAction (lastNonCycleKey, cycleCount);
++cycle_count_;
cycleAction(last_non_cycle_key_, cycle_count_);
return Key_NoKey;
}
};
__attribute__((weak))
void
cycleAction (Key previousKey, uint8_t cycleCount) {
void cycleAction(Key previous_key, uint8_t cycle_count) {
}
KaleidoscopePlugins::Cycle Cycle;
kaleidoscope::Cycle Cycle;

@ -18,33 +18,34 @@
#pragma once
#include <Kaleidoscope.h>
#include <Kaleidoscope-Ranges.h>
#define Key_Cycle (Key){ .raw = KaleidoscopePlugins::Ranges::CYCLE }
#define Key_Cycle ((Key) { .raw = KaleidoscopePlugins::Ranges::CYCLE })
#define cycleThrough(...) ({ \
static const Key __k[] PROGMEM = { __VA_ARGS__ }; \
Cycle.replace(sizeof(__k) / sizeof(Key), &__k[0]); \
})
namespace KaleidoscopePlugins {
namespace kaleidoscope {
class Cycle : public KaleidoscopePlugin {
public:
Cycle(void);
virtual void begin (void) final;
void begin(void) final;
static void replace(Key key);
static void replace (uint8_t cycleSize, const Key cycleSteps[]);
static void replace(uint8_t cycle_size, const Key cycle_steps[]);
private:
static Key lastNonCycleKey;
static uint8_t cycleCount;
static Key last_non_cycle_key_;
static uint8_t cycle_count_;
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);
};
};
void cycleAction (Key previousKey, uint8_t cycleCount);
void cycleAction(Key previous_key, uint8_t cycle_count);
extern KaleidoscopePlugins::Cycle Cycle;
extern kaleidoscope::Cycle Cycle;

Loading…
Cancel
Save