Last active
July 22, 2019 15:00
-
-
Save CeleritasCelery/2526d1807a4b9ef2b0052d3658ed43e3 to your computer and use it in GitHub Desktop.
keyboardio layout
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. <[email protected]> | |
// See "LICENSE" for license details | |
#ifndef BUILD_INFORMATION | |
#define BUILD_INFORMATION "locally built" | |
#endif | |
// The Kaleidoscope core | |
#include "Kaleidoscope.h" | |
// Plugins | |
#include <Kaleidoscope-OneShot.h> | |
#include <kaleidoscope/hid.h> | |
#include <Kaleidoscope-LEDControl.h> | |
#include <Kaleidoscope-LED-ActiveModColor.h> | |
#include "Kaleidoscope-EEPROM-Settings.h" | |
#include <Kaleidoscope-HostOS.h> | |
#include <Kaleidoscope-Unicode.h> | |
#include "Kaleidoscope-EEPROM-Keymap.h" | |
#include "Kaleidoscope-FocusSerial.h" | |
#include "Kaleidoscope-MouseKeys.h" | |
#include "Kaleidoscope-Macros.h" | |
#include "Kaleidoscope-LEDControl.h" | |
#include "Kaleidoscope-NumPad.h" | |
#include "Kaleidoscope-LEDEffect-BootGreeting.h" | |
#include "Kaleidoscope-LEDEffect-SolidColor.h" | |
#include "Kaleidoscope-LEDEffect-Breathe.h" | |
#include "Kaleidoscope-LEDEffect-Chase.h" | |
#include "Kaleidoscope-LEDEffect-Rainbow.h" | |
#include "Kaleidoscope-LED-Stalker.h" | |
#include "Kaleidoscope-LED-AlphaSquare.h" | |
#include "Kaleidoscope-Model01-TestMode.h" | |
#include "Kaleidoscope-HostPowerManagement.h" | |
#include "Kaleidoscope-MagicCombo.h" | |
#include "Kaleidoscope-USB-Quirks.h" | |
enum { MACRO_VERSION_INFO, | |
MACRO_ANY, | |
MACRO_VNC, | |
OSM_CTRL_ALT, | |
OSM_CTRL_SHIFT, | |
OSM_ALT_SHIFT, | |
OSM_CTRL_ALT_SHIFT, | |
UNI_INVISIBLE, | |
UNI_ARROW | |
}; | |
enum { PRIMARY, NUMPAD, FUNCTION }; // layers | |
/* This comment temporarily turns off astyle's indent enforcement | |
* so we can make the keymaps actually resemble the physical key layout better | |
*/ | |
// *INDENT-OFF* | |
KEYMAPS( | |
[PRIMARY] = 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_LeftParen, Key_A, Key_S, Key_D, Key_F, Key_G, | |
Key_RightParen, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, | |
OSM(LeftControl), Key_Spacebar, OSM(LeftAlt), M(OSM_CTRL_ALT), | |
OSL(FUNCTION), | |
Key_LeftGui, Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD), | |
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, | |
M(OSM_CTRL_ALT_SHIFT), Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, | |
M(OSM_ALT_SHIFT), M(OSM_CTRL_SHIFT), Key_Backspace, OSM(RightShift), | |
OSL(FUNCTION)), | |
[NUMPAD] = KEYMAP_STACKED | |
(___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, | |
___, | |
M(MACRO_VERSION_INFO), ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadSubtract, ___, | |
___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadAdd, ___, | |
___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, ___, | |
___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide, Key_Delete, | |
___, ___, ___, ___, | |
___), | |
[FUNCTION] = KEYMAP_STACKED | |
(___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_CapsLock, | |
Key_Tab, M(MACRO_VNC), Key_mouseUp, ___, Key_mouseBtnR, Key_mouseWarpEnd, Key_mouseWarpNE, | |
Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseBtnL, Key_mouseWarpNW, | |
Key_End, Key_PrintScreen, Key_Insert, M(UNI_INVISIBLE), Key_mouseBtnM, Key_mouseWarpSW, Key_mouseWarpSE, | |
___, Key_Enter, ___, ___, | |
___, | |
Consumer_ScanPreviousTrack, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, | |
Consumer_PlaySlashPause, Consumer_ScanNextTrack, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, Key_F12, | |
Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, ___, ___, | |
Key_PcApplication, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Key_Backslash, Key_Pipe, | |
___, ___, Key_Delete, ___, | |
___) | |
) // KEYMAPS( | |
/* Re-enable astyle's indent enforcement */ | |
// *INDENT-ON* | |
static void versionInfoMacro(uint8_t keyState) { | |
if (keyToggledOn(keyState)) { | |
Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope ")); | |
Macros.type(PSTR(BUILD_INFORMATION)); | |
} | |
} | |
static void anyKeyMacro(uint8_t keyState) { | |
static Key lastKey; | |
bool toggledOn = false; | |
if (keyToggledOn(keyState)) { | |
lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36); | |
toggledOn = true; | |
} | |
if (keyIsPressed(keyState)) | |
kaleidoscope::hid::pressKey(lastKey, toggledOn); | |
} | |
static void insertUnicode (uint32_t character, uint8_t keyState) { | |
if (keyToggledOn(keyState)) { | |
Unicode.type(character); | |
} | |
} | |
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { | |
switch (macroIndex) { | |
case MACRO_VERSION_INFO: | |
versionInfoMacro(keyState); | |
break; | |
case MACRO_ANY: | |
anyKeyMacro(keyState); | |
break; | |
case UNI_INVISIBLE: | |
insertUnicode(0x2063, keyState); | |
break; | |
case UNI_ARROW: | |
insertUnicode(0x2192, keyState); | |
break; | |
case MACRO_VNC: | |
return MACRODOWN(D(LeftGui), D(LeftShift), T(RightArrow), U(LeftGui), U(LeftShift), T(F5)); | |
// Macros.play(MACRODOWN(D(LeftGui), D(LeftShift), T(RightArrow), U(LeftGui), U(LeftShift))); | |
// break; | |
case OSM_CTRL_ALT: | |
OneShot.inject(OSM(LeftAlt), keyState); | |
OneShot.inject(OSM(LeftControl), keyState); | |
break; | |
case OSM_CTRL_SHIFT: | |
OneShot.inject(OSM(LeftControl), keyState); | |
OneShot.inject(OSM(LeftShift), keyState); | |
break; | |
case OSM_ALT_SHIFT: | |
OneShot.inject(OSM(LeftAlt), keyState); | |
OneShot.inject(OSM(LeftShift), keyState); | |
break; | |
case OSM_CTRL_ALT_SHIFT: | |
OneShot.inject(OSM(LeftControl), keyState); | |
OneShot.inject(OSM(LeftAlt), keyState); | |
OneShot.inject(OSM(LeftShift), keyState); | |
break; | |
} | |
return MACRO_NONE; | |
} | |
// These 'solid' color effect definitions define a rainbow of | |
// LED color modes calibrated to draw 500mA or less on the | |
// Keyboardio Model 01. | |
static kaleidoscope::LEDSolidColor solidRed(160, 0, 0); | |
static kaleidoscope::LEDSolidColor solidOrange(140, 70, 0); | |
static kaleidoscope::LEDSolidColor solidYellow(130, 100, 0); | |
static kaleidoscope::LEDSolidColor solidGreen(0, 160, 0); | |
static kaleidoscope::LEDSolidColor solidBlue(0, 70, 130); | |
static kaleidoscope::LEDSolidColor solidIndigo(0, 0, 170); | |
static kaleidoscope::LEDSolidColor solidViolet(130, 0, 120); | |
/** toggleLedsOnSuspendResume toggles the LEDs off when the host goes to sleep, | |
* and turns them back on when it wakes up. | |
*/ | |
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; | |
} | |
} | |
/** hostPowerManagementEventHandler dispatches power management events (suspend, | |
* resume, and sleep) to other functions that perform action based on these | |
* events. | |
*/ | |
void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { | |
toggleLedsOnSuspendResume(event); | |
} | |
enum { | |
// Toggle between Boot (6-key rollover; for BIOSes and early boot) and NKRO | |
// mode. | |
COMBO_TOGGLE_NKRO_MODE | |
}; | |
/** A tiny wrapper, to be used by MagicCombo. | |
* This simply toggles the keyboard protocol via USBQuirks, and wraps it within | |
* a function with an unused argument, to match what MagicCombo expects. | |
*/ | |
static void toggleKeyboardProtocol(uint8_t combo_index) { | |
USBQuirks.toggleKeyboardProtocol(); | |
} | |
/** Magic combo list, a list of key combo and action pairs the firmware should | |
* recognise. | |
*/ | |
USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol, | |
// Left Fn + Esc + Shift | |
.keys = { R3C6, R2C6, R3C7 } | |
}); | |
// First, tell Kaleidoscope which plugins you want to use. | |
// The order can be important. For example, LED effects are | |
// added in the order they're listed here. | |
KALEIDOSCOPE_INIT_PLUGINS( | |
EEPROMSettings, | |
EEPROMKeymap, | |
LEDControl, | |
ActiveModColorEffect, | |
Focus, | |
FocusSettingsCommand, | |
FocusEEPROMCommand, | |
BootGreetingEffect, | |
TestMode, | |
LEDControl, | |
LEDOff, | |
LEDRainbowEffect, | |
LEDRainbowWaveEffect, | |
LEDChaseEffect, | |
solidRed, solidOrange, solidYellow, solidGreen, solidBlue, solidIndigo, solidViolet, | |
LEDBreatheEffect, | |
AlphaSquareEffect, | |
StalkerEffect, | |
NumPad, | |
Macros, | |
MouseKeys, | |
HostPowerManagement, | |
MagicCombo, | |
USBQuirks, | |
OneShot, | |
HostOS, | |
Unicode | |
); | |
void setup() { | |
Kaleidoscope.setup(); | |
NumPad.numPadLayer = NUMPAD; | |
ActiveModColorEffect.highlight_color = CRGB(0x00, 0xff, 0xff); | |
AlphaSquare.color = CRGB(255, 0, 0); | |
LEDRainbowEffect.brightness(150); | |
LEDRainbowWaveEffect.brightness(150); | |
StalkerEffect.variant = STALKER(BlazingTrail); | |
LEDOff.activate(); | |
EEPROMKeymap.setup(5, EEPROMKeymap.Mode::EXTEND); | |
OneShot.time_out = 1000; | |
OneShot.disableStickabilityForModifiers(); | |
HostOS.os(kaleidoscope::hostos::WINDOWS); | |
} | |
void loop() { | |
Kaleidoscope.loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment