logo

qmk_firmware

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

wave.c (5018B)


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