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.

216 lines
6.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. /* Copyright 2021 Batuhan Başerdem
  2. * <baserdem.batuhan@gmail.com> @bbaserdem
  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. #include "bb-oled.h"
  18. #include <string.h>
  19. // Grab the print function
  20. #ifdef ENCODER_ENABLE
  21. # include "bb-encoder.h"
  22. #endif // ENCODER_ENABLE
  23. /* OLED
  24. * This contains general purpose oled code
  25. */
  26. // Allow default to be overwritten by keymap if they return false
  27. __attribute__ ((weak)) bool oled_task_keymap(void) {return true;}
  28. // Do sane defaults for regular oled rendering
  29. void oled_task_user(void) {
  30. if (is_oled_on()) {
  31. if (oled_task_keymap()) {
  32. render_status_lite(0, 0);
  33. }
  34. }
  35. }
  36. /*-------------------------*\
  37. |*---RENDERING FUNCTIONS---*|
  38. \*-------------------------*/
  39. void render_qmk_logo(uint8_t row, uint8_t col) {
  40. static const char PROGMEM qmk_logo[] = {
  41. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,
  42. 0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,
  43. 0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  44. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,
  45. 0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  46. oled_set_cursor(col, row);
  47. oled_write_P(qmk_logo, false);
  48. }
  49. void render_layer(uint8_t row, uint8_t col, uint8_t top_layer) {
  50. // Write the layer state; 17 chars
  51. oled_set_cursor(col, row);
  52. oled_write("Layer: ", false);
  53. switch (top_layer) {
  54. case _BASE:
  55. oled_write("Default ", false);
  56. break;
  57. case _CHAR:
  58. oled_write("Sp. Chars ", false);
  59. break;
  60. case _GAME:
  61. oled_write("Gaming ", false);
  62. break;
  63. case _MEDI:
  64. oled_write("Media Ctr ", false);
  65. break;
  66. case _NAVI:
  67. oled_write("Navigation", false);
  68. break;
  69. case _SYMB:
  70. oled_write("Symbols ", false);
  71. break;
  72. case _NUMB:
  73. oled_write("Numpad ", false);
  74. break;
  75. case _FUNC:
  76. oled_write("Funct Keys", false);
  77. break;
  78. case _MOUS:
  79. oled_write("Mouse Keys", false);
  80. break;
  81. case _MUSI:
  82. oled_write("Music Mode", false);
  83. break;
  84. default:
  85. oled_write("?? N/A ?? ", false);
  86. }
  87. }
  88. void render_modifiers_lite(uint8_t row, uint8_t col, uint8_t mods) {
  89. // Write the modifier state, 16 characters
  90. oled_set_cursor(col, row);
  91. oled_write((mods & MOD_MASK_SHIFT ) ? "Shft " : " ", false);
  92. oled_write((mods & MOD_MASK_CTRL ) ? "Ctrl " : " ", false);
  93. oled_write((mods & MOD_MASK_ALT ) ? "Alt" : " ", false);
  94. oled_write((mods & MOD_BIT(KC_RALT)) ? "G " : " ", false);
  95. oled_write((mods & MOD_MASK_GUI ) ? "Meta " : " ", false);
  96. }
  97. void render_encoder(uint8_t row, uint8_t col, uint8_t index, uint8_t layer) {
  98. // Renders the encoder state, 14 characters
  99. oled_set_cursor(col, row);
  100. # ifdef ENCODER_ENABLE
  101. static char encoder_temp9[9] = {0};
  102. oled_write("Enc: ", false);
  103. encoder_state_string(index, layer, encoder_temp9);
  104. oled_write(encoder_temp9, false);
  105. # else // ENCODER_ENABLE
  106. oled_write("No enc. avail.", false);
  107. # endif // ENCODER_ENABLE
  108. }
  109. void render_wpm(uint8_t row, uint8_t col) {
  110. // Renders the WPM, 8 characters
  111. oled_set_cursor(col, row);
  112. # ifdef WPM_ENABLE
  113. static char wpm_temp4[4] = {0};
  114. oled_write("WPM: ", false);
  115. itoa(get_current_wpm(), wpm_temp4, 10);
  116. oled_write(wpm_temp4, false);
  117. oled_write(" ", false);
  118. # else // WPM_ENABLE
  119. oled_write("WPM: N/A", false);
  120. # endif // WPM_ENABLE
  121. }
  122. // Writes the currently used OLED display layout
  123. void render_keymap(uint8_t row, uint8_t col, bool isLite) {
  124. // Render the oled layout; lite is 11, regular is 14 characters
  125. oled_set_cursor(col, row);
  126. if (isLite) {
  127. oled_write("KM: ", false);
  128. } else {
  129. oled_write("Layout: ", false);
  130. }
  131. switch (userspace_config.layout % 3) {
  132. case 0:
  133. oled_write("Dvorak", false);
  134. break;
  135. case 1:
  136. oled_write("Tur. F", false);
  137. break;
  138. case 2:
  139. oled_write("Qwerty", false);
  140. break;
  141. }
  142. if (isLite) {
  143. oled_write(" ", false);
  144. }
  145. }
  146. // Writes the currently used OLED display layout
  147. #ifdef RGB_MATRIX_ENABLE
  148. void render_rgb_lite(uint8_t row, uint8_t col) {
  149. // Writes the currently used OLED display layout, 19 characters
  150. static char rgb_temp4[4] = {0};
  151. // Render the oled layout
  152. oled_set_cursor(col, row);
  153. oled_write("m", false);
  154. itoa(rgb_matrix_get_mode(), rgb_temp4, 10);
  155. oled_write(rgb_temp4, false);
  156. oled_write(" h", false);
  157. itoa(rgb_matrix_get_hue(), rgb_temp4, 10);
  158. oled_write(rgb_temp4, false);
  159. oled_write(" s", false);
  160. itoa(rgb_matrix_get_sat(), rgb_temp4, 10);
  161. oled_write(rgb_temp4, false);
  162. oled_write(" v", false);
  163. itoa(rgb_matrix_get_val(), rgb_temp4, 10);
  164. oled_write(rgb_temp4, false);
  165. }
  166. #endif // RGB_MATRIX_ENABLE
  167. void render_status_lite(uint8_t row, uint8_t col) {
  168. // Function to print state information; for low flash memory
  169. uint8_t this_layer = get_highest_layer(layer_state);
  170. uint8_t this_mod = get_mods();
  171. // Line 1: Layer State
  172. render_layer(row + 0, col + 0, this_layer);
  173. // Line 2: Mod or info
  174. switch (this_layer) {
  175. // Show RGB mode as an overlay in media mode.
  176. # ifdef RGB_MATRIX_ENABLE
  177. case _MEDI:
  178. render_rgb_lite(row + 1, col + 0);
  179. break;
  180. # endif // RGB_MATRIX_ENABLE
  181. // Show the modifier if nothing else is doing anything
  182. default:
  183. render_modifiers_lite(row + 1, col + 0, this_mod);
  184. break;
  185. }
  186. // Line 3: WPM and layout
  187. render_keymap(row + 2, col + 0, true);
  188. render_wpm(row + 2, col + 11);
  189. // Line 4: Encoder states
  190. # ifdef SPLIT_KEYBOARD
  191. if (is_keyboard_left()) {
  192. render_encoder(row + 3, col + 0, 0, this_layer);
  193. } else {
  194. render_encoder(row + 3, col + 0, 1, this_layer);
  195. }
  196. # else // SPLIT_KEYBOARD
  197. render_encoder(row + 3, col + 0, 0, this_layer);
  198. # endif // SPLIT_KEYBOARD
  199. }