logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

wave.h (4978B)


  1. /* Copyright 2021 HorrorTroll <https://github.com/HorrorTroll>
  2. * Copyright 2021 Gopolar
  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. #pragma once
  18. extern const unsigned char font[] PROGMEM;
  19. #define ROW_1 OLED_DISPLAY_WIDTH
  20. #define ROW_2 (OLED_DISPLAY_WIDTH * 2)
  21. static uint32_t wave_sleep = 0;
  22. #define FRAME_TIMEOUT (1000/28)
  23. static uint16_t wave_timer = 0;
  24. static uint8_t next_bar_val = 0;
  25. static uint8_t next_log_byte[OLED_FONT_WIDTH] = {0};
  26. static uint8_t line1[OLED_DISPLAY_WIDTH] = {0};
  27. static uint8_t line2[OLED_DISPLAY_WIDTH] = {0};
  28. static const uint8_t PROGMEM bar_lut[8] = {0, 16, 24, 56, 60, 124, 126, 255};
  29. #define BAR_KEY_WEIGHT 128
  30. #define BAR_KEY_DECAY_MAX 18
  31. static uint8_t bar_key_decay = BAR_KEY_DECAY_MAX;
  32. // clang-format off
  33. static const char PROGMEM code_to_name[0xFF] = {
  34. // 0 1 2 3 4 5 6 7 8 9 A B C D E F
  35. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', // 0x
  36. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', // 1x
  37. '3', '4', '5', '6', '7', '8', '9', '0', 128, 136, 132, 131, 22, '-', '=', '[', // 2x
  38. ']','\\', '#', ';','\'', '`', ',', '.', '/', 130, 7, 7, 7, 7, 7, 7, // 3x
  39. 7, 7, 7, 7, 7, 7, 137, 138, 139, 140, 141, 30, 143, 142, 31, 26, // 4x
  40. 27, 25, 24, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 5x
  41. ' ', ' ', ' ', ' ','\\', 135, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 6x
  42. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7x
  43. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 8x
  44. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 9x
  45. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Ax
  46. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Bx
  47. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Cx
  48. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Dx
  49. 15, 129, 133, 4, 15, 129, 133, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Ex
  50. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' // Fx
  51. };
  52. // clang-format on
  53. void add_keylog(uint16_t keycode) {
  54. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
  55. (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) ||
  56. (keycode >= QK_MODS && keycode <= QK_MODS_MAX)) {
  57. keycode = keycode & 0xFF;
  58. } else if (keycode > 0xFF) {
  59. keycode = 0;
  60. }
  61. if (keycode < ARRAY_SIZE(code_to_name)) {
  62. char log_char = pgm_read_byte(&code_to_name[keycode]);
  63. for (uint8_t j = 0; j < OLED_FONT_WIDTH; j++) {
  64. const uint8_t glyph_line = pgm_read_byte(&font[log_char * OLED_FONT_WIDTH + j]);
  65. next_log_byte[j] = glyph_line;
  66. }
  67. }
  68. }
  69. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  70. if (record->event.pressed) {
  71. wave_sleep = timer_read32();
  72. add_keylog(keycode);
  73. uint8_t t = next_bar_val + BAR_KEY_WEIGHT;
  74. if (t < next_bar_val) {
  75. next_bar_val = 255;
  76. } else {
  77. next_bar_val = t;
  78. }
  79. bar_key_decay = BAR_KEY_DECAY_MAX;
  80. }
  81. return true;
  82. }
  83. void render_frame(void) {
  84. // rotate line 1, and stick in the next byte of the next char,
  85. // then rotate the next char buffer
  86. memmove(line1+1, line1, OLED_DISPLAY_WIDTH - 1);
  87. line1[0] = next_log_byte[OLED_FONT_WIDTH - 1];
  88. memmove(next_log_byte+1, next_log_byte, OLED_FONT_WIDTH - 1);
  89. next_log_byte[0] = 0;
  90. // rotate line 2, sticking in the next display value
  91. uint8_t disp_val = pgm_read_byte(&bar_lut[next_bar_val / 32]);
  92. memmove(line2+1, line2, OLED_DISPLAY_WIDTH - 1);
  93. line2[0] = disp_val;
  94. // draw both bars
  95. for (uint8_t i = 0; i < OLED_DISPLAY_WIDTH; i++) {
  96. oled_write_raw_byte(line1[i], ROW_1 + i);
  97. oled_write_raw_byte(line2[i], ROW_2 + i);
  98. }
  99. // decay the next bar value
  100. if (next_bar_val > bar_key_decay) {
  101. next_bar_val -= bar_key_decay;
  102. } else {
  103. next_bar_val = 0;
  104. }
  105. if (bar_key_decay > 1) {
  106. bar_key_decay -= 1;
  107. }
  108. }