keymap.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Copyright 2020 Ramon Imbao
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. #include "pattern.h"
  18. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  19. [0] = LAYOUT_all(
  20. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_VOLD, KC_MUTE, KC_VOLU,
  21. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_BSPC, KC_HOME,
  22. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGUP,
  23. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGDN,
  24. KC_LSFT, KC_NO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_END,
  25. KC_LCTL, KC_LGUI, KC_LALT, KC_NO, KC_SPC, KC_NO, KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  26. ),
  27. [1] = LAYOUT_all(
  28. RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  29. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  30. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  31. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  32. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  33. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  34. ),
  35. [2] = LAYOUT_all(
  36. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  37. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  38. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  39. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  40. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  41. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  42. ),
  43. [3] = LAYOUT_all(
  44. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  45. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  46. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  47. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  48. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  50. ),
  51. };
  52. keyevent_t encoder_ccw = {
  53. .key = (keypos_t){.row = 6, .col = 0},
  54. .pressed = false
  55. };
  56. keyevent_t encoder_cw = {
  57. .key = (keypos_t){.row = 6, .col = 1},
  58. .pressed = false
  59. };
  60. void matrix_scan_user(void) {
  61. if (IS_PRESSED(encoder_ccw)) {
  62. encoder_ccw.pressed = false;
  63. encoder_ccw.time = (timer_read() | 1);
  64. action_exec(encoder_ccw);
  65. }
  66. if (IS_PRESSED(encoder_cw)) {
  67. encoder_cw.pressed = false;
  68. encoder_cw.time = (timer_read() | 1);
  69. action_exec(encoder_cw);
  70. }
  71. }
  72. #ifdef OLED_DRIVER_ENABLE
  73. uint32_t anim_timer = 0;
  74. uint32_t anim_sleep = 0;
  75. uint8_t current_frame = 0;
  76. #define FRAME_DURATION 50
  77. bool encoder_update_user(uint8_t index, bool clockwise) {
  78. if (clockwise) {
  79. encoder_cw.pressed = true;
  80. encoder_cw.time = (timer_read() | 1);
  81. action_exec(encoder_cw);
  82. anim_sleep = timer_read32();
  83. oled_on();
  84. } else {
  85. encoder_ccw.pressed = true;
  86. encoder_ccw.time = (timer_read() | 1);
  87. action_exec(encoder_ccw);
  88. anim_sleep = timer_read32();
  89. oled_on();
  90. }
  91. return true;
  92. }
  93. static void render_pattern(void) {
  94. void animate(void) {
  95. oled_set_cursor(4, 0);
  96. oled_write_raw_P(pattern_a[current_frame], 96);
  97. oled_set_cursor(4, 1);
  98. oled_write_raw_P(pattern_b[current_frame], 96);
  99. oled_set_cursor(4, 2);
  100. oled_write_raw_P(pattern_a[current_frame], 96);
  101. current_frame = (current_frame + 1) % 32;
  102. }
  103. if (get_current_wpm() != 000) {
  104. oled_on();
  105. if (timer_elapsed32(anim_timer) > FRAME_DURATION) {
  106. anim_timer = timer_read32();
  107. animate();
  108. }
  109. anim_sleep = timer_read32();
  110. } else {
  111. if (timer_elapsed32(anim_sleep) > OLED_TIMEOUT) {
  112. oled_off();
  113. } else {
  114. oled_on();
  115. if (timer_elapsed32(anim_timer) > FRAME_DURATION) {
  116. anim_timer = timer_read32();
  117. animate();
  118. }
  119. }
  120. }
  121. }
  122. void oled_task_user(void) {
  123. // Render Herringbone pattern
  124. render_pattern();
  125. oled_render();
  126. // Host Keyboard LED Status
  127. led_t led_state = host_keyboard_led_state();
  128. oled_set_cursor(0, 0);
  129. oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
  130. oled_set_cursor(0, 1);
  131. oled_write_P(led_state.caps_lock ? PSTR("CAP ") : PSTR(" "), false);
  132. oled_set_cursor(0, 2);
  133. oled_write_P(led_state.scroll_lock ? PSTR("SCR ") : PSTR(" "), false);
  134. oled_render();
  135. }
  136. #endif