#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
class DakkarColor: public kaleidoscope::plugin::LEDMode {
public:
class color {
public:
enum {
OFF,
BASE,
LAUNCH, WINDOW, VIEWPORT,
MOUSE, MOUSE_BUTTON, MOUSE_WARP,
FUNCTION,
};
};
DakkarColor(const cRGB _colors[], const uint8_t _map[][ROWS][COLS]) : colors(_colors), map(_map) { }
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);
const cRGB *colors;
const uint8_t (*map)[ROWS][COLS];
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 {
LEDControl.setCrgbAt(r, c, colors[map[Layer.top()][r][c]]);
}
};
#include "keymap-wrapper.h"
static constexpr cRGB dark_colors[] =
{
[DakkarColor::color::OFF] = CRGB(0,0,0),
[DakkarColor::color::BASE] = CRGB(0,0,0),
[DakkarColor::color::LAUNCH] = CRGB(0,0,150),
[DakkarColor::color::WINDOW] = CRGB(150,0,0),
[DakkarColor::color::VIEWPORT] = CRGB(0,150,0),
[DakkarColor::color::MOUSE] = CRGB(100,100,0),
[DakkarColor::color::MOUSE_BUTTON] = CRGB(50,0,50),
[DakkarColor::color::MOUSE_WARP] = CRGB(0,50,50),
[DakkarColor::color::FUNCTION] = CRGB(100,100,100),
};
static constexpr cRGB bright_colors[] =
{
[DakkarColor::color::OFF] = CRGB(0,0,0),
[DakkarColor::color::BASE] = CRGB(50,50,50),
[DakkarColor::color::LAUNCH] = CRGB(0,0,100),
[DakkarColor::color::WINDOW] = CRGB(100,0,0),
[DakkarColor::color::VIEWPORT] = CRGB(0,100,0),
[DakkarColor::color::MOUSE] = CRGB(50,50,0),
[DakkarColor::color::MOUSE_BUTTON] = CRGB(30,0,30),
[DakkarColor::color::MOUSE_WARP] = CRGB(0,30,30),
[DakkarColor::color::FUNCTION] = CRGB(50,50,80),
};
static DakkarColor DakkarColorDark(dark_colors,color_keymaps);
static DakkarColor DakkarColorBright(bright_colors,color_keymaps);
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();
}