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.

141 lines
4.2 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_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_LOWER 2
  31. # define L_RAISE 4
  32. # define L_ADJUST 8
  33. void oled_render_layer_state(void) {
  34. oled_write_P(PSTR("Layer"), false);
  35. switch (layer_state) {
  36. case L_BASE:
  37. oled_write_ln_P(PSTR("Main"), false);
  38. break;
  39. case L_LOWER:
  40. oled_write_ln_P(PSTR("Bot"), false);
  41. break;
  42. case L_RAISE:
  43. oled_write_ln_P(PSTR("Top"), false);
  44. break;
  45. case L_ADJUST:
  46. case L_ADJUST | L_LOWER:
  47. case L_ADJUST | L_RAISE:
  48. case L_ADJUST | L_LOWER | L_RAISE:
  49. oled_write_ln_P(PSTR("Comb"), false);
  50. break;
  51. }
  52. }
  53. char keylog_str[24] = {};
  54. const char code_to_name[60] = {
  55. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  56. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  57. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  58. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  59. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  60. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  61. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  62. char name = ' ';
  63. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  64. keycode = keycode & 0xFF;
  65. }
  66. if (keycode < 60) {
  67. name = code_to_name[keycode];
  68. }
  69. // update keylog
  70. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", record->event.key.row, record->event.key.col, keycode, name);
  71. }
  72. void oled_render_keylog(void) { oled_write(keylog_str, false); }
  73. // void render_bootmagic_status(bool status) {
  74. // /* Show Ctrl-Gui Swap options */
  75. // static const char PROGMEM logo[][2][3] = {
  76. // {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  77. // {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  78. // };
  79. // if (status) {
  80. // oled_write_ln_P(logo[0][0], false);
  81. // oled_write_ln_P(logo[0][1], false);
  82. // } else {
  83. // oled_write_ln_P(logo[1][0], false);
  84. // oled_write_ln_P(logo[1][1], false);
  85. // }
  86. //}
  87. void render_bootmagic_status(void) {
  88. /* Show Ctrl-Gui Swap options */
  89. static const char PROGMEM logo[][2][3] = {
  90. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  91. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  92. };
  93. oled_write_P(PSTR("BTMGK"), false);
  94. oled_write_P(PSTR(""), false);
  95. if (!keymap_config.swap_lctl_lgui) {
  96. oled_write_P(logo[1][0], false);
  97. oled_write_P(PSTR(" "), false);
  98. oled_write_P(logo[1][1], false);
  99. } else {
  100. oled_write_P(logo[0][0], false);
  101. oled_write_P(PSTR(" "), false);
  102. oled_write_P(logo[0][1], false);
  103. }
  104. oled_write_P(PSTR(" NKRO "), keymap_config.nkro);
  105. oled_write_P(PSTR("WPM: "), false);
  106. char wpm[6];
  107. itoa(get_current_wpm(), wpm, 10);
  108. oled_write_ln(wpm, false);
  109. }
  110. void oled_task_user(void) {
  111. if (is_master) {
  112. oled_render_layer_state();
  113. oled_render_keylog();
  114. render_bootmagic_status();
  115. # ifdef LUNA_ENABLE
  116. led_usb_state = host_keyboard_led_state();
  117. render_luna(0, 13);
  118. # endif
  119. } else {
  120. # ifdef OCEAN_DREAM_ENABLE
  121. render_stars();
  122. # endif
  123. }
  124. }
  125. #endif // OLED_ENABLE