#ifndef BUILD_INFORMATION
#define BUILD_INFORMATION "locally built"
#endif
#include "Kaleidoscope.h"
#include "Kaleidoscope-EEPROM-Settings.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-Model01-TestMode.h"
#include "Kaleidoscope-HostPowerManagement.h"
#include "Kaleidoscope-MagicCombo.h"
#include "Kaleidoscope-USB-Quirks.h"
enum { MACRO_VERSION_INFO,
MACRO_ANY
};
enum { PRIMARY, NUMPAD, FUNCTION, FVWM };
#define PRIMARY_KEYMAP_QWERTY
KEYMAPS(
#if defined (PRIMARY_KEYMAP_QWERTY)
[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_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(FVWM),
M(MACRO_ANY), 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,
Key_RightAlt, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
ShiftToLayer(FUNCTION)),
#elif defined (PRIMARY_KEYMAP_DVORAK)
[PRIMARY] = KEYMAP_STACKED
(___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_Tab,
Key_PageUp, Key_A, Key_O, Key_E, Key_U, Key_I,
Key_PageDown, Key_Semicolon, Key_Q, Key_J, Key_K, Key_X, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
ShiftToLayer(FVWM),
M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
Key_Enter, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Slash,
Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus,
Key_RightAlt, Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals,
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
ShiftToLayer(FUNCTION)),
#else
#error "No default keymap defined. You should make sure that you have a line like '#define PRIMARY_KEYMAP_QWERTY' in your sketch"
#endif
[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_Enter,
___, ___, ___, ___,
___),
[FUNCTION] = KEYMAP_STACKED
(___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_CapsLock,
Key_Tab, ___, 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, ___, Key_mouseBtnM, Key_mouseWarpSW, Key_mouseWarpSE,
___, Key_Delete, ___, ___,
___,
___, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11,
___, ___, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, Key_F12,
Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, ___, ___,
Key_PcApplication, ___, ___, ___, ___, Key_Backslash, Key_Pipe,
___, ___, Key_Enter, ___,
___),
[FVWM] = KEYMAP_STACKED
(___, Key_BacklightDown, Key_BacklightUp, LALT(Key_F1), LALT(Key_F2), ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, LALT(Key_Keypad4), LALT(Key_Keypad2), LALT(Key_Keypad8), LALT(Key_Keypad6),
___, ___, ___, ___, ___, ___, LALT(Key_KeypadMultiply),
___, LALT(Key_Backtick), LSHIFT(LALT(Key_Backtick)), ___,
___,
___, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Consumer_Eject, ___,
___, ___, ___, ___, ___, ___, LSHIFT(LALT(Key_KeypadDivide)),
LALT(Key_LeftArrow), LALT(Key_DownArrow), LALT(Key_UpArrow), LALT(Key_RightArrow), ___, LSHIFT(LALT(Key_KeypadEnter)),
LALT(Key_Pause), ___, ___, ___, ___, LALT(Key_M), LSHIFT(LALT(Key_KeypadDot)),
___, ___, ___, ___,
___)
)
class DakkarColor: public kaleidoscope::plugin::LEDMode {
private:
static constexpr cRGB color_off = CRGB(0,0,0);
static constexpr cRGB color_window = CRGB(255,0,0);
static constexpr cRGB color_viewport = CRGB(0,255,0);
static constexpr cRGB color_lauch = CRGB(0,0,255);
static constexpr cRGB color_mouse = CRGB(0,0,255);
static constexpr cRGB color_mouse_button = CRGB(0,128,128);
static constexpr cRGB color_mouse_warp = CRGB(64,128,128);
static constexpr cRGB color_function = CRGB(64,128,64);
cRGB color_layer;
public:
DakkarColor(cRGB layer) : color_layer(layer) { }
protected:
void update(void) final {
for (uint8_t r = 0; r < ROWS; r++) {
for (uint8_t c = 0; c < COLS; c++) {
this->refreshAt(r, c);
}
}
}
void refreshAt(byte r, byte c) final {
Key k = Layer.lookupOnActiveLayer(r, c);
uint8_t current_layer = Layer.top();
Key layer_key = Layer.getKey(current_layer, r, c);
bool is_on_layer = (k == layer_key && k != Key_NoKey);
cRGB color = color_off;
if (current_layer == FVWM) {
if (is_on_layer) {
color = color_window;
}
switch (k.keyCode) {
case Key_F1.keyCode ... Key_F12.keyCode: case Key_Backtick.keyCode:
color = color_lauch; break;
case Key_LeftArrow.keyCode: case Key_RightArrow.keyCode: case Key_UpArrow.keyCode: case Key_DownArrow.keyCode:
color = color_viewport; break;
}
if (k.flags & SHIFT_HELD) {
color.r >>= 1; color.g >>= 1; color.b >>= 1;
}
}
else if (current_layer == FUNCTION) {
if (k.flags & IS_MOUSE_KEY) {
switch (k.keyCode) {
case Key_mouseUp.keyCode: case Key_mouseDn.keyCode: case Key_mouseL.keyCode: case Key_mouseR.keyCode:
color = color_mouse; break;
}
if (k.keyCode & KEY_MOUSE_WARP) { color = color_mouse_warp; }
else if (k.keyCode & KEY_MOUSE_BUTTON) { color = color_mouse_button; }
}
else if (is_on_layer) {
color = color_function;
}
}
else {
if (k == layer_key && k != Key_NoKey) {
color = color_layer;
}
}
LEDControl.setCrgbAt(r, c, color);
}
};
static DakkarColor DakkarColorDark(CRGB(0,0,0));
static DakkarColor DakkarColorBright(CRGB(0,0,150));
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);
}
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;
}
return MACRO_NONE;
}
void toggleLedsOnSuspendResume(kaleidoscope::plugin::HostPowerManagement::Event event) {
switch (event) {
case kaleidoscope::plugin::HostPowerManagement::Suspend:
LEDControl.set_all_leds_to({0, 0, 0});
LEDControl.syncLeds();
LEDControl.paused = true;
break;
case kaleidoscope::plugin::HostPowerManagement::Resume:
LEDControl.paused = false;
LEDControl.refreshAll();
break;
case kaleidoscope::plugin::HostPowerManagement::Sleep:
break;
}
}
void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) {
toggleLedsOnSuspendResume(event);
}
enum {
COMBO_TOGGLE_NKRO_MODE
};
static void toggleKeyboardProtocol(uint8_t combo_index) {
USBQuirks.toggleKeyboardProtocol();
}
USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol,
.keys = { R3C6, R2C6, R3C7 }
});
KALEIDOSCOPE_INIT_PLUGINS(
EEPROMSettings,
EEPROMKeymap,
Focus,
FocusSettingsCommand,
FocusEEPROMCommand,
BootGreetingEffect,
TestMode,
LEDControl,
DakkarColorDark, DakkarColorBright,
NumPad,
Macros,
MouseKeys,
HostPowerManagement,
MagicCombo,
USBQuirks
);
void setup() {
Kaleidoscope.setup();
NumPad.numPadLayer = NUMPAD;
DakkarColorDark.activate();
EEPROMKeymap.setup(5);
}
void loop() {
Kaleidoscope.loop();
}