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.

489 lines
19 KiB

  1. /* Copyright 2021 John Ezra
  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. //Sets up what the OLED screens display.
  17. #include QMK_KEYBOARD_H
  18. int timer = 0;
  19. char wpm_counter[5];
  20. int x = 31;
  21. int currwpm = 0;
  22. int vert_count = 0;
  23. //============= USER CONFIG PARAMS ===============
  24. float max_wpm = 150.0f; //WPM value at the top of the graph window
  25. int graph_refresh_interval = 100; //in milliseconds
  26. int graph_area_fill_interval = 3; //determines how dense the horizontal lines under the graph line are; lower = more dense
  27. int vert_interval = 3; //determines frequency of vertical lines under the graph line
  28. bool vert_line = false; //determines whether to draw vertical lines
  29. int graph_line_thickness = 2; //determines thickness of graph line in pixels
  30. //============= END USER PARAMS ===============
  31. #ifdef OLED_ENABLE
  32. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  33. return OLED_ROTATION_180;
  34. }
  35. static void render_qmk_logo(void) {
  36. static const char PROGMEM qmk_logo[] = {
  37. 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0x70, 0x70, 0x7e, 0xf0, 0xf0, 0xfe, 0xf0, 0x70, 0x7e,
  38. 0x70, 0xf0, 0xfe, 0xf0, 0xf0, 0x7e, 0x70, 0x70, 0xf0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  39. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x92, 0x92, 0x92, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
  46. 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x92, 0x92, 0x92, 0x00, 0x00,
  47. 0xf8, 0xfc, 0x0e, 0x06, 0x06, 0x06, 0x0e, 0xfc, 0xf8, 0x00, 0xfe, 0xfe, 0x1c, 0x38, 0x70, 0xe0,
  48. 0x70, 0x38, 0x1c, 0xfe, 0xfe, 0x00, 0xfe, 0xfe, 0xe0, 0xf0, 0xb8, 0x1c, 0x0e, 0x06, 0x00, 0x00,
  49. 0x00, 0xfe, 0xfe, 0xc6, 0xc6, 0xc6, 0x06, 0x00, 0xe6, 0xe6, 0x00, 0xf0, 0xf0, 0x60, 0x30, 0x30,
  50. 0x60, 0x00, 0xf0, 0xf0, 0x30, 0x30, 0xe0, 0xc0, 0x30, 0x30, 0x30, 0xe0, 0xc0, 0x00, 0xf0, 0xf0,
  51. 0x00, 0xc0, 0xe0, 0x70, 0xe0, 0xc0, 0x00, 0xf0, 0xf0, 0x00, 0x20, 0xb0, 0x90, 0xb0, 0xf0, 0xe0,
  52. 0x00, 0xf0, 0xf0, 0x60, 0x30, 0x30, 0x60, 0x00, 0xc0, 0xe0, 0x30, 0x30, 0x30, 0xe0, 0xc0, 0x00,
  53. 0x00, 0x24, 0x24, 0x24, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xf1, 0xe3, 0xe3, 0x00, 0x00,
  54. 0x00, 0xe3, 0xe3, 0xf1, 0xf0, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0x24, 0x24, 0x24, 0x00, 0x00,
  55. 0x03, 0x07, 0x0e, 0x0c, 0x0c, 0x1c, 0x1e, 0x17, 0x13, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x0f, 0x0f, 0x00, 0x01, 0x03, 0x07, 0x0e, 0x0c, 0x00, 0x00,
  57. 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x01, 0x0f,
  59. 0x0f, 0x07, 0x01, 0x00, 0x01, 0x07, 0x0f, 0x0f, 0x01, 0x00, 0x07, 0x0f, 0x0c, 0x04, 0x0f, 0x0f,
  60. 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0d, 0x09, 0x09, 0x0d, 0x04, 0x00,
  61. 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x07, 0x3f, 0x07, 0x07, 0x3f, 0x07, 0x07, 0x3f,
  62. 0x07, 0x07, 0x3f, 0x07, 0x07, 0x3f, 0x07, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  69. };
  70. oled_write_raw_P(qmk_logo, sizeof(qmk_logo));
  71. }
  72. // Loop to create line by line rendering for Horizontal display
  73. // Input is oled_render_image(how many rows tall, how many pixels wide, what to render, X pos, Y pos, Frame offset)
  74. void oled_render_image(int lines, int px, const char render_line[][px], int X_pos, int Y_pos, int frame) {
  75. for (uint8_t i = 0; i < lines; i++){
  76. oled_set_cursor(X_pos, Y_pos + i);
  77. oled_write_raw_P(render_line[i + frame], px);
  78. }
  79. }
  80. static void render_layers(void) {
  81. static const char PROGMEM layer_background_r1[1][38] = {
  82. {0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x82, 0x82, 0x42,
  83. 0x42, 0x42, 0x22, 0x22, 0x22, 0x42, 0x42, 0x42, 0x82, 0x82, 0x82, 0x02, 0x02, 0x02, 0x02, 0x02,
  84. 0x02, 0x02, 0x02, 0x02, 0x02, 0xfe}
  85. };
  86. static const char PROGMEM layer_background_r2[1][38] = {
  87. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x20, 0x20, 0x20, 0x40,
  88. 0x40, 0x40, 0x80, 0x80, 0x80, 0x40, 0x40, 0x40, 0x20, 0x20, 0x20, 0x11, 0x11, 0x11, 0xaa, 0xaa,
  89. 0xaa, 0x44, 0x44, 0x44, 0x00, 0xff}
  90. };
  91. static const char PROGMEM layer_background_r3[1][38] = {
  92. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x44,
  93. 0x44, 0x44, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0xaa, 0xaa,
  94. 0xaa, 0x44, 0x44, 0x44, 0x00, 0xff}
  95. };
  96. static const char PROGMEM layer_background_r4[1][38] = {
  97. {0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x42, 0x42, 0x42, 0x44,
  98. 0x44, 0x44, 0x48, 0x48, 0x48, 0x44, 0x44, 0x44, 0x42, 0x42, 0x42, 0x41, 0x41, 0x41, 0x40, 0x40,
  99. 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f}
  100. };
  101. static const char PROGMEM base[1][38] = {
  102. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xae, 0xae, 0xae, 0x1f, 0x1f, 0x1f, 0x3e, 0x3e, 0x3e, 0x7c,
  103. 0x7c, 0x7c, 0xf8, 0xf8, 0xf8, 0x7c, 0x7c, 0x7c, 0x3e, 0x3e, 0x3e, 0x1f, 0x1f, 0x1f, 0xae, 0xae,
  104. 0xae, 0x44, 0x44, 0x44, 0x00, 0xff}
  105. };
  106. static const char PROGMEM lower[2][38] = {
  107. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xea, 0xea, 0xea, 0xf1, 0xf1, 0xf1, 0xe2, 0xe2, 0xe2, 0xc4,
  108. 0xc4, 0xc4, 0x88, 0x88, 0x88, 0xc4, 0xc4, 0xc4, 0xe2, 0xe2, 0xe2, 0xf1, 0xf1, 0xf1, 0xea, 0xea,
  109. 0xea, 0x44, 0x44, 0x44, 0x00, 0xff},
  110. {0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x43, 0x43, 0x43, 0x47,
  111. 0x47, 0x47, 0x4f, 0x4f, 0x4f, 0x47, 0x47, 0x47, 0x43, 0x43, 0x43, 0x41, 0x41, 0x41, 0x40, 0x40,
  112. 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f}
  113. };
  114. static const char PROGMEM raise[][38] = {
  115. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xea, 0xea, 0xea, 0xf1, 0xf1, 0xf1, 0xe0, 0xe0, 0xe0, 0xc0,
  116. 0xc0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xf1, 0xf1, 0xf1, 0xea, 0xea,
  117. 0xea, 0x44, 0x44, 0x44, 0x00, 0xff},
  118. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x23, 0x23, 0x23, 0x47,
  119. 0x47, 0x47, 0x8f, 0x8f, 0x8f, 0x47, 0x47, 0x47, 0x23, 0x23, 0x23, 0x11, 0x11, 0x11, 0xaa, 0xaa,
  120. 0xaa, 0x44, 0x44, 0x44, 0x00, 0xff}
  121. };
  122. static const char PROGMEM adjust[][38] = {
  123. {0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x82, 0x82, 0xc2,
  124. 0xc2, 0xc2, 0xe2, 0xe2, 0xe2, 0xc2, 0xc2, 0xc2, 0x82, 0x82, 0x82, 0x02, 0x02, 0x02, 0x02, 0x02,
  125. 0x02, 0x02, 0x02, 0x02, 0x02, 0xfe},
  126. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xae, 0xae, 0xae, 0x1f, 0x1f, 0x1f, 0x3f, 0x3f, 0x3f, 0x7f,
  127. 0x7f, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0x1f, 0xae, 0xae,
  128. 0xae, 0x44, 0x44, 0x44, 0x00, 0xff}
  129. };
  130. static const char PROGMEM custom[][38] = {
  131. {0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x82, 0x82, 0x82, 0x42,
  132. 0xc2, 0x42, 0xa2, 0x62, 0xa2, 0x42, 0xc2, 0x42, 0x82, 0x82, 0x82, 0x02, 0x02, 0x02, 0x02, 0x02,
  133. 0x02, 0x02, 0x02, 0x02, 0x02, 0xfe},
  134. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xaa, 0xee, 0xaa, 0x55, 0xbb, 0x55, 0xaa, 0x75, 0xaa, 0x55,
  135. 0xea, 0x55, 0xaa, 0xd5, 0xaa, 0x55, 0xea, 0x55, 0xaa, 0x75, 0xaa, 0x55, 0xbb, 0x55, 0xaa, 0xee,
  136. 0xaa, 0x44, 0x44, 0x44, 0x00, 0xff},
  137. {0x00, 0xff, 0x00, 0x44, 0x44, 0x44, 0xaa, 0xee, 0xaa, 0x55, 0xbb, 0x55, 0xaa, 0x77, 0xaa, 0x55,
  138. 0xee, 0x55, 0xaa, 0xdd, 0xaa, 0x55, 0xee, 0x55, 0xaa, 0x77, 0xaa, 0x55, 0xbb, 0x55, 0xaa, 0xee,
  139. 0xaa, 0x44, 0x44, 0x44, 0x00, 0xff},
  140. {0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x42, 0x43, 0x42, 0x45,
  141. 0x46, 0x45, 0x4a, 0x4d, 0x4a, 0x45, 0x46, 0x45, 0x42, 0x43, 0x42, 0x41, 0x41, 0x41, 0x40, 0x40,
  142. 0x40, 0x40, 0x40, 0x40, 0x40, 0x7f}
  143. };
  144. switch (get_highest_layer(layer_state)) {
  145. case 0:
  146. oled_render_image(1, 38, layer_background_r1, 15, 4, 0);
  147. oled_render_image(1, 38, layer_background_r2, 15, 5, 0);
  148. oled_render_image(1, 38, base, 15, 6, 0);
  149. oled_render_image(1, 38, layer_background_r4, 15, 7, 0);
  150. break;
  151. case 3:
  152. oled_render_image(2, 38, lower, 15, 6, 0);
  153. break;
  154. case 4:
  155. oled_render_image(1, 38, layer_background_r1, 15, 4, 0);
  156. oled_render_image(2, 38, raise, 15, 5, 0);
  157. oled_render_image(1, 38, layer_background_r4, 15, 7, 0);
  158. break;
  159. case 5:
  160. oled_render_image(2, 38, adjust, 15, 4, 0);
  161. oled_render_image(1, 38, layer_background_r3, 15, 6, 0);
  162. oled_render_image(1, 38, layer_background_r4, 15, 7, 0);
  163. break;
  164. default:
  165. oled_render_image(4, 38, custom, 15, 4, 0);
  166. break;
  167. }
  168. }
  169. void render_mod_state(uint8_t modifiers) {
  170. static const char PROGMEM gui_off [][3]= {{0x80, 0x81, 0}, {0xa0, 0xa1, 0}};
  171. static const char PROGMEM gui_on [][3]= {{0xc0, 0xc1, 0}, {0xe0, 0xe1, 0}};
  172. static const char PROGMEM alt_off [][3]= {{0x82, 0x83, 0}, {0xa2, 0xa3, 0}};
  173. static const char PROGMEM alt_on [][3]= {{0xc2, 0xc3, 0}, {0xe2, 0xe3, 0}};
  174. static const char PROGMEM ctrl_off [][3]= {{0x84, 0x85, 0}, {0xa4, 0xa5, 0}};
  175. static const char PROGMEM ctrl_on [][3]= {{0xc4, 0xc5, 0}, {0xe4, 0xe5, 0}};
  176. static const char PROGMEM shift_off [][3]= {{0x86, 0x87, 0}, {0xa6, 0xa7, 0}};
  177. static const char PROGMEM shift_on [][3]= {{0xc6, 0xc7, 0}, {0xe6, 0xe7, 0}};
  178. // fillers between the modifier icons bleed into the icon frames
  179. static const char PROGMEM off_off [][2]= {{0x9e, 0}, {0xbe, 0}};
  180. static const char PROGMEM on_on [][2]= {{0xdf, 0}, {0xff, 0}};
  181. static const char PROGMEM on_off [][2]= {{0xde, 0}, {0xfe, 0}};
  182. static const char PROGMEM off_on [][2]= {{0x9f, 0}, {0xbf, 0}};
  183. // render icons
  184. if(modifiers & MOD_MASK_GUI) {
  185. oled_set_cursor(0, 4);
  186. oled_write_P(gui_on[0], false);
  187. oled_set_cursor(0, 5);
  188. oled_write_P(gui_on[1], false);
  189. } else {
  190. oled_set_cursor(0, 4);
  191. oled_write_P(gui_off[0], false);
  192. oled_set_cursor(0, 5);
  193. oled_write_P(gui_off[1], false);
  194. }
  195. if(modifiers & MOD_MASK_ALT) {
  196. oled_set_cursor(3, 4);
  197. oled_write_P(alt_on[0], false);
  198. oled_set_cursor(3, 5);
  199. oled_write_P(alt_on[1], false);
  200. } else {
  201. oled_set_cursor(3, 4);
  202. oled_write_P(alt_off[0], false);
  203. oled_set_cursor(3, 5);
  204. oled_write_P(alt_off[1], false);
  205. }
  206. if(modifiers & MOD_MASK_CTRL) {
  207. oled_set_cursor(0, 6);
  208. oled_write_P(ctrl_on[0], false);
  209. oled_set_cursor(0, 7);
  210. oled_write_P(ctrl_on[1], false);
  211. } else {
  212. oled_set_cursor(0, 6);
  213. oled_write_P(ctrl_off[0], false);
  214. oled_set_cursor(0, 7);
  215. oled_write_P(ctrl_off[1], false);
  216. }
  217. if(modifiers & MOD_MASK_SHIFT) {
  218. oled_set_cursor(3, 6);
  219. oled_write_P(shift_on[0], false);
  220. oled_set_cursor(3, 7);
  221. oled_write_P(shift_on[1], false);
  222. } else {
  223. oled_set_cursor(3, 6);
  224. oled_write_P(shift_off[0], false);
  225. oled_set_cursor(3, 7);
  226. oled_write_P(shift_off[1], false);
  227. }
  228. // render fillers
  229. if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) {
  230. oled_set_cursor(2, 4);
  231. oled_write_P(on_on[0], false);
  232. oled_set_cursor(2, 5);
  233. oled_write_P(on_on[1], false);
  234. } else if(modifiers & MOD_MASK_GUI) {
  235. oled_set_cursor(2, 4);
  236. oled_write_P(on_off[0], false);
  237. oled_set_cursor(2, 5);
  238. oled_write_P(on_off[1], false);
  239. } else if(modifiers & MOD_MASK_ALT) {
  240. oled_set_cursor(2, 4);
  241. oled_write_P(off_on[0], false);
  242. oled_set_cursor(2, 5);
  243. oled_write_P(off_on[1], false);
  244. } else {
  245. oled_set_cursor(2, 4);
  246. oled_write_P(off_off[0], false);
  247. oled_set_cursor(2, 5);
  248. oled_write_P(off_off[1], false);
  249. }
  250. if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) {
  251. oled_set_cursor(2, 6);
  252. oled_write_P(on_on[0], false);
  253. oled_set_cursor(2, 7);
  254. oled_write_P(on_on[1], false);
  255. } else if(modifiers & MOD_MASK_CTRL) {
  256. oled_set_cursor(2, 6);
  257. oled_write_P(on_off[0], false);
  258. oled_set_cursor(2, 7);
  259. oled_write_P(on_off[1], false);
  260. } else if(modifiers & MOD_MASK_SHIFT) {
  261. oled_set_cursor(2, 6);
  262. oled_write_P(off_on[0], false);
  263. oled_set_cursor(2, 7);
  264. oled_write_P(off_on[1], false);
  265. } else {
  266. oled_set_cursor(2, 6);
  267. oled_write_P(off_off[0], false);
  268. oled_set_cursor(2, 7);
  269. oled_write_P(off_off[1], false);
  270. }
  271. }
  272. void render_bootmagic_status(void) {
  273. static const char PROGMEM nkro_off [][3]= {{0x88, 0x89, 0}, {0xa8, 0xa9, 0}};
  274. static const char PROGMEM nkro_on [][3]= {{0xc8, 0xc9, 0}, {0xe8, 0xe9, 0}};
  275. static const char PROGMEM mac_os_off [][6]= {{0x90, 0x91, 0x92, 0x93, 0x94, 0}, {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0}};
  276. static const char PROGMEM mac_os_on [][6]= {{0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0}, {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0}};
  277. static const char PROGMEM windows_off [][6]= {{0x95, 0x96, 0x97, 0x98, 0x99, 0}, {0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0}};
  278. static const char PROGMEM windows_on [][6]= {{0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0}, {0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0}};
  279. if (keymap_config.nkro) {
  280. oled_set_cursor(5, 4);
  281. oled_write_P(nkro_on[0], false);
  282. oled_set_cursor(5, 5);
  283. oled_write_P(nkro_on[1], false);
  284. } else {
  285. oled_set_cursor(5, 4);
  286. oled_write_P(nkro_off[0], false);
  287. oled_set_cursor(5, 5);
  288. oled_write_P(nkro_off[1], false);
  289. }
  290. if (keymap_config.swap_lctl_lgui) {
  291. oled_set_cursor(10, 6);
  292. oled_write_P(windows_on[0], false);
  293. oled_set_cursor(10, 7);
  294. oled_write_P(windows_on[1], false);
  295. oled_set_cursor(10, 4);
  296. oled_write_P(mac_os_off[0], false);
  297. oled_set_cursor(10, 5);
  298. oled_write_P(mac_os_off[1], false);
  299. } else {
  300. oled_set_cursor(10, 4);
  301. oled_write_P(mac_os_on[0], false);
  302. oled_set_cursor(10, 5);
  303. oled_write_P(mac_os_on[1], false);
  304. oled_set_cursor(10, 6);
  305. oled_write_P(windows_off[0], false);
  306. oled_set_cursor(10, 7);
  307. oled_write_P(windows_off[1], false);
  308. }
  309. }
  310. void render_lock_status(void) {
  311. static const char PROGMEM caps_off [][3]= {{0x8a, 0x8b, 0}, {0xaa, 0xab, 0}};
  312. static const char PROGMEM caps_on [][3]= {{0xca, 0xcb, 0}, {0xea, 0xeb, 0}};
  313. static const char PROGMEM num_off [][3]= {{0x8c, 0x8d, 0}, {0xac, 0xad, 0}};
  314. static const char PROGMEM num_on [][3]= {{0xcc, 0xcd, 0}, {0xec, 0xed, 0}};
  315. static const char PROGMEM scrl_off [][3]= {{0x8e, 0x8f, 0}, {0xae, 0xaf, 0}};
  316. static const char PROGMEM scrl_on [][3]= {{0xce, 0xcf, 0}, {0xee, 0xef, 0}};
  317. static const char PROGMEM off_off [][2]= {{0x9e, 0}, {0xbe, 0}};
  318. static const char PROGMEM on_on [][2]= {{0xdf, 0}, {0xff, 0}};
  319. static const char PROGMEM on_off [][2]= {{0xde, 0}, {0xfe, 0}};
  320. static const char PROGMEM off_on [][2]= {{0x9f, 0}, {0xbf, 0}};
  321. led_t led_usb_state = host_keyboard_led_state();
  322. if (led_usb_state.caps_lock) {
  323. oled_set_cursor(8, 4);
  324. oled_write_P(caps_on[0], false);
  325. oled_set_cursor(8, 5);
  326. oled_write_P(caps_on[1], false);
  327. } else {
  328. oled_set_cursor(8, 4);
  329. oled_write_P(caps_off[0], false);
  330. oled_set_cursor(8, 5);
  331. oled_write_P(caps_off[1], false);
  332. }
  333. if (led_usb_state.num_lock) {
  334. oled_set_cursor(5, 6);
  335. oled_write_P(num_on[0], false);
  336. oled_set_cursor(5, 7);
  337. oled_write_P(num_on[1], false);
  338. } else {
  339. oled_set_cursor(5, 6);
  340. oled_write_P(num_off[0], false);
  341. oled_set_cursor(5, 7);
  342. oled_write_P(num_off[1], false);
  343. }
  344. if (led_usb_state.scroll_lock) {
  345. oled_set_cursor(8, 6);
  346. oled_write_P(scrl_on[0], false);
  347. oled_set_cursor(8, 7);
  348. oled_write_P(scrl_on[1], false);
  349. } else {
  350. oled_set_cursor(8, 6);
  351. oled_write_P(scrl_off[0], false);
  352. oled_set_cursor(8, 7);
  353. oled_write_P(scrl_off[1], false);
  354. }
  355. // render fillers
  356. if ((led_usb_state.caps_lock) && (keymap_config.nkro)) {
  357. oled_set_cursor(7, 4);
  358. oled_write_P(on_on[0], false);
  359. oled_set_cursor(7, 5);
  360. oled_write_P(on_on[1], false);
  361. } else if(keymap_config.nkro) {
  362. oled_set_cursor(7, 4);
  363. oled_write_P(on_off[0], false);
  364. oled_set_cursor(7, 5);
  365. oled_write_P(on_off[1], false);
  366. } else if(led_usb_state.caps_lock) {
  367. oled_set_cursor(7, 4);
  368. oled_write_P(off_on[0], false);
  369. oled_set_cursor(7, 5);
  370. oled_write_P(off_on[1], false);
  371. } else {
  372. oled_set_cursor(7, 4);
  373. oled_write_P(off_off[0], false);
  374. oled_set_cursor(7, 5);
  375. oled_write_P(off_off[1], false);
  376. }
  377. if ((led_usb_state.num_lock) && (led_usb_state.scroll_lock)) {
  378. oled_set_cursor(7, 6);
  379. oled_write_P(on_on[0], false);
  380. oled_set_cursor(7, 7);
  381. oled_write_P(on_on[1], false);
  382. } else if(led_usb_state.num_lock) {
  383. oled_set_cursor(7, 6);
  384. oled_write_P(on_off[0], false);
  385. oled_set_cursor(7, 7);
  386. oled_write_P(on_off[1], false);
  387. } else if(led_usb_state.scroll_lock) {
  388. oled_set_cursor(7, 6);
  389. oled_write_P(off_on[0], false);
  390. oled_set_cursor(7, 7);
  391. oled_write_P(off_on[1], false);
  392. } else {
  393. oled_set_cursor(7, 6);
  394. oled_write_P(off_off[0], false);
  395. oled_set_cursor(7, 7);
  396. oled_write_P(off_off[1], false);
  397. }
  398. }
  399. void render_wpm_graph(void) {
  400. currwpm = get_current_wpm(); //get current WPM value
  401. if(timer_elapsed(timer) > graph_refresh_interval){ //check if it's been long enough before refreshing graph
  402. x = 63 - ((currwpm / max_wpm) * 63); // main calculation to plot graph line
  403. for(int i = 0; i <= graph_line_thickness - 1; i++){ //first draw actual value line
  404. oled_write_pixel(1, x + i, true);
  405. }
  406. if(vert_line){ //then fill in area below the value line
  407. if(vert_count == vert_interval){
  408. vert_count = 0;
  409. while(x <= 63){
  410. oled_write_pixel(1, x, true);
  411. x++;
  412. }
  413. } else {
  414. for(int i = 63; i > x; i--){
  415. if(i % graph_area_fill_interval == 0){
  416. oled_write_pixel(1, i, true);
  417. }
  418. }
  419. vert_count++;
  420. }
  421. } else {
  422. for(int i = 63; i > x; i--){
  423. if(i % graph_area_fill_interval == 0){
  424. oled_write_pixel(1, i, true);
  425. }
  426. }
  427. }
  428. oled_pan(false); //then move the entire graph one pixel to the right
  429. timer = timer_read(); //refresh the timer for the next iteration
  430. }
  431. char buf[4]; //format current WPM value into a printable string
  432. oled_set_cursor(14, 0);
  433. oled_write("WPM:", false);
  434. buf[0] = currwpm >= 100 ? ((currwpm/100) + '0') : ' ';
  435. buf[1] = currwpm >= 10 ? (((currwpm/10) % 10) + '0') : ' ';
  436. buf[2] = (currwpm % 10) + '0';
  437. buf[3] = 0;
  438. oled_write(buf, false);
  439. }
  440. void render_status_main(void) {
  441. render_qmk_logo();
  442. render_layers();
  443. render_mod_state(get_mods());
  444. render_bootmagic_status();
  445. render_lock_status();
  446. }
  447. void render_status_secondary(void) {
  448. render_wpm_graph();
  449. }
  450. void oled_task_user(void) {
  451. if (is_keyboard_master()) {
  452. render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc)
  453. } else {
  454. render_status_secondary();
  455. }
  456. }
  457. #endif