Conform to the latest Kaleidoscope Style Guide

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

@ -20,43 +20,43 @@
#include <Kaleidoscope-Cycle.h> #include <Kaleidoscope-Cycle.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_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_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,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_Cycle, Key_Cycle,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
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_Cycle), Key_Cycle),
}; };
void cycleAction(Key previous_key, uint8_t cycle_count) { void cycleAction(Key previous_key, uint8_t cycle_count) {
if (previous_key.raw == Key_E.raw) { if (previous_key.raw == Key_E.raw) {
if (cycle_count == 1) { if (cycle_count == 1) {
Cycle.replace(Key_F); Cycle.replace(Key_F);
} else if (cycle_count == 2) { } else if (cycle_count == 2) {
Cycle.replace(Key_G); Cycle.replace(Key_G);
}
}
if (previous_key.raw == Key_A.raw) {
cycleThrough(Key_A, Key_B, Key_C, Key_D);
} }
}
if (previous_key.raw == Key_A.raw) {
cycleThrough(Key_A, Key_B, Key_C, Key_D);
}
} }
void setup() { void setup() {
USE_PLUGINS(&Cycle); USE_PLUGINS(&Cycle);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
void loop() { void loop() {
Kaleidoscope.loop(); Kaleidoscope.loop();
} }

@ -34,55 +34,55 @@ Cycle::Cycle(void) {
} }
void Cycle::begin(void) { void Cycle::begin(void) {
event_handler_hook_use(eventHandlerHook); 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); handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED); handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED); handle_keyswitch_event(key, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
} }
void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) { void Cycle::replace(uint8_t cycle_size, const Key cycle_steps[]) {
uint8_t idx = cycle_count_ % cycle_size; uint8_t idx = cycle_count_ % cycle_size;
Key key; Key key;
key.raw = pgm_read_word(cycle_steps + idx); key.raw = pgm_read_word(cycle_steps + idx);
replace(key); replace(key);
} }
// --- hooks --- // --- hooks ---
Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { Key Cycle::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
if (key_state & INJECTED) if (key_state & INJECTED)
return mapped_key; return mapped_key;
if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) { if (!key_is_pressed(key_state) && !key_was_pressed(key_state)) {
if (isCycle(mapped_key)) if (isCycle(mapped_key))
return Key_NoKey; return Key_NoKey;
return mapped_key; return mapped_key;
} }
if (!isCycle(mapped_key)) { if (!isCycle(mapped_key)) {
if (key_toggled_on(key_state)) { if (key_toggled_on(key_state)) {
last_non_cycle_key_.raw = mapped_key.raw; last_non_cycle_key_.raw = mapped_key.raw;
cycle_count_ = 0; cycle_count_ = 0;
}
return mapped_key;
} }
return mapped_key;
}
if (!key_toggled_off(key_state)) if (!key_toggled_off(key_state))
return Key_NoKey;
++cycle_count_;
cycleAction(last_non_cycle_key_, cycle_count_);
return Key_NoKey; return Key_NoKey;
++cycle_count_;
cycleAction(last_non_cycle_key_, cycle_count_);
return Key_NoKey;
} }
}; };

@ -30,19 +30,19 @@
namespace kaleidoscope { namespace kaleidoscope {
class Cycle : public KaleidoscopePlugin { class Cycle : public KaleidoscopePlugin {
public: public:
Cycle(void); Cycle(void);
void begin(void) final; void begin(void) final;
static void replace(Key key); static void replace(Key key);
static void replace(uint8_t cycle_size, const Key cycle_steps[]); static void replace(uint8_t cycle_size, const Key cycle_steps[]);
private: private:
static Key last_non_cycle_key_; static Key last_non_cycle_key_;
static uint8_t cycle_count_; static uint8_t cycle_count_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
}; };

Loading…
Cancel
Save