oled_stuff.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. Copyright 2018-2022 Eric Gebhart <e.a.gebhart@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "ericgebhart.h"
  15. #include <string.h>
  16. #include <stdio.h>
  17. #ifdef OLED_CUSTOM_ENABLE
  18. extern uint32_t current_locale;
  19. void oled_render_locale(void) {
  20. // oled_write_P(PSTR("Layout: "), false);
  21. switch (current_locale) {
  22. WRITE_STR_CASE(LOCALE_DEFAULT, DEFAULT_LANG_NAME)
  23. #ifdef SECOND_LOCALE
  24. WRITE_STR_CASE(LOCALE_TWO, SECOND_LOCALE_NAME)
  25. #endif
  26. }
  27. }
  28. void oled_render_keylock_status(uint8_t led_usb_state) {
  29. oled_write_P(PSTR(" Lock:"), false);
  30. oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK));
  31. oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK));
  32. oled_write_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
  33. }
  34. void oled_render_mod_status(uint8_t modifiers) {
  35. oled_write_P(PSTR("Mods:"), false);
  36. oled_write_P(PSTR("S"), (modifiers & MOD_MASK_SHIFT));
  37. oled_write_P(PSTR("C"), (modifiers & MOD_MASK_CTRL));
  38. oled_write_P(PSTR("A"), (modifiers & MOD_MASK_ALT));
  39. oled_write_P(PSTR("G"), (modifiers & MOD_MASK_GUI));
  40. }
  41. void oled_render_mod_lock_status(){
  42. oled_render_mod_status(get_mods() | get_oneshot_mods());
  43. oled_render_keylock_status(host_keyboard_leds());
  44. }
  45. #ifdef KEYLOGGER_ENABLE
  46. char mkeylog_str[22] = {};
  47. const char mcode_to_name[60] = {
  48. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  49. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  50. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  51. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  52. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  53. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  54. void oled_render_keylog(void) {
  55. oled_write_ln(mkeylog_str, false);
  56. }
  57. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  58. char name = ' ';
  59. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
  60. (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  61. keycode = keycode & 0xFF;
  62. }
  63. if (keycode < 60) {
  64. name = mcode_to_name[keycode];
  65. }
  66. // update keylog
  67. memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1);
  68. snprintf(mkeylog_str, sizeof(mkeylog_str), "%dx%d, k%2d : %c",
  69. record->event.key.row, record->event.key.col,
  70. keycode, name);
  71. }
  72. #endif
  73. __attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) { return rotation; }
  74. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  75. // for the big screen.
  76. #ifdef OLED_DISPLAY_128X64
  77. return OLED_ROTATION_180;
  78. #endif
  79. // rotate the slave side of the corne to be bottom side in.
  80. if (!is_keyboard_master()) {
  81. return OLED_ROTATION_180;
  82. }
  83. return oled_init_keymap(rotation);
  84. }
  85. /* oled_rotation_t oled_init_user(oled_rotation_t rotation) { */
  86. /* memset(mkeylog_str, ' ', sizeof(mkeylog_str) - 1); */
  87. /* if (is_keyboard_master()) { */
  88. /* return OLED_ROTATION_270; */
  89. /* } else { */
  90. /* return OLED_ROTATION_180; */
  91. /* } */
  92. /* } */
  93. void render_bootmagic_status(bool status) {
  94. /* Show Ctrl-Gui Swap options */
  95. static const char PROGMEM logo[][2][3] = {
  96. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  97. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  98. };
  99. if (status) {
  100. oled_write_ln_P(logo[0][0], false);
  101. oled_write_ln_P(logo[0][1], false);
  102. } else {
  103. oled_write_ln_P(logo[1][0], false);
  104. oled_write_ln_P(logo[1][1], false);
  105. }
  106. }
  107. __attribute__((weak)) void oled_render_logo(void) {
  108. // clang-format off
  109. static const char PROGMEM qmk_logo[] = {
  110. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  111. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  112. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  113. // clang-format on
  114. oled_write_P(qmk_logo, false);
  115. }
  116. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  117. #ifdef KEYLOGGER_ENABLE
  118. if (record->event.pressed) {
  119. //oled_timer = timer_read32();
  120. add_keylog(keycode, record);
  121. //add_keylog(keycode);
  122. }
  123. #endif
  124. return true;
  125. }
  126. bool oled_task_user(void) {
  127. //oled_clear();
  128. if (is_keyboard_master()) {
  129. oled_render_mod_lock_status();
  130. oled_advance_page(false);
  131. oled_render_default_layer_state();
  132. oled_render_locale();
  133. oled_write_ln_P(PSTR(" "), false);
  134. oled_render_layer_state();
  135. oled_write_ln_P(PSTR(" "), false);
  136. #ifdef OLED_DISPLAY_128X64
  137. oled_render_layer_map();
  138. #endif
  139. #ifdef KEYLOGGER_ENABLE
  140. oled_render_keylog();
  141. #endif
  142. // slave side display.
  143. } else {
  144. oled_clear();
  145. #ifdef OLED_LOGO_ENABLE
  146. oled_render_logo();
  147. #endif
  148. oled_render_default_layer_state();
  149. oled_render_locale();
  150. oled_write_ln_P(PSTR(" "), false);
  151. #ifdef SPLIT_LAYER_STATE_ENABLE
  152. oled_render_layer_state();
  153. oled_render_layer_map();
  154. #endif
  155. }
  156. return(false);
  157. }
  158. #endif
  159. /* oled_render_keylock_status(host_keyboard_leds()); */
  160. /* oled_render_mod_status(get_mods() | get_oneshot_mods()); */