keymap.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* Copyright 2021 Kyle McCreery
  2. * Copyright 2021 Jonavin Eng
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include QMK_KEYBOARD_H
  18. #include <stdio.h>
  19. enum custom_layers {
  20. _BASE,
  21. _FN1,
  22. _LOWER,
  23. _RAISE,
  24. };
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [_BASE] = LAYOUT_all(
  27. KC_MUTE,
  28. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  29. TT(_RAISE), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  30. KC_LSFT, KC_SLSH, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SFTENT,
  31. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, LT(_LOWER,KC_SPC), KC_SPC, KC_RALT, MO(_FN1), KC_RCTL ),
  32. [_FN1] = LAYOUT_all(
  33. KC_TRNS,
  34. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,
  35. KC_CAPS, KC_F11, KC_F12, KC_NO, KC_NO, KC_NO, KC_NO, KC_PSCR, KC_SCLN, KC_PAUS, KC_NO, KC_NO,
  36. KC_TRNS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NLCK, KC_P0, KC_NO, KC_NO, KC_SFTENT,
  37. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ),
  38. [_LOWER] = LAYOUT_all(
  39. KC_TRNS,
  40. KC_GRAVE, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  41. KC_TRNS, KC_MINS, KC_EQL, KC_NO, KC_NO, KC_NO, KC_NO, KC_QUES, KC_SLSH, KC_PIPE, KC_BSLS, KC_TILD,
  42. KC_TRNS, KC_TRNS, KC_UNDS, KC_PLUS, KC_NO, KC_NO, KC_NO, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_TRNS,
  43. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ),
  44. [_RAISE] = LAYOUT_all(
  45. KC_TRNS,
  46. KC_TAB, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_PMNS, KC_PPLS, KC_P7, KC_P8, KC_P9, KC_P0, KC_TRNS,
  47. TT(_RAISE), KC_LEFT, KC_DOWN, KC_RIGHT,KC_PGDN, KC_PSLS, KC_TAB, KC_P4, KC_P5, KC_P6, KC_PDOT, KC_PEQL,
  48. KC_TRNS, KC_TRNS, KC_NO, KC_DEL, KC_INS, KC_NO, KC_PAST, KC_P0, KC_P1, KC_P2, KC_P3, KC_PENT,
  49. KC_TRNS, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS )
  50. };
  51. #ifdef ENCODER_ENABLE // Encoder Functionality
  52. uint8_t selected_layer = 0;
  53. bool encoder_update_user(uint8_t index, bool clockwise) {
  54. #ifdef OLED_DRIVER_ENABLE
  55. oled_clear();
  56. oled_render();
  57. #endif
  58. switch (index) {
  59. case 0: // This is the only encoder right now, keeping for consistency
  60. if ( clockwise ) {
  61. if ( selected_layer < 3 && keyboard_report->mods & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers
  62. selected_layer ++;
  63. layer_move(selected_layer);
  64. } else {
  65. tap_code(KC_VOLU); // Otherwise it just changes volume
  66. }
  67. } else if ( !clockwise ) {
  68. if ( selected_layer > 0 && keyboard_report->mods & MOD_BIT(KC_LSFT) ){
  69. selected_layer --;
  70. layer_move(selected_layer);
  71. } else {
  72. tap_code(KC_VOLD);
  73. }
  74. }
  75. }
  76. return true;
  77. }
  78. #endif
  79. #ifdef OLED_DRIVER_ENABLE // OLED Functionality
  80. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  81. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  82. }
  83. bool clear_screen = false; // used to manage singular screen clears to prevent display glitch
  84. static void render_name(void) { // Render Mercutio Script Text
  85. static const char PROGMEM mercutio_name[] = {
  86. 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0x95, 0xB5, 0x96, 0xD5, 0xB6, 0xB6,
  87. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94,
  88. 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4,
  89. 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00
  90. };
  91. oled_write_P(mercutio_name, false);
  92. }
  93. static void render_logo(void) { // Render MechWild "MW" Logo
  94. static const char PROGMEM logo_1[] = {0x97, 0x98, 0x99, 0x9A,0x00};
  95. static const char PROGMEM logo_2[] = {0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0x00};
  96. static const char PROGMEM logo_3[] = {0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xB6, 0x00};
  97. static const char PROGMEM logo_4[] = {0xB6, 0xB6, 0xB6, 0x9B, 0x9C, 0x9D, 0x9E, 0x00};
  98. oled_set_cursor(0,0);
  99. oled_write_P(logo_1, false);
  100. oled_set_cursor(0,1);
  101. oled_write_P(logo_2, false);
  102. oled_set_cursor(0,2);
  103. oled_write_P(logo_3, false);
  104. oled_set_cursor(0,3);
  105. oled_write_P(logo_4, false);
  106. }
  107. void oled_task_user(void) {
  108. if ( IS_HOST_LED_OFF(USB_LED_NUM_LOCK) && IS_HOST_LED_OFF(USB_LED_CAPS_LOCK) && selected_layer == 0 && get_highest_layer(layer_state) == 0 ) {
  109. render_name();
  110. clear_screen = true;
  111. } else {
  112. if (clear_screen == true) {
  113. oled_clear();
  114. oled_render();
  115. clear_screen = false;
  116. }
  117. render_logo();
  118. oled_set_cursor(8,2);
  119. switch(selected_layer){
  120. case 0:
  121. oled_write_P(PSTR("BASE"), false);
  122. break;
  123. case 1:
  124. oled_write_P(PSTR("FN"), false);
  125. break;
  126. case 2:
  127. oled_write_P(PSTR("LOWER"), false);
  128. break;
  129. case 3:
  130. oled_write_P(PSTR("RAISE"), false);
  131. break;
  132. default:
  133. oled_write_P(PSTR("Layer ?"), false); // Should never display, here as a catchall
  134. }
  135. oled_set_cursor(8,3);
  136. if (get_highest_layer(layer_state) == selected_layer) {
  137. oled_write_P(PSTR(" "), false);
  138. } else {
  139. switch (get_highest_layer(layer_state)) {
  140. case 0:
  141. oled_write_P(PSTR("Temp BASE"), false);
  142. break;
  143. case 1:
  144. oled_write_P(PSTR("Temp FN"), false);
  145. break;
  146. case 2:
  147. oled_write_P(PSTR("Temp LOWER"), false);
  148. break;
  149. case 3:
  150. oled_write_P(PSTR("Temp RAISE"), false);
  151. break;
  152. default:
  153. oled_write_P(PSTR("Temp Layer ?"), false); // Should never display, here as a catchall
  154. }
  155. }
  156. led_t led_state = host_keyboard_led_state();
  157. oled_set_cursor(8,0);
  158. uint8_t wpm_count;
  159. char wpm_str[10];
  160. wpm_count=get_current_wpm();
  161. if (wpm_count > 020) { // how wpm when > 20
  162. sprintf(wpm_str, " WPM: %03d", wpm_count);
  163. oled_write(wpm_str, false);
  164. } else {
  165. oled_write_P(PSTR(" JONAVIN "), false); // otherwise display keymap name
  166. }
  167. oled_set_cursor(8,1);
  168. oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
  169. oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false);
  170. oled_write_P(led_state.scroll_lock ? PSTR("SCR") : PSTR(" "), false);
  171. }
  172. }
  173. void suspend_power_down_user(void) { // shutdown oled when powered down to prevent OLED from showing Mercutio all the time
  174. oled_off();
  175. }
  176. #endif