Skip to content

Instantly share code, notes, and snippets.

@burke
Created September 30, 2022 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burke/eef4a5bf917331ba422eb87fd8af5df4 to your computer and use it in GitHub Desktop.
Save burke/eef4a5bf917331ba422eb87fd8af5df4 to your computer and use it in GitHub Desktop.
// -*- mode: c++ -*-
#include "Kaleidoscope.h"
#include "Kaleidoscope-Macros.h"
#include "Kaleidoscope-LEDControl.h"
#include "Kaleidoscope-LEDEffect-BootGreeting.h"
#include "Kaleidoscope-LED-Stalker.h"
#include "Kaleidoscope-SpaceCadet.h"
// Macros
enum {
R_M, R_Q, R_H, R_J, R_S, R_N, R_Y, R_V, B_C, B_O, B_T, B_F, B_N, B_I, B_R, B_P,
A_0, A_1, A_2, A_3, A_Q, A_W, A_E, A_R, A_T, A_A, A_S, A_D, A_F, A_Z, A_EN, A_I, A_P, A_H, A_J, A_K, A_L, A_N, A_CM, A_DT, A_SP,
A2_SP, A2_H, A2_L, A2_K, A2_J, A2_1, A2_2, A2_3, A2_4, A2_5, A2_6, A2_7, A2_8, A2_9, A2_0, A2_W, A2_E, A2_R, A2_Q, A2_T, A2_AL, A2_AR
};
// Keymap layers
enum { K_ROOT, K_FN, K_ANY, K_BF, K_AUX1, K_AUX2 };
// clang-format off
KEYMAPS(
[K_ROOT] = KEYMAP_STACKED (
___, 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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
/**/ /**/ /**/ /**/ /**/ /**/ ShiftToLayer(K_AUX1),
ShiftToLayer(K_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, ___,
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,
ShiftToLayer(K_BF), Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl, /**/ /**/ /**/
ShiftToLayer(K_FN) /**/ /**/ /**/ /**/ /**/ /**/
), [K_FN] = KEYMAP_STACKED (
___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_CapsLock,
Key_Tab, ___, ___, ___, ___, ___, ___,
Key_Home, ___, ___, ___, ___, ___, /**/
Key_End, Key_PrintScreen, Key_Insert, ___, ___, ___, ___,
/**/ /**/ /**/ ___, Key_Delete, ___, ___,
/**/ /**/ /**/ /**/ /**/ /**/ ___,
Consumer_ScanPreviousTrack, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11,
Consumer_PlaySlashPause, Consumer_ScanNextTrack, ___, ___, ___, ___, Key_F12,
/**/ Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, ___, ___,
Key_PcApplication, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Key_Backslash, Key_Pipe,
___, ___, Key_Enter, ___, /**/ /**/ /**/
___ /**/ /**/ /**/ /**/ /**/ /**/
), [K_ANY] = KEYMAP_STACKED (
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, M(B_R), M(B_T), ___,
___, ___, ___, ___, M(B_F), ___, /**/
___, ___, ___, M(B_C), ___, ___, ___,
/**/ /**/ /**/ ___, ___, ___, ___,
/**/ /**/ /**/ /**/ /**/ /**/ ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, M(B_I), M(B_O), M(B_P), ___,
/**/ ___, ___, ___, ___, ___, ___,
___, M(B_N), ___, ___, ___, ___, ___,
___, ___, ___, ___, /**/ /**/ /**/
___ /**/ /**/ /**/ /**/ /**/ /**/
), [K_BF] = KEYMAP_STACKED (
___, ___, ___, ___, ___, ___, ___,
___, M(R_Q), ___, ___, ___, ___, ___,
___, M(R_S), ___, ___, ___, ___, /**/
___, ___, ___, ___, M(R_V), ___, ___,
/**/ /**/ /**/ ___, ___, ___, ___,
/**/ /**/ /**/ /**/ /**/ /**/ ShiftToLayer(K_AUX2),
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, M(R_Y), ___, ___, ___,
/**/ M(R_H), M(R_J), ___, ___, ___, ___,
___, M(R_N), M(R_M), ___, ___, ___, ___,
___, ___, ___, ___, /**/ /**/ /**/
___ /**/ /**/ /**/ /**/ /**/ /**/
), [K_AUX1] = KEYMAP_STACKED (
___, M(A_1), M(A_2), M(A_3), ___, ___, ___,
___, M(A_Q), M(A_W), M(A_E), M(A_R), M(A_T), ___,
Key_Home, M(A_A), M(A_S), M(A_D), M(A_F), ___, /**/
Key_End, M(A_Z), ___, ___, ___, ___, ___,
/**/ /**/ /**/ ___, Key_Delete, ___, ___,
/**/ /**/ /**/ /**/ /**/ /**/ ___,
___, ___, ___, ___, ___, M(A_0), ___,
M(A_EN), ___, ___, M(A_I), ___, M(A_P), ___,
/**/ M(A_H), M(A_J), M(A_K), M(A_L), ___, ___,
ShiftToLayer(K_AUX2), M(A_N), ___, M(A_CM), M(A_DT), ___, ___,
___, ___, M(A_SP), ___, /**/ /**/ /**/
___ /**/ /**/ /**/ /**/ /**/ /**/
), [K_AUX2] = KEYMAP_STACKED (
___, M(A2_1), M(A2_2), M(A2_3), M(A2_4), M(A2_5), ___,
___, M(A2_Q), M(A2_W), M(A2_E), M(A2_R), M(A2_T), ___,
___, ___, ___, ___, ___, ___, /**/
___, ___, ___, ___, ___, ___, ___,
/**/ /**/ /**/ ___, ___, ___, ___,
/**/ /**/ /**/ /**/ /**/ /**/ ___,
___, M(A2_6), M(A2_7), M(A2_8), M(A2_9), M(A2_0), ___,
___, ___, ___, ___, ___, ___, ___,
/**/ M(A2_H), M(A2_J), M(A2_K), M(A2_L), ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, M(A2_SP), ___, /**/ /**/ /**/
___ /**/ /**/ /**/ /**/ /**/ /**/
)
)
// clang-format on
static void anyKeyMacro(KeyEvent &event) {
if (keyToggledOn(event.state)) {
event.key.setKeyCode(Key_A.getKeyCode() + (uint8_t)(millis() % 36));
event.key.setFlags(0);
}
}
#define BROWSE_MACRO(macro, key) \
case macro: \
if (keyToggledOn(event.state)) { \
return MACRO( \
D(LeftGui), D(LeftShift), D(LeftControl), D(LeftAlt), \
T(key), \
U(LeftGui), U(LeftShift), U(LeftControl), U(LeftAlt) \
); \
} \
break;
#define AUX1_MACRO(macro, key) \
case macro: \
if (keyToggledOn(event.state)) { \
return MACRO( \
D(LeftShift), D(LeftAlt), \
T(key), \
U(LeftShift), U(LeftAlt) \
); \
} \
break;
#define AUX2_MACRO(macro, key) \
case macro: \
if (keyToggledOn(event.state)) { \
return MACRO( \
D(LeftControl), D(LeftShift), D(LeftAlt), \
T(key), \
U(LeftControl), U(LeftShift), U(LeftAlt) \
); \
} \
break;
const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) {
switch (macro_id) {
BROWSE_MACRO(B_C, C);
BROWSE_MACRO(B_O, O);
BROWSE_MACRO(B_N, N);
BROWSE_MACRO(B_T, T);
BROWSE_MACRO(B_F, F);
BROWSE_MACRO(B_I, I);
BROWSE_MACRO(B_R, R);
BROWSE_MACRO(B_P, P);
AUX1_MACRO(A_0, 0);
AUX1_MACRO(A_1, 1);
AUX1_MACRO(A_2, 2);
AUX1_MACRO(A_3, 3);
AUX1_MACRO(A_A, A);
AUX1_MACRO(A_CM, Comma);
AUX1_MACRO(A_D, D);
AUX1_MACRO(A_DT, Period);
AUX1_MACRO(A_E, E);
AUX1_MACRO(A_EN, Enter);
AUX1_MACRO(A_F, F);
AUX1_MACRO(A_H, H);
AUX1_MACRO(A_I, I);
AUX1_MACRO(A_J, J);
AUX1_MACRO(A_K, K);
AUX1_MACRO(A_L, L);
AUX1_MACRO(A_N, N);
AUX1_MACRO(A_P, P);
AUX1_MACRO(A_Q, Q);
AUX1_MACRO(A_R, R);
AUX1_MACRO(A_S, S);
AUX1_MACRO(A_SP, Spacebar);
AUX1_MACRO(A_T, T);
AUX1_MACRO(A_W, W);
AUX1_MACRO(A_Z, Z);
AUX2_MACRO(A2_SP, Space);
AUX2_MACRO(A2_H, H);
AUX2_MACRO(A2_L, L);
AUX2_MACRO(A2_K, K);
AUX2_MACRO(A2_J, J);
AUX2_MACRO(A2_1, 1);
AUX2_MACRO(A2_2, 2);
AUX2_MACRO(A2_3, 3);
AUX2_MACRO(A2_4, 4);
AUX2_MACRO(A2_5, 5);
AUX2_MACRO(A2_6, 6);
AUX2_MACRO(A2_7, 7);
AUX2_MACRO(A2_8, 8);
AUX2_MACRO(A2_9, 9);
AUX2_MACRO(A2_0, 0);
AUX2_MACRO(A2_W, W);
AUX2_MACRO(A2_E, E);
AUX2_MACRO(A2_R, R);
AUX2_MACRO(A2_Q, Q);
AUX2_MACRO(A2_T, T);
AUX2_MACRO(A2_AL, LeftArrow);
AUX2_MACRO(A2_AR, RightArrow);
}
return MACRO_NONE;
}
KALEIDOSCOPE_INIT_PLUGINS(
Macros,
SpaceCadet,
BootGreetingEffect,
LEDControl,
StalkerEffect,
LEDOff
);
void setup() {
Kaleidoscope.setup();
static kaleidoscope::plugin::SpaceCadet::KeyBinding spacecadetmap[] = {
{Key_LeftShift, Key_LeftParen, 250}
, {Key_RightShift, Key_RightParen, 250}
, {Key_LeftGui, Key_LeftCurlyBracket, 250}
, {Key_LeftAlt, Key_RightCurlyBracket, 250}
, {Key_LeftControl, Key_LeftBracket, 250}
, {Key_RightControl, Key_RightBracket, 250}
, SPACECADET_MAP_END
};
SpaceCadet.setMap(spacecadetmap);
BootGreetingEffect.hue = 85;
StalkerEffect.variant = STALKER(BlazingTrail);
}
void loop() {
Kaleidoscope.loop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment