keymap.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 "jonavin.h"
  19. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  20. [_BASE] = LAYOUT_all(
  21. KC_MUTE,
  22. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  23. TT(_RAISE), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  24. KC_LSFTCAPS, KC_SLSH, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, SC_SENT,
  25. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, LT(_LOWER,KC_SPC), KC_SPC, KC_RALT, MO(_FN1), KC_RCTL ),
  26. [_FN1] = LAYOUT_all(
  27. ENCFUNC,
  28. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DEL,
  29. KC_CAPS, KC_F11, KC_F12, KC_NO, KC_NO, KC_NO, KC_NO, KC_PSCR, KC_SCRL, KC_PAUS, KC_NO, KC_NO,
  30. KC_TRNS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NUM, KC_NO, KC_NO, KC_NO, SC_SENT,
  31. KC_TRNS, KC_WINLCK, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ),
  32. [_LOWER] = LAYOUT_all(
  33. KC_TRNS,
  34. KC_GRAVE, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  35. KC_TRNS, KC_MINS, KC_EQL, KC_NO, KC_NO, KC_NO, KC_NO, KC_QUES, KC_SLSH, KC_PIPE, KC_BSLS, KC_TILD,
  36. KC_TRNS, KC_TRNS, KC_UNDS, KC_PLUS, KC_NO, KC_NO, KC_NO, KC_LCBR, KC_RCBR, KC_LBRC, KC_RBRC, KC_TRNS,
  37. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ),
  38. [_RAISE] = LAYOUT_all(
  39. KC_TRNS,
  40. KC_TAB, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_PMNS, KC_PPLS, KC_P7, KC_P8, KC_P9, KC_P0, KC_TRNS,
  41. TT(_RAISE), KC_LEFT, KC_DOWN, KC_RIGHT,KC_PGDN, KC_PSLS, KC_TAB, KC_P4, KC_P5, KC_P6, KC_PDOT, KC_PEQL,
  42. KC_TRNS, KC_TRNS, KC_NO, KC_DEL, KC_INS, KC_NO, KC_PAST, KC_P0, KC_P1, KC_P2, KC_P3, KC_PENT,
  43. KC_TRNS, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS )
  44. };
  45. /* These are needed whether encoder function is enabled or not when ENCFUNC keycode is pressed.?
  46. Defaults never changes if no encoder present to change it
  47. */
  48. typedef struct {
  49. char keydesc[6]; // this will be displayed on OLED
  50. uint16_t keycode; // this is the keycode that will be sent when activted
  51. } keycodedescType;
  52. static const keycodedescType PROGMEM keyselection[] = {
  53. // list of key codes that will be scrollled through by encoder and description
  54. {"TASK", KC_TASK},
  55. {"INS", KC_INS},
  56. {"DEL", KC_DEL},
  57. {"PrtSc", KC_PSCR},
  58. {"ScrLk", KC_SCLN},
  59. {"Break", KC_PAUS},
  60. {"C-A-D", KC_CAD}, // Ctrl-Alt-Del
  61. {"AltF4", KC_AF4},
  62. {"PLAY", KC_MEDIA_PLAY_PAUSE},
  63. {"FLASH", QK_BOOT}, // firmware flash mode
  64. };
  65. #define MAX_KEYSELECTION ARRAY_SIZE(keyselection)
  66. static uint8_t selectedkey_idx = 0;
  67. static keycodedescType selectedkey_rec;
  68. static void set_selectedkey(uint8_t idx) {
  69. // make a copy from PROGMEM
  70. memcpy_P (&selectedkey_rec, &keyselection[idx], sizeof selectedkey_rec);
  71. //selectedkey_rec = keyselection[idx];
  72. }
  73. void keyboard_post_init_keymap(void) {
  74. // Call the keyboard post init code.
  75. set_selectedkey(selectedkey_idx);
  76. }
  77. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  78. switch (keycode) {
  79. case ENCFUNC:
  80. if (record->event.pressed) {
  81. selectedkey_rec.keycode == QK_BOOT ? reset_keyboard() : tap_code16(selectedkey_rec.keycode); // handle QK_BOOT code
  82. } else {
  83. // when keycode is released
  84. }
  85. break;
  86. }
  87. return true;
  88. };
  89. #ifdef ENCODER_ENABLE // Encoder Functionality
  90. void encoder_action_selectkey(bool clockwise) {
  91. if ( clockwise ) {
  92. if ( selectedkey_idx < MAX_KEYSELECTION-1) {
  93. selectedkey_idx ++;
  94. } else {
  95. // do nothing
  96. }
  97. } else if ( !clockwise ) {
  98. if ( selectedkey_idx > 0){
  99. selectedkey_idx --;
  100. } else {
  101. // do nothing
  102. }
  103. }
  104. set_selectedkey(selectedkey_idx);
  105. }
  106. bool encoder_update_user(uint8_t index, bool clockwise) {
  107. #ifdef OLED_ENABLE
  108. oled_clear();
  109. oled_render();
  110. #endif
  111. uint8_t mods_state = get_mods();
  112. switch (index) {
  113. case 0: // This is the only encoder right now, keeping for consistency
  114. switch(get_highest_layer(layer_state)){ // special handling per layer
  115. case _FN1: // on Fn layer select what the encoder does when pressed
  116. if (!mods_state) {
  117. encoder_action_selectkey(clockwise);
  118. break;
  119. } else {
  120. // continue to default
  121. }
  122. default: // all other layers
  123. if (mods_state & MOD_BIT(KC_LSFT) ) { // If you are holding L shift, encoder changes layers
  124. encoder_action_layerchange(clockwise);
  125. } else if (mods_state & MOD_BIT(KC_LCTL)) { // if holding Left Ctrl, navigate next/prev word
  126. encoder_action_navword(clockwise);
  127. } else if (mods_state & MOD_BIT(KC_LALT)) { // if holding Left Alt, change media next/prev track
  128. encoder_action_mediatrack(clockwise);
  129. } else {
  130. encoder_action_volume(clockwise); // Otherwise it just changes volume
  131. }
  132. break;
  133. }
  134. break;
  135. }
  136. return false;
  137. }
  138. #endif
  139. #ifdef OLED_ENABLE // OLED Functionality
  140. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  141. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  142. }
  143. bool clear_screen = false; // used to manage singular screen clears to prevent display glitch
  144. static void render_name(void) { // Render Mercutio Script Text
  145. static const char PROGMEM mercutio_name[] = {
  146. 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0xB6, 0x95, 0xB5, 0x96, 0xD5, 0xB6, 0xB6,
  147. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94,
  148. 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4,
  149. 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00
  150. };
  151. oled_write_P(mercutio_name, false);
  152. }
  153. static void render_logo(void) { // Render MechWild "MW" Logo
  154. static const char PROGMEM logo_1[] = {0x97, 0x98, 0x99, 0x9A,0x00};
  155. static const char PROGMEM logo_2[] = {0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0x00};
  156. static const char PROGMEM logo_3[] = {0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xB6, 0x00};
  157. static const char PROGMEM logo_4[] = {0xB6, 0xB6, 0xB6, 0x9B, 0x9C, 0x9D, 0x9E, 0x00};
  158. oled_set_cursor(0,0);
  159. oled_write_P(logo_1, false);
  160. oled_set_cursor(0,1);
  161. oled_write_P(logo_2, false);
  162. oled_set_cursor(0,2);
  163. oled_write_P(logo_3, false);
  164. oled_set_cursor(0,3);
  165. oled_write_P(logo_4, false);
  166. }
  167. bool oled_task_user(void) {
  168. led_t led_state = host_keyboard_led_state();
  169. if ( !led_state.num_lock && !led_state.caps_lock && get_selected_layer() == 0 && get_highest_layer(layer_state) == 0 ) {
  170. render_name();
  171. clear_screen = true;
  172. } else {
  173. if (clear_screen == true) {
  174. oled_clear();
  175. oled_render();
  176. clear_screen = false;
  177. }
  178. render_logo();
  179. oled_set_cursor(8,2);
  180. switch(get_selected_layer()){
  181. case 0:
  182. oled_write_P(PSTR("BASE"), false);
  183. break;
  184. case 1:
  185. oled_write_P(PSTR("FN "), false);
  186. oled_write(selectedkey_rec.keydesc, false);
  187. break;
  188. case 2:
  189. oled_write_P(PSTR("LOWER"), false);
  190. break;
  191. case 3:
  192. oled_write_P(PSTR("RAISE"), false);
  193. break;
  194. default:
  195. oled_write_P(PSTR("Layer ?"), false); // Should never display, here as a catchall
  196. }
  197. oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false);
  198. oled_set_cursor(8,3);
  199. if (get_highest_layer(layer_state) == get_selected_layer()) {
  200. oled_write_P(PSTR(" "), false);
  201. } else {
  202. switch (get_highest_layer(layer_state)) {
  203. case 0:
  204. oled_write_P(PSTR("Temp BASE"), false);
  205. break;
  206. case 1:
  207. oled_write_P(PSTR("Temp FN "), false);
  208. oled_write(selectedkey_rec.keydesc, false);
  209. break;
  210. case 2:
  211. oled_write_P(PSTR("Temp LOWER"), false);
  212. break;
  213. case 3:
  214. oled_write_P(PSTR("Temp RAISE"), false);
  215. break;
  216. default:
  217. oled_write_P(PSTR("Temp Layer ?"), false); // Should never display, here as a catchall
  218. }
  219. }
  220. led_t led_state = host_keyboard_led_state();
  221. oled_set_cursor(8,0);
  222. uint8_t wpm_count;
  223. wpm_count=get_current_wpm();
  224. if (wpm_count > 020) { // how wpm when > 20
  225. oled_write_P(PSTR(" WPM: "), false);
  226. oled_write(get_u8_str(wpm_count, ' '), false);
  227. } else {
  228. oled_write_P(PSTR(" JONAVIN "), false); // otherwise display keymap name
  229. }
  230. oled_set_cursor(8,1);
  231. oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
  232. oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false);
  233. oled_write_P(led_state.scroll_lock ? PSTR("SCR") : PSTR(" "), false);
  234. }
  235. return false;
  236. }
  237. void suspend_power_down_user(void) { // shutdown oled when powered down to prevent OLED from showing Mercutio all the time
  238. oled_off();
  239. }
  240. #endif