QMK/keymaps/default/keymap.c

320 lines
6.0 KiB
C

#include "keymap.h"
#include "layers.h"
enum custom_keycodes {
RGB_SLD = EZ_SAFE_RANGE,
HSV_136_138_245,
HSV_24_210_255,
HSV_0_0_255,
ST_MACRO_0,
ST_MACRO_1,
RU_LAYER,
EN_LAYER,
RU_SYMBOL,
};
enum tap_dance_codes {
DANCE_0,
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYER_MAIN,
[1] = LAYER_COLEMAK,
[2] = LAYER_NUMBERS,
[3] = LAYER_SYMBOLS,
[4] = LAYER_ARROWS,
[5] = LAYER_FKEYS,
[6] = LAYER_NAVIGATE,
[7] = LAYER_DESKTOP,
[8] = LAYER_KEYBOARD,
[9] = LAYER_RUSSIAN,
[10] = LAYER_RUSSIAN_SYMBOLS,
};
const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = {
[1] = LAYER_COLEMAK_LEDS,
[2] = LAYER_NUMBERS_LEDS,
[3] = LAYER_SYMBOLS_LEDS,
[4] = LAYER_ARROWS_LEDS,
[5] = LAYER_FKEYS_LEDS,
[6] = LAYER_NAVIGATE_LEDS,
[7] = LAYER_DESKTOP_LEDS,
[9] = LAYER_RUSSIAN_LEDS,
[10] = LAYER_RUSSIAN_SYMBOLS_LEDS
};
extern bool g_suspend_state;
extern rgb_config_t rgb_matrix_config;
void keyboard_post_init_user(void) {
rgb_matrix_enable();
}
void set_layer_color(int layer) {
for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
HSV hsv = {
.h = pgm_read_byte(&ledmap[layer][i][0]),
.s = pgm_read_byte(&ledmap[layer][i][1]),
.v = pgm_read_byte(&ledmap[layer][i][2]),
};
if (!hsv.h && !hsv.s && !hsv.v) {
rgb_matrix_set_color( i, 0, 0, 0 );
} else {
RGB rgb = hsv_to_rgb( hsv );
float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
rgb_matrix_set_color( i, f * rgb.r, f * rgb.g, f * rgb.b );
}
}
}
void rgb_matrix_indicators_user(void) {
if (g_suspend_state || keyboard_config.disable_layer_led) {
return;
}
switch (biton32(layer_state)) {
case 1:
set_layer_color(1);
break;
case 2:
set_layer_color(2);
break;
case 3:
set_layer_color(3);
break;
case 4:
set_layer_color(4);
break;
case 5:
set_layer_color(5);
break;
case 6:
set_layer_color(6);
break;
case 7:
set_layer_color(7);
break;
case 9:
set_layer_color(9);
break;
case 10:
set_layer_color(10);
break;
default:
if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
rgb_matrix_set_color_all(0, 0, 0);
}
break;
}
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case ST_MACRO_0:
if (record->event.pressed) {
SEND_STRING(SS_LCTL(SS_LGUI(SS_LSFT(SS_TAP(X_R)))));
}
break;
case ST_MACRO_1:
if (record->event.pressed) {
SEND_STRING(SS_LGUI(SS_TAP(X_P)) SS_DELAY(100) SS_TAP(X_Y) SS_DELAY(100) SS_TAP(X_ENTER));
}
break;
case RU_LAYER:
if (record->event.pressed) {
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_9)))));
layer_move(9);
}
break;
case EN_LAYER:
if (record->event.pressed) {
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_0)))));
layer_move(0);
}
break;
case RU_SYMBOL:
if (record->event.pressed) {
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_0)))));
layer_move(10);
} else {
SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_9)))));
layer_move(9);
}
break;
case RGB_SLD:
if (record->event.pressed) {
rgblight_mode(1);
}
return false;
case HSV_136_138_245:
if (record->event.pressed) {
rgblight_mode(1);
rgblight_sethsv(136,138,245);
}
return false;
case HSV_24_210_255:
if (record->event.pressed) {
rgblight_mode(1);
rgblight_sethsv(24,210,255);
}
return false;
case HSV_0_0_255:
if (record->event.pressed) {
rgblight_mode(1);
rgblight_sethsv(0,0,255);
}
return false;
}
return true;
}
uint32_t layer_state_set_user(uint32_t state) {
uint8_t layer = biton32(state);
ergodox_board_led_off();
ergodox_right_led_1_off();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
switch (layer) {
case 1:
ergodox_right_led_1_on();
break;
case 2:
ergodox_right_led_2_on();
break;
case 3:
ergodox_right_led_3_on();
break;
case 4:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
break;
case 5:
ergodox_right_led_1_on();
ergodox_right_led_3_on();
break;
case 6:
ergodox_right_led_2_on();
ergodox_right_led_3_on();
break;
case 7:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
ergodox_right_led_3_on();
break;
default:
break;
}
return state;
};
typedef struct {
bool is_press_action;
uint8_t step;
} tap;
enum {
SINGLE_TAP = 1,
SINGLE_HOLD,
DOUBLE_TAP,
DOUBLE_HOLD,
DOUBLE_SINGLE_TAP,
MORE_TAPS
};
static tap dance_state[1];
uint8_t dance_step(qk_tap_dance_state_t *state);
uint8_t dance_step(qk_tap_dance_state_t *state) {
if (state->count == 1) {
if (state->interrupted || !state->pressed) {
return SINGLE_TAP;
} else {
return SINGLE_HOLD;
}
} else if (state->count == 2) {
if (state->interrupted) {
return DOUBLE_SINGLE_TAP;
} else if (state->pressed) {
return DOUBLE_HOLD;
} else {
return DOUBLE_TAP;
}
}
return MORE_TAPS;
}
void on_dance_0(qk_tap_dance_state_t *state, void *user_data);
void dance_0_finished(qk_tap_dance_state_t *state, void *user_data);
void dance_0_reset(qk_tap_dance_state_t *state, void *user_data);
void on_dance_0(qk_tap_dance_state_t *state, void *user_data) {
if(state->count == 3) {
tap_code16(LGUI(KC_L));
tap_code16(LGUI(KC_L));
tap_code16(LGUI(KC_L));
}
if(state->count > 3) {
tap_code16(LGUI(KC_L));
}
}
void dance_0_finished(qk_tap_dance_state_t *state, void *user_data) {
dance_state[0].step = dance_step(state);
switch (dance_state[0].step) {
case SINGLE_TAP:
register_code16(LGUI(KC_L));
break;
case DOUBLE_TAP:
register_code16(LGUI(KC_K));
break;
case DOUBLE_SINGLE_TAP:
tap_code16(LGUI(KC_L));
register_code16(LGUI(KC_L));
break;
}
}
void dance_0_reset(qk_tap_dance_state_t *state, void *user_data) {
wait_ms(10);
switch (dance_state[0].step) {
case SINGLE_TAP:
unregister_code16(LGUI(KC_L));
break;
case DOUBLE_TAP:
unregister_code16(LGUI(KC_K));
break;
case DOUBLE_SINGLE_TAP:
unregister_code16(LGUI(KC_L));
break;
}
dance_state[0].step = 0;
}
qk_tap_dance_action_t tap_dance_actions[] = {
[DANCE_0] = ACTION_TAP_DANCE_FN_ADVANCED(on_dance_0, dance_0_finished, dance_0_reset),
};