Last active
December 25, 2018 12:17
-
-
Save jamadagni/afe3848e1e5f95343e8e84fb6c60f4e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- mode: c++ -*- | |
// Copyright 2016 Keyboardio, inc. <jesse@keyboard.io> | |
// See "LICENSE" for license details | |
#include "Kaleidoscope.h" | |
#include "Kaleidoscope-Model01-TestMode.h" | |
#include "Kaleidoscope-MouseKeys.h" | |
#include "Kaleidoscope-Macros.h" | |
#include "Kaleidoscope-OneShot.h" | |
#include "Kaleidoscope-Escape-OneShot.h" | |
#include "Kaleidoscope-LEDControl.h" | |
#include "LED-Off.h" | |
#include "Kaleidoscope-LEDEffect-BootGreeting.h" | |
#include "Kaleidoscope-LEDEffect-Rainbow.h" | |
#include "Kaleidoscope-LEDEffect-SolidColor.h" | |
#include "Kaleidoscope-LEDEffect-Breathe.h" | |
#include "Kaleidoscope-NumPad.h" | |
#include "Kaleidoscope-LED-ActiveModColor.h" | |
#include "Kaleidoscope-HostPowerManagement.h" | |
enum { LYR_QWERTY, LYR_NUM, LYR_NAV, LYR_FN }; | |
enum { MACRO_PWD, MACRO_CONTEXT_MENU, MACRO_LED_OFF, MACRO_OSM_LEVEL4, | |
MACRO_ZOOM_IN, MACRO_ZOOM_OUT, | |
MACRO_SCRN_2_TOGGLE, MACRO_MV_WIN_TO_SCRN_1, MACRO_MV_WIN_TO_SCRN_2 }; | |
/* This comment temporarily turns off astyle's indent enforcement | |
* so we can make the keymaps actually resemble the physical key layout better | |
*/ | |
// *INDENT-OFF* | |
/* | |
Layer template: | |
[LAYER_ENUM_NAME] = KEYMAP_STACKED | |
(XXX, XXX, XXX, XXX, XXX, XXX, ___, | |
XXX, XXX, XXX, XXX, XXX, XXX, ___, | |
XXX, XXX, XXX, XXX, XXX, XXX, | |
XXX, XXX, XXX, XXX, XXX, XXX, ___, | |
___, ___, ___, ___, | |
___, | |
___, XXX, XXX, XXX, XXX, XXX, XXX, | |
___, XXX, XXX, XXX, XXX, XXX, XXX, | |
XXX, XXX, XXX, XXX, XXX, XXX, | |
___, XXX, XXX, XXX, XXX, XXX, XXX, | |
___, ___, ___, ___, | |
___), | |
*/ | |
//#define KEY_LEVEL3 Key_RightAlt | |
//#define KEY_LEVEL4 LSHIFT(Key_RightAlt) | |
//#define KEY_LEVEL5 Key_RightCtrl | |
#define OSM_LEVEL3 OSM(RightAlt) | |
#define OSM_LEVEL4 M(MACRO_OSM_LEVEL4) | |
#define KEY_ZOOM_IN M(MACRO_ZOOM_IN) | |
#define KEY_ZOOM_OUT M(MACRO_ZOOM_OUT) | |
#define KEY_GO_TOP LCTRL(Key_Home) | |
#define KEY_GO_BTM LCTRL(Key_End) | |
#define KEY_GO_WORD_LT LCTRL(Key_LeftArrow) | |
#define KEY_GO_WORD_RT LCTRL(Key_RightArrow) | |
#define KEY_GO_VIEW_PREV LALT(Key_LeftArrow) | |
#define KEY_GO_VIEW_NEXT LALT(Key_RightArrow) | |
#define KEY_GO_VIEW_UP LALT(Key_UpArrow) | |
#define KEY_GO_VIEW_HOME LALT(Key_Home) | |
#define KEY_GO_TAB_LT LCTRL(Key_PageUp) | |
#define KEY_GO_TAB_RT LCTRL(Key_PageDown) | |
#define KEY_GO_DESKTOP_LT LCTRL(LSHIFT(Key_PageUp)) | |
#define KEY_GO_DESKTOP_RT LCTRL(LSHIFT(Key_PageDown)) | |
#define KEY_WINDOW_MINIMIZE LCTRL(LSHIFT(Key_Home)) | |
#define KEY_WINDOW_MAXIMIZE LCTRL(LSHIFT(Key_End)) | |
#define KEY_WINDOW_OPACITY_DN LCTRL(LALT(Key_Home)) | |
#define KEY_WINDOW_OPACITY_UP LCTRL(LALT(Key_End)) | |
#define KEY_LINE_MOVE_UP LCTRL(LALT(Key_UpArrow)) | |
#define KEY_LINE_MOVE_DN LCTRL(LALT(Key_DownArrow)) | |
#define KEY_LINE_DUP_UP LCTRL(LSHIFT(Key_UpArrow)) | |
#define KEY_LINE_DUP_DN LCTRL(LSHIFT(Key_DownArrow)) | |
#define KEY_BLOCK_MODE LCTRL(LSHIFT(Key_B)) | |
KEYMAPS( | |
[LYR_QWERTY] = KEYMAP_STACKED | |
(Key_Backtick, Key_1, Key_2, Key_3, Key_4, Key_5, Key_Escape, | |
Key_LeftBracket, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, | |
Key_Minus, Key_A, Key_S, Key_D, Key_F, Key_G, | |
Key_Backslash, Key_Z, Key_X, Key_C, Key_V, Key_B, OSM(LeftAlt), | |
OSM(LeftGui), Key_Backspace, Key_Delete, Key_Insert, | |
OSL(LYR_NAV), | |
Key_F12, Key_6, Key_7, Key_8, Key_9, Key_0, Key_NonUsBackslashAndPipe, | |
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_RightBracket, | |
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Equals, | |
OSM(LeftControl), Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Quote, | |
OSM_LEVEL4, OSM(LeftShift), Key_Spacebar, OSM_LEVEL3, | |
OSL(LYR_FN)), | |
[LYR_NUM] = KEYMAP_STACKED | |
(LockLayer(LYR_QWERTY), XXX, XXX, XXX, XXX, XXX, ___, | |
XXX, XXX, XXX, Key_UpArrow, Key_KeypadLeftParen, Key_KeypadRightParen, ___, | |
XXX, XXX, Key_LeftArrow, Key_DownArrow, Key_RightArrow, XXX, | |
XXX, XXX, XXX, XXX, XXX, XXX, ___, | |
___, ___, ___, ___, | |
___, | |
___, Key_KeypadDivide, Key_Keypad7, Key_Keypad8, Key_Keypad9, XXX, XXX, | |
___, Key_KeypadMultiply, Key_Keypad4, Key_Keypad5, Key_Keypad6, XXX, XXX, | |
Key_KeypadAdd, Key_Keypad1, Key_Keypad2, Key_Keypad3, XXX, XXX, | |
___, Key_KeypadSubtract, Key_Keypad0, XXX, Key_KeypadDot, XXX, XXX, | |
___, ___, ___, ___, | |
___), | |
[LYR_NAV] = KEYMAP_STACKED | |
(___, Key_mouseScrollL, Key_mouseScrollUp, Key_mouseScrollR, Key_mouseWarpNW, Key_mouseWarpNE, ___, | |
XXX, KEY_ZOOM_IN, Key_mouseScrollDn, Key_mouseUp, Key_mouseWarpSW, Key_mouseWarpSE, ___, | |
XXX, KEY_ZOOM_OUT, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseWarpEnd, | |
XXX, XXX, XXX, Key_mouseBtnL, Key_mouseBtnR, XXX, ___, | |
___, ___, ___, ___, | |
___, | |
___, KEY_GO_TOP, Key_Home, Key_End, KEY_GO_DESKTOP_LT, KEY_GO_DESKTOP_RT, XXX, | |
___, Key_PageUp, KEY_GO_WORD_LT, Key_UpArrow, KEY_GO_WORD_RT, KEY_GO_TAB_LT, XXX, | |
Key_PageDown, Key_LeftArrow, Key_DownArrow, Key_RightArrow, KEY_GO_TAB_RT, XXX, | |
___, KEY_GO_BTM, KEY_GO_VIEW_PREV, KEY_GO_VIEW_UP, KEY_GO_VIEW_NEXT, KEY_GO_VIEW_HOME, XXX, | |
___, ___, ___, ___, | |
___), | |
[LYR_FN] = KEYMAP_STACKED | |
(___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, ___, | |
LockLayer(LYR_NUM), XXX, Key_LEDEffectPrevious, Key_LEDEffectNext, M(MACRO_LED_OFF), XXX, ___, | |
XXX, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, Consumer_PlaySlashPause, XXX, | |
KEY_BLOCK_MODE, XXX, XXX, XXX, M(MACRO_PWD), XXX, ___, | |
___, ___, ___, ___, | |
System_Sleep, | |
___, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, | |
___, KEY_WINDOW_MAXIMIZE, KEY_LINE_DUP_UP, KEY_LINE_MOVE_UP, XXX, XXX, KEY_WINDOW_OPACITY_UP, | |
KEY_WINDOW_MINIMIZE, KEY_LINE_DUP_DN, KEY_LINE_MOVE_DN, XXX, XXX, KEY_WINDOW_OPACITY_DN, | |
___, M(MACRO_SCRN_2_TOGGLE), M(MACRO_MV_WIN_TO_SCRN_1), M(MACRO_MV_WIN_TO_SCRN_2), XXX, XXX, Key_PrintScreen, | |
___, ___, ___, ___, | |
___), | |
) // KEYMAPS | |
/* Re-enable astyle's indent enforcement */ | |
// *INDENT-ON* | |
const macro_t * macroAction(uint8_t macroIndex, uint8_t keyState) | |
{ | |
switch (macroIndex) | |
{ | |
case MACRO_PWD: | |
if (keyToggledOn(keyState)) | |
return Macros.type(PSTR("my_low_security_pwd")); | |
break; | |
case MACRO_CONTEXT_MENU: | |
if (keyToggledOn(keyState)) | |
return MACRODOWN(T(PcApplication), Tr(LockLayer(LYR_NAV))); | |
break; | |
case MACRO_LED_OFF: | |
if (keyToggledOn(keyState)) | |
LEDOff.activate(); | |
break; | |
case MACRO_OSM_LEVEL4: | |
if (keyToggledOn(keyState)) | |
{ | |
OneShot.inject(OSM(RightAlt), keyState); | |
OneShot.inject(OSM(LeftShift), keyState); | |
} | |
break; | |
case MACRO_ZOOM_IN: | |
if (keyToggledOn(keyState)) | |
{ | |
handleKeyswitchEvent(Key_LeftControl, Macros.row, Macros.col, keyState); | |
handleKeyswitchEvent(Key_mouseScrollUp, Macros.row, Macros.col, keyState); | |
} | |
break; | |
case MACRO_ZOOM_OUT: | |
if (keyToggledOn(keyState)) | |
{ | |
handleKeyswitchEvent(Key_LeftControl, Macros.row, Macros.col, keyState); | |
handleKeyswitchEvent(Key_mouseScrollDn, Macros.row, Macros.col, keyState); | |
} | |
break; | |
case MACRO_SCRN_2_TOGGLE: | |
if (keyToggledOn(keyState)) | |
return MACRODOWN(I(50), D(LeftAlt), T(F2), U(LeftAlt), T(S), T(2), T(T), T(Enter)); | |
break; | |
case MACRO_MV_WIN_TO_SCRN_1: | |
if (keyToggledOn(keyState)) | |
return MACRODOWN(I(25), D(LeftAlt), T(F3), U(LeftAlt), T(S), T(1)); | |
break; | |
case MACRO_MV_WIN_TO_SCRN_2: | |
if (keyToggledOn(keyState)) | |
return MACRODOWN(I(25), D(LeftAlt), T(F3), U(LeftAlt), T(S), T(2)); | |
break; | |
} | |
return MACRO_NONE; | |
} | |
static kaleidoscope::LEDSolidColor LEDSolidYellow(130, 100, 0); | |
KALEIDOSCOPE_INIT_PLUGINS | |
( | |
TestMode, // invoked by tapping Prog, LED and the left Fn button at the same time. | |
MouseKeys, | |
Macros, | |
OneShot, | |
EscapeOneShot, | |
LEDControl, | |
LEDOff, | |
BootGreetingEffect, | |
LEDRainbowWaveEffect, | |
LEDSolidYellow, | |
LEDBreatheEffect, | |
NumPad, | |
ActiveModColorEffect, | |
HostPowerManagement | |
); | |
void setup() | |
{ | |
Kaleidoscope.setup(); | |
NumPad.numPadLayer = LYR_NUM; | |
LEDRainbowWaveEffect.brightness(150); | |
ActiveModColorEffect.sticky_color = CRGB(0, 255, 255); | |
} | |
// | |
// REST OF THE FILE ARE INTERNALS YOU DON'T NEED TO TOUCH | |
// | |
void loop() | |
{ | |
Kaleidoscope.loop(); | |
} | |
void toggleLedsOnSuspendResume(kaleidoscope::HostPowerManagement::Event event) | |
{ | |
switch (event) | |
{ | |
case kaleidoscope::HostPowerManagement::Suspend: | |
LEDControl.paused = true; | |
LEDControl.set_all_leds_to({0, 0, 0}); | |
LEDControl.syncLeds(); | |
break; | |
case kaleidoscope::HostPowerManagement::Resume: | |
LEDControl.paused = false; | |
LEDControl.refreshAll(); | |
break; | |
case kaleidoscope::HostPowerManagement::Sleep: | |
break; | |
} | |
} | |
void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) | |
{ | |
toggleLedsOnSuspendResume(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment