#include QMK_KEYBOARD_H
enum layers {
_NUMPAD,
_RGB,
_MACRO
};
enum custom_keycodes {
HELLO_WORLD = SAFE_RANGE,
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_NUMPAD] = LAYOUT(
KC_7, KC_8, KC_9, TO(_NUMPAD),
KC_4, KC_5, KC_6, TO(_RGB),
KC_1, KC_2, KC_3, TO(_MACRO),
KC_0, KC_DOT, KC_ENTER
),
[_RGB] = LAYOUT(
RGB_HUI, RGB_SAI, RGB_VAI, KC_TRNS,
RGB_HUD, RGB_SAD, RGB_VAD, KC_TRNS,
KC_NO, KC_NO, KC_NO, KC_TRNS,
RGB_RMOD, RGB_TOG, RGB_MOD
),
[_MACRO] = LAYOUT(
HELLO_WORLD, KC_NO, KC_NO, KC_TRNS,
KC_NO, KC_NO, KC_NO, KC_TRNS,
KC_NO, KC_NO, KC_NO, KC_TRNS,
KC_NO, KC_NO, KC_NO
)
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case HELLO_WORLD:
if (record->event.pressed) {
SEND_STRING("Hello, world!");
}
break;
}
return true;
};
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
switch (get_highest_layer(layer_state)) { case _NUMPAD:
if (clockwise) {
tap_code(KC_DOWN);
} else {
tap_code(KC_UP);
}
break;
case _RGB:
if (clockwise) {
rgblight_increase_hue();
} else {
rgblight_decrease_hue();
}
break;
case _MACRO:
if (clockwise) {
break;
} else {
break;
}
break;
}
} else if (index == 1) {
switch (get_highest_layer(layer_state)) {
case _NUMPAD:
if (clockwise) {
tap_code(KC_PGDN);
} else {
tap_code(KC_PGUP);
}
break;
case _RGB:
if (clockwise) {
rgblight_increase_sat();
} else {
rgblight_decrease_sat();
}
break;
case _MACRO:
if (clockwise) {
break;
} else {
break;
}
break;
}
} else if (index == 2) {
switch (get_highest_layer(layer_state)) {
case _NUMPAD:
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
break;
case _RGB:
if (clockwise) {
rgblight_increase_val();
} else {
rgblight_decrease_val();
}
break;
case _MACRO:
if (clockwise) {
break;
} else {
break;
}
break;
}
}
return true;
}
layer_state_t layer_state_set_user(layer_state_t state) { switch (get_highest_layer(state)) {
case _NUMPAD:
setrgb(RGB_WHITE, &led[0]); setrgb(0, 0, 0, &led[1]);
setrgb(0, 0, 0, &led[2]);
break;
case _RGB:
setrgb(0, 0, 0, &led[0]); setrgb(RGB_WHITE, &led[1]);
setrgb(0, 0, 0, &led[2]);
break;
case _MACRO:
setrgb(0, 0, 0, &led[0]);
setrgb(0, 0, 0, &led[1]);
setrgb(RGB_WHITE, &led[2]); break;
}
rgblight_set();
return state;
}
#ifdef OLED_DRIVER_ENABLE
static const char *ANIMATION_NAMES[] = {
"unknown",
"static",
"breathing I",
"breathing II",
"breathing III",
"breathing IV",
"rainbow mood I",
"rainbow mood II",
"rainbow mood III",
"rainbow swirl I",
"rainbow swirl II",
"rainbow swirl III",
"rainbow swirl IV",
"rainbow swirl V",
"rainbow swirl VI",
"snake I",
"snake II",
"snake III",
"snake IV",
"snake V",
"snake VI",
"knight I",
"knight II",
"knight III",
"christmas",
"static gradient I",
"static gradient II",
"static gradient III",
"static gradient IV",
"static gradient V",
"static gradient VI",
"static gradient VII",
"static gradient VIII",
"static gradient IX",
"static gradient X",
"rgb test",
"alternating",
"twinkle I",
"twinkle II",
"twinkle III",
"twinkle IV",
"twinkle V",
"twinkle VI"
};
void rgblight_get_mode_name(uint8_t mode, size_t bufsize, char *buf) {
snprintf(buf, bufsize, "%-25s", ANIMATION_NAMES[mode]);
}
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
#ifdef LEFT_HAND
return OLED_ROTATION_180;
#else
return OLED_ROTATION_0;
#endif
}
void oled_task_user(void) {
oled_write_P(PSTR("Layer: "), false);
switch (get_highest_layer(layer_state)) {
case _NUMPAD:
oled_write_P(PSTR("Numpad\n"), false);
break;
case _RGB:
oled_write_P(PSTR("RGB\n"), false);
break;
case _MACRO:
oled_write_P(PSTR("Macro\n"), false);
break;
default:
oled_write_ln_P(PSTR("Undefined"), false);
}
static char rgb_mode_name[30];
rgblight_get_mode_name(rgblight_get_mode(), sizeof(rgb_mode_name), rgb_mode_name);
oled_write_P(PSTR("Mode: "), false);
oled_write_ln(rgb_mode_name, false);
}
#endif