keymap.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include QMK_KEYBOARD_H
  2. #include "rgblight.h"
  3. enum layer_names {
  4. _BL,
  5. _FL
  6. };
  7. /**
  8. * HHKB style.
  9. * Esc on capslock, space-hold is fn.
  10. * Fn layer has hjkl arrows, home on backspace, rgb stuff.
  11. */
  12. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  13. [_BL] = LAYOUT_60_ansi(
  14. 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,
  15. 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,
  16. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
  17. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
  18. _______, KC_LCTL, KC_LALT, LT(_FL,KC_SPC), KC_LGUI, KC_RALT, KC_RCTL, _______
  19. ),
  20. [_FL] = LAYOUT_60_ansi(
  21. RESET, 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_HOME,
  22. RGB_MOD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, BL_DEC, BL_INC, BL_TOGG,
  23. _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, _______, _______, _______,
  24. _______, RGB_TOG, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______,
  25. _______, _______, _______, _______, _______, _______, _______, _______
  26. )
  27. };
  28. /**
  29. * Terminal Prompt
  30. * Mimicks a terminal prompt. On keystrokes, the led bar is filled. Backspace
  31. * removes from bar. Enter clears bar. After some timeout, the bar is also cleared.
  32. * A blinking cursor is displayed at the right of the bar.
  33. * This can't be defined as an animation, because animations only are called on an
  34. * interval, not on keypress. In the future all animations could be enhanced to
  35. * react to keystrokes in QMK.
  36. */
  37. uint8_t cursor_pos;
  38. uint16_t interval_time = 10; // maybe too short...
  39. uint16_t reset_time = 10000;
  40. uint16_t last_timer = 0;
  41. uint16_t timer_pos = 0;
  42. uint16_t reset_timer = 0;
  43. void reset_chars(void);
  44. void add_char(bool space);
  45. void remove_char(void);
  46. void animate_cursor(uint16_t);
  47. // animate, like the built-in animations, with timer_* functions
  48. void matrix_scan_user(void) {
  49. if (timer_elapsed(reset_timer) > reset_time) {
  50. reset_chars();
  51. reset_timer = timer_read();
  52. return;
  53. }
  54. if (timer_elapsed(last_timer) < interval_time) {
  55. return;
  56. }
  57. last_timer += interval_time;
  58. timer_pos += 4;
  59. if (timer_pos >= 255) {
  60. timer_pos = 0;
  61. last_timer = timer_read();
  62. }
  63. animate_cursor(timer_pos);
  64. }
  65. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  66. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  67. keycode = keycode & 0xFF;
  68. }
  69. switch (keycode) {
  70. case KC_A ... KC_Z:
  71. case KC_1 ... KC_0:
  72. case KC_LBRC:
  73. case KC_RBRC:
  74. case KC_SCLN:
  75. case KC_QUOT:
  76. case KC_COMM:
  77. case KC_DOT:
  78. case KC_SLSH:
  79. case KC_BSLS:
  80. if (record->event.pressed) {
  81. add_char(false);
  82. }
  83. break;
  84. case KC_ENTER:
  85. case KC_ESC:
  86. if (record->event.pressed) {
  87. reset_chars();
  88. }
  89. break;
  90. case KC_BSPC:
  91. if (record->event.pressed) {
  92. remove_char();
  93. }
  94. break;
  95. case KC_SPACE:
  96. if (!record->event.pressed) {
  97. add_char(true);
  98. }
  99. break;
  100. }
  101. reset_timer = timer_read();
  102. return true;
  103. }
  104. void keyboard_post_init_user(void) {
  105. // reset the bar and animation
  106. rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
  107. cursor_pos = 0;
  108. reset_chars();
  109. reset_timer = last_timer = timer_read();
  110. }
  111. void reset_chars(void) {
  112. // flush the whole thing, gets rid of previous animations
  113. for (uint8_t i = 0; i < RGBLED_NUM; i++) {
  114. // don't flicker the cursor if bar was empty on reset_timer
  115. if (i == 0 && cursor_pos == 0) {
  116. continue;
  117. }
  118. rgblight_sethsv_at(0, 0, 0, i);
  119. }
  120. cursor_pos = 0;
  121. }
  122. void add_char(bool space) {
  123. if (cursor_pos == RGBLED_NUM - 1) {
  124. cursor_pos = 0;
  125. reset_chars();
  126. return;
  127. }
  128. if (space) {
  129. rgblight_sethsv_at(0, 0, 0, cursor_pos);
  130. } else {
  131. rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), cursor_pos);
  132. }
  133. cursor_pos += 1;
  134. }
  135. void remove_char(void) {
  136. if (cursor_pos == 0) return;
  137. rgblight_sethsv_at(0, 0, 0, cursor_pos);
  138. rgblight_sethsv_at(0, 0, 0, cursor_pos - 1);
  139. cursor_pos -= 1;
  140. }
  141. void animate_cursor(uint16_t pos) {
  142. uint16_t value = pos < 196 ? fmin(255, pos * 16) : (255 - (pos * 2));
  143. rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), value, cursor_pos);
  144. }