#include "keymap.h" // -1 => skip int8_t col_to_array[10][5] = { { 47, 43, 38, 33, 28 }, { 46, 42, 37, 32, 27 }, { 45, 41, 36, 31, 26 }, { 44, 40, 35, 30, 25 }, { -1, 39, 34, 29, 24 }, { -1, 15, 10, 5, 0 }, { 20, 16, 11, 6, 1 }, { 21, 17, 12, 7, 2 }, { 22, 18, 13, 8, 3 }, { 23, 19, 14, 9, 4 } }; void cmd_animation(uint8_t *data, uint8_t length) { uint8_t subcmd = data[1]; switch (subcmd) { case 0x02: // Data input (fft) for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { // Turn off all LEDs rgb_matrix_set_color( i, 0x00, 0x00, 0x00 ); } for (uint8_t bin = 0; bin < 10; bin++) { uint8_t d = data[bin + 2]; uint8_t bin_height = d / 20; uint8_t last_brightness = ((d % 20)/20.0) * 0xFF; if (bin_height == 0) { continue; } for (uint8_t i = 0; i < bin_height; i++) { if (col_to_array[bin][i] < 0) { continue; } if (i == bin_height - 1) { rgb_matrix_set_color( col_to_array[bin][i], last_brightness, 0x00, last_brightness ); } else { rgb_matrix_set_color( col_to_array[bin][i], 0x00, 0x00, 0xFF ); } } } break; } } void raw_hid_receive(uint8_t *data, uint8_t length) { uint8_t cmd = data[0]; switch (cmd) { case 0x01: // animation cmd_animation(data, length); break; default: break; } /* raw_hid_send(data, length); ergodox_right_led_1_on(); _delay_ms(10); ergodox_right_led_1_off(); i2c_start(0x14, ERGODOX_EZ_I2C_TIMEOUT); i2c_write(0, ERGODOX_EZ_I2C_TIMEOUT); i2c_stop(); */ } // Define custom keys // (Must be done BEFORE keymaps) enum custom_keycodes { M_SHUTDOWN = BETA_SAFE_RANGE, M_RESETWM, RU_LAYER, EN_LAYER, M_RU_CTRL, M_RU_ALT }; enum tap_dance_codes { TD_WMLAYOUT, }; // Assemble key and LED maps enum layer_indices { LAYER_MAIN_IDX = 0, LAYER_RUSSIAN_IDX, LAYER_COLEMAK_IDX, LAYER_NUMPAD_IDX, LAYER_SYMBOLS_IDX, LAYER_ARROWS_IDX, LAYER_FKEYS_IDX, LAYER_NAVIGATE_IDX, LAYER_DESKTOP_IDX, LAYER_KEYBOARD_IDX, }; // Used to set system keymap enum key_encodings { LANG_NULL, // For layers that don't care about input lang LANG_EN, LANG_RU }; enum led_indices { // We have seperate indexes for LEDs because // some layers may not need an led map. // This saves memory by avoiding extra empty led maps. LAYER_COLEMAK_LEDS_IDX = 0, LAYER_RUSSIAN_LEDS_IDX, LAYER_NUMPAD_LEDS_IDX, LAYER_SYMBOLS_LEDS_IDX, LAYER_ARROWS_LEDS_IDX, LAYER_FKEYS_LEDS_IDX, LAYER_NAVIGATE_LEDS_IDX, LAYER_DESKTOP_LEDS_IDX }; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [LAYER_MAIN_IDX] = LAYER_MAIN, [LAYER_RUSSIAN_IDX] = LAYER_RUSSIAN, [LAYER_COLEMAK_IDX] = LAYER_COLEMAK, [LAYER_NUMPAD_IDX] = LAYER_NUMPAD, [LAYER_SYMBOLS_IDX] = LAYER_SYMBOLS, [LAYER_ARROWS_IDX] = LAYER_ARROWS, [LAYER_FKEYS_IDX] = LAYER_FKEYS, [LAYER_NAVIGATE_IDX] = LAYER_NAVIGATE, [LAYER_DESKTOP_IDX] = LAYER_DESKTOP, [LAYER_KEYBOARD_IDX] = LAYER_KEYBOARD }; const uint8_t PROGMEM ledmap[][DRIVER_LED_TOTAL][3] = { [LAYER_COLEMAK_LEDS_IDX] = LAYER_COLEMAK_LEDS, [LAYER_RUSSIAN_LEDS_IDX] = LAYER_RUSSIAN_LEDS, [LAYER_NUMPAD_LEDS_IDX] = LAYER_NUMPAD_LEDS, [LAYER_SYMBOLS_LEDS_IDX] = LAYER_SYMBOLS_LEDS, [LAYER_ARROWS_LEDS_IDX] = LAYER_ARROWS_LEDS, [LAYER_FKEYS_LEDS_IDX] = LAYER_FKEYS_LEDS, [LAYER_NAVIGATE_LEDS_IDX] = LAYER_NAVIGATE_LEDS, [LAYER_DESKTOP_LEDS_IDX] = LAYER_DESKTOP_LEDS }; int current_lang = LANG_EN; void keyboard_post_init_user(void) { //set_lang(LANG_EN); } 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 LAYER_COLEMAK_IDX: set_layer_color(LAYER_COLEMAK_LEDS_IDX); break; case LAYER_RUSSIAN_IDX: set_layer_color(LAYER_RUSSIAN_LEDS_IDX); break; case LAYER_NUMPAD_IDX: set_layer_color(LAYER_NUMPAD_LEDS_IDX); break; case LAYER_SYMBOLS_IDX: set_layer_color(LAYER_SYMBOLS_LEDS_IDX); break; case LAYER_ARROWS_IDX: set_layer_color(LAYER_ARROWS_LEDS_IDX); break; case LAYER_FKEYS_IDX: set_layer_color(LAYER_FKEYS_LEDS_IDX); break; case LAYER_NAVIGATE_IDX: set_layer_color(LAYER_NAVIGATE_LEDS_IDX); break; case LAYER_DESKTOP_IDX: set_layer_color(LAYER_DESKTOP_LEDS_IDX); break; default: if (rgb_matrix_get_flags() == LED_FLAG_NONE) { rgb_matrix_set_color_all(0, 0, 0); } break; } } void set_lang(int lang) { set_lang_long(lang, false); } void set_lang_long(int lang, bool force) { if (current_lang != lang || force) { switch (lang) { case LANG_EN: SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_0))))); current_lang = lang; break; case LANG_RU: SEND_STRING(SS_LGUI(SS_LSFT(SS_LCTL(SS_TAP(X_9))))); current_lang = lang; break; case LANG_NULL: break; default: break; } } } bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case M_RESETWM: if (record->event.pressed) { SEND_STRING(SS_LCTL(SS_LGUI(SS_LSFT(SS_TAP(X_R))))); } break; case M_SHUTDOWN: 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) { set_lang(LANG_RU); layer_move(LAYER_RUSSIAN_IDX); } break; case EN_LAYER: if (record->event.pressed) { set_lang(LANG_EN); layer_move(LAYER_MAIN_IDX); } break; case M_RU_CTRL: if (record->event.pressed) { if (current_lang == LANG_RU) { set_lang_long(LANG_EN, true); layer_move(LAYER_MAIN_IDX); current_lang = LANG_RU; } register_code16(KC_LCTRL); } else { unregister_code16(KC_LCTRL); if (current_lang == LANG_RU) { layer_move(LAYER_RUSSIAN_IDX); set_lang_long(LANG_RU, true); } } break; } 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 LAYER_MAIN_IDX: set_lang(LANG_EN); break; case LAYER_RUSSIAN_IDX: set_lang(LANG_RU); ergodox_right_led_2_on(); break; case LAYER_COLEMAK_IDX: set_lang(LANG_EN); ergodox_right_led_2_on(); break; case LAYER_NUMPAD_IDX: set_lang(LANG_EN); ergodox_right_led_1_on(); break; case LAYER_SYMBOLS_IDX: set_lang(LANG_EN); break; case LAYER_ARROWS_IDX: set_lang(LANG_EN); break; case LAYER_FKEYS_IDX: set_lang(LANG_EN); break; case LAYER_NAVIGATE_IDX: set_lang(LANG_EN); ergodox_right_led_3_on(); break; case LAYER_DESKTOP_IDX: set_lang(LANG_EN); break; case LAYER_KEYBOARD_IDX: set_lang(LANG_NULL); ergodox_right_led_1_on(); ergodox_right_led_2_on(); ergodox_right_led_3_on(); break; default: break; } return state; }; qk_tap_dance_action_t tap_dance_actions[] = { [TD_WMLAYOUT] = ACTION_TAP_DANCE_FN_ADVANCED(td_wmlayout_dance, td_wmlayout_finished, td_wmlayout_reset), };