astyle pass

pull/135/head
Jesse Vincent 8 years ago
parent 57ebb17d8f
commit 8c6b8433cc
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -48,20 +48,20 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
switch (macroIndex) { switch (macroIndex) {
case M_APPSWITCH: case M_APPSWITCH:
return macroAppSwitch (keyState); return macroAppSwitch(keyState);
case M_APPCANCEL: case M_APPCANCEL:
return macroAppCancel (keyState); return macroAppCancel(keyState);
} }
return MACRO_NONE; return MACRO_NONE;
} }
void setup () { void setup() {
Kaleidoscope.setup (KEYMAP_SIZE); Kaleidoscope.setup(KEYMAP_SIZE);
Kaleidoscope.use (&HostOS, &Macros, NULL); Kaleidoscope.use(&HostOS, &Macros, NULL);
} }
void loop () { void loop() {
Kaleidoscope.loop (); Kaleidoscope.loop();
} }

@ -27,31 +27,31 @@ using namespace KaleidoscopePlugins::HostOS;
static bool appSwitchActive = false; static bool appSwitchActive = false;
const macro_t *macroAppSwitch (uint8_t keyState) { const macro_t *macroAppSwitch(uint8_t keyState) {
Key mod = Key_LeftAlt; Key mod = Key_LeftAlt;
if (HostOS.os () == OSX) if (HostOS.os() == OSX)
mod = Key_LeftGui; mod = Key_LeftGui;
// Key was just pressed, or is being held // Key was just pressed, or is being held
if (key_is_pressed(keyState)) { if (key_is_pressed(keyState)) {
return MACRO(Dr(mod), D(Tab), END); return MACRO(Dr(mod), D(Tab), END);
} }
// Key was just released // Key was just released
if (key_toggled_off(keyState)) { if (key_toggled_off(keyState)) {
return MACRO(U(Tab), Dr(mod), END); return MACRO(U(Tab), Dr(mod), END);
} }
// Key is not pressed, and was not just released. // Key is not pressed, and was not just released.
// if appSwitchActive is true, we continue holding Alt. // if appSwitchActive is true, we continue holding Alt.
if (appSwitchActive) { if (appSwitchActive) {
return MACRO(Dr(mod), END); return MACRO(Dr(mod), END);
} }
// otherwise we do nothing // otherwise we do nothing
return MACRO_NONE; return MACRO_NONE;
} }
const macro_t *macroAppCancel (uint8_t keyState) { const macro_t *macroAppCancel(uint8_t keyState) {
if (key_toggled_on (keyState)) if (key_toggled_on(keyState))
appSwitchActive = false; appSwitchActive = false;
return MACRO_NONE; return MACRO_NONE;
} }

@ -22,9 +22,9 @@
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Macros.h>
enum { enum {
M_APPSWITCH, M_APPSWITCH,
M_APPCANCEL, M_APPCANCEL,
}; };
const macro_t *macroAppSwitch (uint8_t keyState); const macro_t *macroAppSwitch(uint8_t keyState);
const macro_t *macroAppCancel (uint8_t keyState); const macro_t *macroAppCancel(uint8_t keyState);

@ -21,91 +21,91 @@
#define GENERIC_FN2 KEYMAP_STACKED ( \ #define GENERIC_FN2 KEYMAP_STACKED ( \
___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, XXX, \ ___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, XXX, \
Key_Tab, Key_mouseBtnM, Key_mouseUp, ___, Key_mouseWarpNW, Key_mouseWarpNE, Consumer_ScanNextTrack, \ Key_Tab, Key_mouseBtnM, Key_mouseUp, ___, Key_mouseWarpNW, Key_mouseWarpNE, Consumer_ScanNextTrack, \
Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseWarpSW, Key_mouseWarpSE, \ Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseWarpSW, Key_mouseWarpSE, \
Key_End, Key_Z, Key_X, Key_C, Key_V, Key_mouseWarpEnd, ___, \ Key_End, Key_Z, Key_X, Key_C, Key_V, Key_mouseWarpEnd, ___, \
Key_LeftControl, Key_mouseBtnL, Key_LeftGui, Key_LeftShift, \ Key_LeftControl, Key_mouseBtnL, Key_LeftGui, Key_LeftShift, \
___,\ ___, \
\ \
XXX, Key_F6, Key_F7, Key_F8, Key_F9, ___, ___,\ XXX, Key_F6, Key_F7, Key_F8, Key_F9, ___, ___, \
Key_Delete, Consumer_PlaySlashPause, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, System_Sleep,\ Key_Delete, Consumer_PlaySlashPause, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, System_Sleep, \
Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, Key_F11, Key_F12,\ Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, Key_F11, Key_F12, \
___, Consumer_VolumeDecrement, Consumer_VolumeIncrement, Key_BacklightDown, Key_BacklightUp, Key_Backslash, Key_Pipe,\ ___, Consumer_VolumeDecrement, Consumer_VolumeIncrement, Key_BacklightDown, Key_BacklightUp, Key_Backslash, Key_Pipe, \
Key_RightShift, Key_RightAlt, Key_mouseBtnR, Key_RightControl,\ Key_RightShift, Key_RightAlt, Key_mouseBtnR, Key_RightControl, \
___\ ___\
) )
#define NUMPAD KEYMAP (\ #define NUMPAD KEYMAP (\
___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadSubtract, ___, \ ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadSubtract, ___, \
___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadAdd, ___, \ ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadAdd, ___, \
___, ___, ___, ___, ___, ___, ___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, Key_Quote, \ ___, ___, ___, ___, ___, ___, ___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, Key_Quote, \
___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide, Key_Enter, \ ___, ___, ___, ___, ___, ___, ___, ___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide, Key_Enter, \
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,\ Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, \
Key_Keymap1_Momentary, Key_Keymap1_Momentary \ Key_Keymap1_Momentary, Key_Keymap1_Momentary \
) )
#define QWERTY KEYMAP ( \ #define QWERTY KEYMAP ( \
___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \ ___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext, ___, Key_6, Key_7, Key_8, Key_9, Key_0, Key_ToggleNumlock, \
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, \ Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, \
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, \ Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, \
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, ___, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, \ Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, ___, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, \
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,\ Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, \
Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \ Key_KeymapNext_Momentary, Key_KeymapNext_Momentary \
) )
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
QWERTY, QWERTY,
GENERIC_FN2, GENERIC_FN2,
NUMPAD NUMPAD
}; };
static LEDSolidColor solidRed (60, 0, 0); static LEDSolidColor solidRed(60, 0, 0);
static LEDSolidColor solidOrange (60, 20, 0); static LEDSolidColor solidOrange(60, 20, 0);
static LEDSolidColor solidYellow (40, 35, 0); static LEDSolidColor solidYellow(40, 35, 0);
static LEDSolidColor solidGreen (0, 100, 0); static LEDSolidColor solidGreen(0, 100, 0);
static LEDSolidColor solidBlue (0, 15, 100); static LEDSolidColor solidBlue(0, 15, 100);
static LEDSolidColor solidIndigo (0, 0, 100); static LEDSolidColor solidIndigo(0, 0, 100);
static LEDSolidColor solidViolet (70, 0, 60); static LEDSolidColor solidViolet(70, 0, 60);
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == TOGGLENUMLOCK && key_toggled_on(keyState)) { if (macroIndex == TOGGLENUMLOCK && key_toggled_on(keyState)) {
return NumLock.toggle (Macros.row, Macros.col, NUMPAD_KEYMAP); return NumLock.toggle(Macros.row, Macros.col, NUMPAD_KEYMAP);
} }
if (macroIndex == 1 && key_toggled_on(keyState)) { if (macroIndex == 1 && key_toggled_on(keyState)) {
Serial.print("Keyboard.IO keyboard driver v0.00"); Serial.print("Keyboard.IO keyboard driver v0.00");
return MACRO(I(25), return MACRO(I(25),
D(LeftShift), T(M), U(LeftShift), T(O), T(D), T(E), T(L), D(LeftShift), T(M), U(LeftShift), T(O), T(D), T(E), T(L),
T(Spacebar), T(Spacebar),
W(100), W(100),
T(0), T(1), T(0), T(1),
END); END);
} }
return MACRO_NONE; return MACRO_NONE;
} }
void setup() { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
Kaleidoscope.use(&TestMode, Kaleidoscope.use(&TestMode,
&LEDControl, &LEDOff, &LEDControl, &LEDOff,
&solidRed, &solidOrange, &solidYellow, &solidGreen, &solidBlue, &solidIndigo, &solidViolet, &solidRed, &solidOrange, &solidYellow, &solidGreen, &solidBlue, &solidIndigo, &solidViolet,
&LEDBreatheEffect, &LEDRainbowEffect, &LEDChaseEffect, &NumLock, &LEDBreatheEffect, &LEDRainbowEffect, &LEDChaseEffect, &NumLock,
&Macros, &Macros,
&MouseKeys, &MouseKeys,
NULL); NULL);
LEDOff.activate(); LEDOff.activate();
} }
void loop() { void loop() {
Kaleidoscope.loop(); Kaleidoscope.loop();
} }

@ -9,131 +9,131 @@ Kaleidoscope_::Kaleidoscope_(void) {
void void
Kaleidoscope_::setup(void) { Kaleidoscope_::setup(void) {
KeyboardHardware.setup(); KeyboardHardware.setup();
Keyboard.begin(); Keyboard.begin();
// A workaround, so that the compiler does not optimize this out... // A workaround, so that the compiler does not optimize this out...
handle_keyswitch_event (Key_NoKey, 255, 255, 0); handle_keyswitch_event(Key_NoKey, 255, 255, 0);
} }
void void
Kaleidoscope_::loop(void) { Kaleidoscope_::loop(void) {
KeyboardHardware.scan_matrix(); KeyboardHardware.scan_matrix();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) { for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
loopHook hook = loopHooks[i]; loopHook hook = loopHooks[i];
(*hook)(false); (*hook)(false);
} }
Keyboard.sendReport(); Keyboard.sendReport();
Keyboard.releaseAll(); Keyboard.releaseAll();
for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) { for (byte i = 0; loopHooks[i] != NULL && i < HOOK_MAX; i++) {
loopHook hook = loopHooks[i]; loopHook hook = loopHooks[i];
(*hook)(true); (*hook)(true);
} }
} }
void void
Kaleidoscope_::use(KaleidoscopePlugin *plugin, ...) { Kaleidoscope_::use(KaleidoscopePlugin *plugin, ...) {
va_list ap; va_list ap;
KaleidoscopePlugin *p; KaleidoscopePlugin *p;
plugin->begin(); plugin->begin();
va_start(ap, plugin); va_start(ap, plugin);
while ((p = va_arg(ap, KaleidoscopePlugin*)) != NULL) { while ((p = va_arg(ap, KaleidoscopePlugin*)) != NULL) {
p->begin(); p->begin();
} }
va_end(ap); va_end(ap);
} }
void void
Kaleidoscope_::replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) { Kaleidoscope_::replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook) {
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == oldHook) { if (eventHandlers[i] == oldHook) {
eventHandlers[i] = newHook; eventHandlers[i] = newHook;
return; return;
}
} }
}
} }
void void
Kaleidoscope_::appendEventHandlerHook (eventHandlerHook hook) { Kaleidoscope_::appendEventHandlerHook(eventHandlerHook hook) {
replaceEventHandlerHook((eventHandlerHook)NULL, hook); replaceEventHandlerHook((eventHandlerHook)NULL, hook);
} }
void void
Kaleidoscope_::useEventHandlerHook (eventHandlerHook hook) { Kaleidoscope_::useEventHandlerHook(eventHandlerHook hook) {
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (eventHandlers[i] == hook) if (eventHandlers[i] == hook)
return; return;
} }
appendEventHandlerHook(hook); appendEventHandlerHook(hook);
} }
void void
Kaleidoscope_::replaceLoopHook(loopHook oldHook, loopHook newHook) { Kaleidoscope_::replaceLoopHook(loopHook oldHook, loopHook newHook) {
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == oldHook) { if (loopHooks[i] == oldHook) {
loopHooks[i] = newHook; loopHooks[i] = newHook;
return; return;
}
} }
}
} }
void void
Kaleidoscope_::appendLoopHook(loopHook hook) { Kaleidoscope_::appendLoopHook(loopHook hook) {
replaceLoopHook((loopHook)NULL, hook); replaceLoopHook((loopHook)NULL, hook);
} }
void void
Kaleidoscope_::useLoopHook(loopHook hook) { Kaleidoscope_::useLoopHook(loopHook hook) {
for (byte i = 0; i < HOOK_MAX; i++) { for (byte i = 0; i < HOOK_MAX; i++) {
if (loopHooks[i] == hook) if (loopHooks[i] == hook)
return; return;
} }
appendLoopHook (hook); appendLoopHook(hook);
} }
bool bool
Kaleidoscope_::focusHook(const char *command) { Kaleidoscope_::focusHook(const char *command) {
enum { enum {
ON, ON,
OFF, OFF,
GETSTATE, GETSTATE,
} subCommand; } subCommand;
if (strncmp_P(command, PSTR("layer."), 6) != 0) if (strncmp_P(command, PSTR("layer."), 6) != 0)
return false; return false;
if (strcmp_P (command + 6, PSTR("on")) == 0) if (strcmp_P(command + 6, PSTR("on")) == 0)
subCommand = ON; subCommand = ON;
else if (strcmp_P(command + 6, PSTR("off")) == 0) else if (strcmp_P(command + 6, PSTR("off")) == 0)
subCommand = OFF; subCommand = OFF;
else if (strcmp_P(command + 6, PSTR("getState")) == 0) else if (strcmp_P(command + 6, PSTR("getState")) == 0)
subCommand = GETSTATE; subCommand = GETSTATE;
else else
return false; return false;
switch (subCommand) { switch (subCommand) {
case ON: { case ON: {
uint8_t layer = Serial.parseInt(); uint8_t layer = Serial.parseInt();
Layer.on(layer); Layer.on(layer);
break; break;
} }
case OFF: { case OFF: {
uint8_t layer = Serial.parseInt(); uint8_t layer = Serial.parseInt();
Layer.off(layer); Layer.off(layer);
break; break;
} }
case GETSTATE: case GETSTATE:
Serial.println(Layer.getLayerState(), BIN); Serial.println(Layer.getLayerState(), BIN);
break; break;
} }
return true; return true;
} }
Kaleidoscope_ Kaleidoscope; Kaleidoscope_ Kaleidoscope;

@ -52,51 +52,51 @@ extern HARDWARE_IMPLEMENTATION KeyboardHardware;
}) })
class KaleidoscopePlugin { class KaleidoscopePlugin {
public: public:
virtual void begin(void) = 0; virtual void begin(void) = 0;
}; };
class Kaleidoscope_ { class Kaleidoscope_ {
public: public:
Kaleidoscope_(void); Kaleidoscope_(void);
void setup(const byte keymap_count) { void setup(const byte keymap_count) {
setup(); setup();
} }
void setup(void); void setup(void);
void loop(void); void loop(void);
void use(KaleidoscopePlugin *plugin, ...) __attribute__((sentinel)); void use(KaleidoscopePlugin *plugin, ...) __attribute__((sentinel));
// ---- hooks ---- // ---- hooks ----
/* /*
* In most cases, one only wants a single copy of a hook. On the other hand, * In most cases, one only wants a single copy of a hook. On the other hand,
* plugins that depend on other plugins, may want to make it easier for the * plugins that depend on other plugins, may want to make it easier for the
* end-user to use the plugin, and call the setup function of the dependent * end-user to use the plugin, and call the setup function of the dependent
* plugins too. In case the end-user calls the same setup function, we'd end up * plugins too. In case the end-user calls the same setup function, we'd end up
* with hooks registered multiple times. * with hooks registered multiple times.
* *
* To avoid this, protection against double-registration has been introduced. * To avoid this, protection against double-registration has been introduced.
* The `event_handler_hook_use` and `loop_hook_use` functions will only allow * The `event_handler_hook_use` and `loop_hook_use` functions will only allow
* one copy of the hook. The `event_handler_hook_append` and `loop_hook_append` * one copy of the hook. The `event_handler_hook_append` and `loop_hook_append`
* functions will, on the other hand, just append the hooks, and not care about * functions will, on the other hand, just append the hooks, and not care about
* protection. * protection.
*/ */
typedef Key (*eventHandlerHook)(Key mappedKey, byte row, byte col, uint8_t keyState); typedef Key(*eventHandlerHook)(Key mappedKey, byte row, byte col, uint8_t keyState);
static eventHandlerHook eventHandlers[HOOK_MAX]; static eventHandlerHook eventHandlers[HOOK_MAX];
static void replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook); static void replaceEventHandlerHook(eventHandlerHook oldHook, eventHandlerHook newHook);
static void appendEventHandlerHook(eventHandlerHook hook); static void appendEventHandlerHook(eventHandlerHook hook);
static void useEventHandlerHook(eventHandlerHook hook); static void useEventHandlerHook(eventHandlerHook hook);
typedef void (*loopHook)(bool postClear); typedef void (*loopHook)(bool postClear);
static loopHook loopHooks[HOOK_MAX]; static loopHook loopHooks[HOOK_MAX];
static void replaceLoopHook(loopHook oldHook, loopHook newHook); static void replaceLoopHook(loopHook oldHook, loopHook newHook);
static void appendLoopHook(loopHook hook); static void appendLoopHook(loopHook hook);
static void useLoopHook(loopHook hook); static void useLoopHook(loopHook hook);
static bool focusHook(const char *command); static bool focusHook(const char *command);
}; };
extern Kaleidoscope_ Kaleidoscope; extern Kaleidoscope_ Kaleidoscope;

@ -12,49 +12,49 @@
typedef union Key_ { typedef union Key_ {
struct { struct {
uint8_t keyCode; uint8_t keyCode;
uint8_t flags; uint8_t flags;
}; };
uint16_t raw; uint16_t raw;
inline bool operator==(uint16_t rhs) { inline bool operator==(uint16_t rhs) {
return this->raw == rhs; return this->raw == rhs;
} }
inline bool operator==(const Key_ rhs) { inline bool operator==(const Key_ rhs) {
return this->raw == rhs.raw; return this->raw == rhs.raw;
} }
inline Key_& operator=(uint16_t raw) { inline Key_& operator=(uint16_t raw) {
this->raw = raw; this->raw = raw;
return *this; return *this;
} }
inline bool operator!=(const Key_& rhs) { inline bool operator!=(const Key_& rhs) {
return !(*this == rhs); return !(*this == rhs);
} }
inline bool operator>=(uint16_t raw) { inline bool operator>=(uint16_t raw) {
return this->raw >= raw; return this->raw >= raw;
} }
inline bool operator<=(uint16_t raw) { inline bool operator<=(uint16_t raw) {
return this->raw <= raw; return this->raw <= raw;
} }
inline bool operator>(uint16_t raw) { inline bool operator>(uint16_t raw) {
return this->raw > raw; return this->raw > raw;
} }
inline bool operator<(uint16_t raw) { inline bool operator<(uint16_t raw) {
return this->raw < raw; return this->raw < raw;
} }
inline bool operator>=(const Key_& other) { inline bool operator>=(const Key_& other) {
return this->raw >= other.raw; return this->raw >= other.raw;
} }
inline bool operator<=(const Key_& other) { inline bool operator<=(const Key_& other) {
return this->raw <= other.raw; return this->raw <= other.raw;
} }
inline bool operator>(const Key_& other) { inline bool operator>(const Key_& other) {
return this->raw > other.raw; return this->raw > other.raw;
} }
inline bool operator<(const Key_& other) { inline bool operator<(const Key_& other) {
return this->raw < other.raw; return this->raw < other.raw;
} }
} Key; } Key;

@ -1,96 +1,96 @@
#include "Kaleidoscope.h" #include "Kaleidoscope.h"
static bool handle_synthetic_keyswitch_event(Key mappedKey, uint8_t keyState) { static bool handle_synthetic_keyswitch_event(Key mappedKey, uint8_t keyState) {
if (mappedKey.flags & RESERVED) if (mappedKey.flags & RESERVED)
return false; return false;
if (!(mappedKey.flags & SYNTHETIC)) if (!(mappedKey.flags & SYNTHETIC))
return false; return false;
if (mappedKey.flags & IS_INTERNAL) { if (mappedKey.flags & IS_INTERNAL) {
return false; return false;
} else if (mappedKey.flags & IS_CONSUMER) { } else if (mappedKey.flags & IS_CONSUMER) {
if (key_is_pressed(keyState)) if (key_is_pressed(keyState))
ConsumerControl.press(mappedKey.keyCode); ConsumerControl.press(mappedKey.keyCode);
else if (key_was_pressed(keyState)) else if (key_was_pressed(keyState))
ConsumerControl.release(mappedKey.keyCode); ConsumerControl.release(mappedKey.keyCode);
} else if (mappedKey.flags & IS_SYSCTL) { } else if (mappedKey.flags & IS_SYSCTL) {
if (key_is_pressed(keyState)) if (key_is_pressed(keyState))
SystemControl.press(mappedKey.keyCode); SystemControl.press(mappedKey.keyCode);
else if (key_was_pressed(keyState)) else if (key_was_pressed(keyState))
SystemControl.release(); SystemControl.release();
} else if (mappedKey.flags & SWITCH_TO_KEYMAP) { } else if (mappedKey.flags & SWITCH_TO_KEYMAP) {
// Should not happen, handled elsewhere. // Should not happen, handled elsewhere.
} }
return true; return true;
} }
static bool handle_keyswitch_event_default(Key mappedKey, byte row, byte col, uint8_t keyState) { static bool handle_keyswitch_event_default(Key mappedKey, byte row, byte col, uint8_t keyState) {
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
if (mappedKey.flags & SYNTHETIC) { if (mappedKey.flags & SYNTHETIC) {
handle_synthetic_keyswitch_event( mappedKey, keyState); handle_synthetic_keyswitch_event(mappedKey, keyState);
} else if (key_is_pressed(keyState)) { } else if (key_is_pressed(keyState)) {
press_key(mappedKey); press_key(mappedKey);
} else if (key_toggled_off(keyState) && (keyState & INJECTED)) { } else if (key_toggled_off(keyState) && (keyState & INJECTED)) {
release_key(mappedKey); release_key(mappedKey);
} }
return true; return true;
} }
void press_key(Key mappedKey) { void press_key(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) { if (mappedKey.flags & SHIFT_HELD) {
Keyboard.press(Key_LeftShift.keyCode); Keyboard.press(Key_LeftShift.keyCode);
} }
if (mappedKey.flags & CTRL_HELD) { if (mappedKey.flags & CTRL_HELD) {
Keyboard.press(Key_LeftControl.keyCode); Keyboard.press(Key_LeftControl.keyCode);
} }
if (mappedKey.flags & LALT_HELD) { if (mappedKey.flags & LALT_HELD) {
Keyboard.press(Key_LeftAlt.keyCode); Keyboard.press(Key_LeftAlt.keyCode);
} }
if (mappedKey.flags & RALT_HELD) { if (mappedKey.flags & RALT_HELD) {
Keyboard.press(Key_RightAlt.keyCode); Keyboard.press(Key_RightAlt.keyCode);
} }
if (mappedKey.flags & GUI_HELD) { if (mappedKey.flags & GUI_HELD) {
Keyboard.press(Key_LeftGui.keyCode); Keyboard.press(Key_LeftGui.keyCode);
} }
Keyboard.press(mappedKey.keyCode); Keyboard.press(mappedKey.keyCode);
} }
void release_key(Key mappedKey) { void release_key(Key mappedKey) {
if (mappedKey.flags & SHIFT_HELD) { if (mappedKey.flags & SHIFT_HELD) {
Keyboard.release(Key_LeftShift.keyCode); Keyboard.release(Key_LeftShift.keyCode);
} }
if (mappedKey.flags & CTRL_HELD) { if (mappedKey.flags & CTRL_HELD) {
Keyboard.release(Key_LeftControl.keyCode); Keyboard.release(Key_LeftControl.keyCode);
} }
if (mappedKey.flags & LALT_HELD) { if (mappedKey.flags & LALT_HELD) {
Keyboard.release(Key_LeftAlt.keyCode); Keyboard.release(Key_LeftAlt.keyCode);
} }
if (mappedKey.flags & RALT_HELD) { if (mappedKey.flags & RALT_HELD) {
Keyboard.release(Key_RightAlt.keyCode); Keyboard.release(Key_RightAlt.keyCode);
} }
if (mappedKey.flags & GUI_HELD) { if (mappedKey.flags & GUI_HELD) {
Keyboard.release(Key_LeftGui.keyCode); Keyboard.release(Key_LeftGui.keyCode);
} }
Keyboard.release(mappedKey.keyCode); Keyboard.release(mappedKey.keyCode);
} }
void handle_keyswitch_event(Key mappedKey, byte row, byte col, uint8_t keyState) { void handle_keyswitch_event(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!(keyState & INJECTED)) { if (!(keyState & INJECTED)) {
mappedKey = Layer.lookup(row, col); mappedKey = Layer.lookup(row, col);
} }
for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) { for (byte i = 0; Kaleidoscope.eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i]; Kaleidoscope_::eventHandlerHook handler = Kaleidoscope.eventHandlers[i];
mappedKey = (*handler)(mappedKey, row, col, keyState); mappedKey = (*handler)(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
}
mappedKey = Layer.eventHandler(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw) if (mappedKey.raw == Key_NoKey.raw)
return; return;
handle_keyswitch_event_default(mappedKey, row, col, keyState); }
mappedKey = Layer.eventHandler(mappedKey, row, col, keyState);
if (mappedKey.raw == Key_NoKey.raw)
return;
handle_keyswitch_event_default(mappedKey, row, col, keyState);
} }

@ -5,145 +5,145 @@ static uint32_t LayerState;
uint8_t Layer_::highestLayer; uint8_t Layer_::highestLayer;
uint8_t Layer_::keyMap[ROWS][COLS]; uint8_t Layer_::keyMap[ROWS][COLS];
Key (*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM; Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM;
static void handle_keymap_keyswitch_event(Key keymapEntry, uint8_t keyState) { static void handle_keymap_keyswitch_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.keyCode >= MOMENTARY_OFFSET) { if (keymapEntry.keyCode >= MOMENTARY_OFFSET) {
uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET; uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET;
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
if ( target == KEYMAP_NEXT) { if (target == KEYMAP_NEXT) {
Layer.next(); Layer.next();
} else if ( target == KEYMAP_PREVIOUS) { } else if (target == KEYMAP_PREVIOUS) {
Layer.previous(); Layer.previous();
} else { } else {
Layer.on(target); Layer.on(target);
} }
}
if (key_toggled_off(keyState)) {
if ( target == KEYMAP_NEXT) {
Layer.previous();
} else if ( target == KEYMAP_PREVIOUS) {
Layer.next();
} else {
Layer.off(target);
}
}
// switch keymap and stay there
} else if (key_toggled_on(keyState)) {
if (Layer.isOn (keymapEntry.keyCode) && keymapEntry.keyCode)
Layer.off(keymapEntry.keyCode);
else
Layer.on(keymapEntry.keyCode);
} }
if (key_toggled_off(keyState)) {
if (target == KEYMAP_NEXT) {
Layer.previous();
} else if (target == KEYMAP_PREVIOUS) {
Layer.next();
} else {
Layer.off(target);
}
}
// switch keymap and stay there
} else if (key_toggled_on(keyState)) {
if (Layer.isOn(keymapEntry.keyCode) && keymapEntry.keyCode)
Layer.off(keymapEntry.keyCode);
else
Layer.on(keymapEntry.keyCode);
}
} }
Key Key
Layer_::eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState) { Layer_::eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (mappedKey.flags != (SYNTHETIC | SWITCH_TO_KEYMAP)) if (mappedKey.flags != (SYNTHETIC | SWITCH_TO_KEYMAP))
return mappedKey; return mappedKey;
handle_keymap_keyswitch_event(mappedKey, keyState); handle_keymap_keyswitch_event(mappedKey, keyState);
return Key_NoKey; return Key_NoKey;
} }
Layer_::Layer_ (void) { Layer_::Layer_(void) {
defaultLayer (0); defaultLayer(0);
} }
Key Key
Layer_::getKeyFromPROGMEM (uint8_t layer, byte row, byte col) { Layer_::getKeyFromPROGMEM(uint8_t layer, byte row, byte col) {
Key key; Key key;
key.raw = pgm_read_word(&(keymaps[layer][row][col])); key.raw = pgm_read_word(&(keymaps[layer][row][col]));
return key; return key;
} }
void void
Layer_::mergeLayers(void) { Layer_::mergeLayers(void) {
memset (keyMap, DefaultLayer, ROWS * COLS); memset(keyMap, DefaultLayer, ROWS * COLS);
if (LayerState == (uint32_t)(1 << DefaultLayer)) if (LayerState == (uint32_t)(1 << DefaultLayer))
return; return;
for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) { for (uint8_t c = 0; c < COLS; c++) {
int8_t layer = highestLayer; int8_t layer = highestLayer;
while (layer > DefaultLayer) { while (layer > DefaultLayer) {
if (Layer.isOn (layer)) { if (Layer.isOn(layer)) {
Key mappedKey = (*getKey)(layer, r, c); Key mappedKey = (*getKey)(layer, r, c);
if (mappedKey != Key_Transparent) { if (mappedKey != Key_Transparent) {
keyMap[r][c] = layer; keyMap[r][c] = layer;
break; break;
} }
}
layer--;
}
} }
layer--;
}
} }
}
} }
Key Layer_::lookup(byte row, byte col) { Key Layer_::lookup(byte row, byte col) {
uint8_t layer = keyMap[row][col]; uint8_t layer = keyMap[row][col];
return (*getKey)(layer, row, col); return (*getKey)(layer, row, col);
} }
uint8_t Layer_::top (void) { uint8_t Layer_::top(void) {
for (int8_t i = 31; i >= 0; i--) { for (int8_t i = 31; i >= 0; i--) {
if (bitRead (LayerState, i)) if (bitRead(LayerState, i))
return i; return i;
} }
return 0; return 0;
} }
void Layer_::move (uint8_t layer) { void Layer_::move(uint8_t layer) {
LayerState = 0; LayerState = 0;
on (layer); on(layer);
} }
void Layer_::on (uint8_t layer) { void Layer_::on(uint8_t layer) {
bitSet (LayerState, layer); bitSet(LayerState, layer);
if (layer > highestLayer) if (layer > highestLayer)
highestLayer = layer; highestLayer = layer;
mergeLayers(); mergeLayers();
} }
void Layer_::off (uint8_t layer) { void Layer_::off(uint8_t layer) {
bitClear (LayerState, layer); bitClear(LayerState, layer);
if (layer == highestLayer) if (layer == highestLayer)
highestLayer = top(); highestLayer = top();
mergeLayers(); mergeLayers();
} }
boolean Layer_::isOn (uint8_t layer) { boolean Layer_::isOn(uint8_t layer) {
return bitRead(LayerState, layer); return bitRead(LayerState, layer);
} }
void Layer_::next (void) { void Layer_::next(void) {
on (top () + 1); on(top() + 1);
} }
void Layer_::previous (void) { void Layer_::previous(void) {
off (top ()); off(top());
} }
void Layer_::defaultLayer (uint8_t layer) { void Layer_::defaultLayer(uint8_t layer) {
move (layer); move(layer);
DefaultLayer = layer; DefaultLayer = layer;
} }
uint8_t Layer_::defaultLayer (void) { uint8_t Layer_::defaultLayer(void) {
return DefaultLayer; return DefaultLayer;
} }
uint32_t Layer_::getLayerState (void) { uint32_t Layer_::getLayerState(void) {
return LayerState; return LayerState;
} }
Layer_ Layer; Layer_ Layer;

@ -5,38 +5,38 @@
#include KALEIDOSCOPE_HARDWARE_H #include KALEIDOSCOPE_HARDWARE_H
class Layer_ { class Layer_ {
public: public:
Layer_(void); Layer_(void);
static Key lookup(byte row, byte col); static Key lookup(byte row, byte col);
static void on(uint8_t layer); static void on(uint8_t layer);
static void off(uint8_t layer); static void off(uint8_t layer);
static void move(uint8_t layer); static void move(uint8_t layer);
static uint8_t top(void); static uint8_t top(void);
static void next(void); static void next(void);
static void previous(void); static void previous(void);
static boolean isOn(uint8_t layer); static boolean isOn(uint8_t layer);
static void defaultLayer(uint8_t layer); static void defaultLayer(uint8_t layer);
static uint8_t defaultLayer(void); static uint8_t defaultLayer(void);
static uint32_t getLayerState(void); static uint32_t getLayerState(void);
static Key eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState);
static Key (*getKey)(uint8_t layer, byte row, byte col); static Key(*getKey)(uint8_t layer, byte row, byte col);
static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col); static Key getKeyFromPROGMEM(uint8_t layer, byte row, byte col);
private: private:
static uint8_t highestLayer; static uint8_t highestLayer;
static uint8_t keyMap[ROWS][COLS]; static uint8_t keyMap[ROWS][COLS];
static void mergeLayers(void); static void mergeLayers(void);
}; };
Key layer_getKey (uint8_t layer, uint8_t r, uint8_t c); Key layer_getKey(uint8_t layer, uint8_t r, uint8_t c);
extern Layer_ Layer; extern Layer_ Layer;

Loading…
Cancel
Save