You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.4 KiB

  1. /*
  2. * Copyright QMK Community
  3. * Copyright 2021 Tyler Thrailkill (@snowe/@snowe2010) <tyler.b.thrailkill@gmail.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifdef OLED_ENABLE
  19. # include QMK_KEYBOARD_H
  20. # include "quantum.h"
  21. # include "snowe.h"
  22. # include <stdio.h> // for keylog?
  23. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  24. if (!is_keyboard_master()) {
  25. return OLED_ROTATION_270; // flips the display 180 degrees if offhand
  26. }
  27. return OLED_ROTATION_270;
  28. }
  29. # define L_BASE 0
  30. # define L_GAME 2
  31. # define L_LOWER 4
  32. # define L_RAISE 6
  33. # define L_ADJUST 8
  34. void oled_render_layer_state(void) {
  35. oled_write_P(PSTR("Layer"), false);
  36. switch (layer_state) {
  37. case L_BASE:
  38. oled_write_ln_P(PSTR("Main"), false);
  39. break;
  40. case L_GAME:
  41. oled_write_ln_P(PSTR("Game"), false);
  42. break;
  43. case L_LOWER:
  44. oled_write_ln_P(PSTR("Bot"), false);
  45. break;
  46. case L_RAISE:
  47. oled_write_ln_P(PSTR("Top"), false);
  48. break;
  49. // case L_ADJUST:
  50. // case L_ADJUST | L_LOWER:
  51. // case L_ADJUST | L_RAISE:
  52. // case L_ADJUST | L_LOWER | L_RAISE:
  53. // oled_write_ln_P(PSTR("Comb"), false);
  54. // break;
  55. }
  56. }
  57. char keylog_str[24] = {};
  58. const char code_to_name[60] = {
  59. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  60. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  61. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  62. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  63. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  64. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  65. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  66. char name = ' ';
  67. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  68. keycode = keycode & 0xFF;
  69. }
  70. if (keycode < 60) {
  71. name = code_to_name[keycode];
  72. }
  73. // update keylog
  74. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", record->event.key.row, record->event.key.col, keycode, name);
  75. }
  76. void oled_render_keylog(void) { oled_write(keylog_str, false); }
  77. // void render_bootmagic_status(bool status) {
  78. // /* Show Ctrl-Gui Swap options */
  79. // static const char PROGMEM logo[][2][3] = {
  80. // {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  81. // {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  82. // };
  83. // if (status) {
  84. // oled_write_ln_P(logo[0][0], false);
  85. // oled_write_ln_P(logo[0][1], false);
  86. // } else {
  87. // oled_write_ln_P(logo[1][0], false);
  88. // oled_write_ln_P(logo[1][1], false);
  89. // }
  90. //}
  91. void render_bootmagic_status(void) {
  92. /* Show Ctrl-Gui Swap options */
  93. static const char PROGMEM logo[][2][3] = {
  94. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  95. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  96. };
  97. oled_write_P(PSTR("BTMGK"), false);
  98. oled_write_P(PSTR(""), false);
  99. if (!keymap_config.swap_lctl_lgui) {
  100. oled_write_P(logo[1][0], false);
  101. oled_write_P(PSTR(" "), false);
  102. oled_write_P(logo[1][1], false);
  103. } else {
  104. oled_write_P(logo[0][0], false);
  105. oled_write_P(PSTR(" "), false);
  106. oled_write_P(logo[0][1], false);
  107. }
  108. oled_write_P(PSTR(" NKRO "), keymap_config.nkro);
  109. oled_write_P(PSTR("WPM: "), false);
  110. char wpm[6];
  111. itoa(get_current_wpm(), wpm, 10);
  112. oled_write_ln(wpm, false);
  113. }
  114. bool oled_task_user(void) {
  115. if (is_keyboard_master()) {
  116. oled_render_layer_state();
  117. oled_render_keylog();
  118. render_bootmagic_status();
  119. # ifdef LUNA_ENABLE
  120. led_usb_state = host_keyboard_led_state();
  121. render_luna(0, 13);
  122. # endif
  123. } else {
  124. # ifdef OCEAN_DREAM_ENABLE
  125. render_stars();
  126. # endif
  127. }
  128. return false;
  129. }
  130. #endif // OLED_ENABLE