logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

oled.c (9436B)


  1. /*
  2. Copyright 2021 gregorio
  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 "oled.h"
  15. #include "rubi.h"
  16. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  17. return process_record_user(keycode, record);
  18. }
  19. void change_oled_mode(void) {
  20. oled_mode = (oled_mode + 1) % _NUM_OLED_MODES;
  21. }
  22. void render_layer_section(void) {
  23. // Layer indicators
  24. static const char PROGMEM layer_0[] = {0xc8, 0xc9, 0};
  25. static const char PROGMEM layer_1[] = {0xca, 0xcb, 0};
  26. static const char PROGMEM layer_2[] = {0xcc, 0xcd, 0};
  27. static const char PROGMEM layer_3[] = {0xce, 0xcf, 0};
  28. oled_set_cursor(oled_max_chars()-15, 0);
  29. oled_write_P(PSTR("LAYER"), false);
  30. switch (get_highest_layer(layer_state)) {
  31. case 0:
  32. oled_write_P(layer_0, false);
  33. break;
  34. case 1:
  35. oled_write_P(layer_1, false);
  36. break;
  37. case 2:
  38. oled_write_P(layer_2, false);
  39. break;
  40. case 3:
  41. oled_write_P(layer_3, false);
  42. break;
  43. default:
  44. oled_write_P(PSTR("? "), false);
  45. break;
  46. }
  47. }
  48. void render_encoder_section(void) {
  49. static const char PROGMEM enc_vol[] = {0x88, 0x89, 0x8a, 0x8b, 0};
  50. static const char PROGMEM enc_med[] = {0xa8, 0xa9, 0xaa, 0xab, 0};
  51. static const char PROGMEM enc_brt[] = {0x8c, 0x8d, 0x8e, 0x8f, 0};
  52. oled_set_cursor(oled_max_chars()-7, 0);
  53. oled_write_P(PSTR("ENC"), false);
  54. switch (encoder_mode) {
  55. default:
  56. case ENC_MODE_VOLUME:
  57. oled_write_P(enc_vol, false);
  58. break;
  59. case ENC_MODE_MEDIA:
  60. oled_write_P(enc_med, false);
  61. break;
  62. case ENC_MODE_BRIGHTNESS:
  63. oled_write_P(enc_brt, false);
  64. break;
  65. }
  66. }
  67. void render_numlock_section(void) {
  68. static const char PROGMEM num_on[] = {0x80, 0x81, 0x82, 0x83, 0};
  69. static const char PROGMEM num_off[] = {0xa0, 0xa1, 0xa2, 0xa3, 0};
  70. static const char PROGMEM cap_on[] = {0x84, 0x85, 0x86, 0x87, 0};
  71. static const char PROGMEM cap_off[] = {0xa4, 0xa5, 0xa6, 0xa7, 0};
  72. static const char PROGMEM scr_on[] = {0xba, 0xbb, 0xbc, 0xbd, 0};
  73. static const char PROGMEM scr_off[] = {0xda, 0xdb, 0xdc, 0xdd, 0};
  74. led_t led_state = host_keyboard_led_state();
  75. oled_set_cursor(oled_max_chars()-12, 3);
  76. // num lock
  77. oled_write_P(led_state.num_lock ? num_on : num_off, false);
  78. oled_write_P(led_state.caps_lock ? cap_on : cap_off, false);
  79. oled_write_P(led_state.scroll_lock ? scr_on : scr_off, false);
  80. }
  81. void render_mode_section(void) {
  82. static const char PROGMEM pad_on[] = {0xb0, 0xb1, 0xb2, 0xb3, 0};
  83. static const char PROGMEM pad_off[] = {0xc4, 0xc5, 0xc6, 0xc7, 0};
  84. static const char PROGMEM cal_on[] = {0x90, 0x91, 0x92, 0x93, 0};
  85. static const char PROGMEM cal_off[] = {0xc0, 0xc1, 0xc2, 0xc3, 0};
  86. if (oled_mode == OLED_MODE_CALC) {
  87. oled_set_cursor(0, 0);
  88. oled_write_P(pad_off, false);
  89. oled_set_cursor(0, 1);
  90. oled_write_P(cal_on, false);
  91. } else {
  92. oled_set_cursor(0, 0);
  93. oled_write_P(pad_on, false);
  94. oled_set_cursor(0, 1);
  95. oled_write_P(cal_off, false);
  96. }
  97. }
  98. void render_calc_section(void) {
  99. static const char PROGMEM add_on[] = {0xd4, 0xd5, 0};
  100. static const char PROGMEM add_off[] = {0x94, 0x95, 0};
  101. static const char PROGMEM sub_on[] = {0xd6, 0xd7, 0};
  102. static const char PROGMEM sub_off[] = {0x96, 0x97, 0};
  103. static const char PROGMEM mul_on[] = {0xd8, 0xd9, 0};
  104. static const char PROGMEM mul_off[] = {0x9c, 0x9d, 0};
  105. static const char PROGMEM div_on[] = {0xb8, 0xb9, 0};
  106. static const char PROGMEM div_off[] = {0x9e, 0x9f, 0};
  107. static const char PROGMEM sqr_on[] = {0x98, 0x99, 0};
  108. static const char PROGMEM sqr_off[] = {0xbe, 0xbf, 0};
  109. static const char PROGMEM rec_on[] = {0x9a, 0x9b, 0};
  110. static const char PROGMEM rec_off[] = {0xde, 0xdf, 0};
  111. static const char PROGMEM neg_on[] = {0xb4, 0xb5, 0};
  112. static const char PROGMEM neg_off[] = {0xb6, 0xb7, 0};
  113. if (oled_mode == OLED_MODE_CALC) {
  114. if (get_highest_layer(layer_state) == 1) {
  115. oled_set_cursor(oled_max_chars()-8, 0);
  116. switch (calc_operator_display) {
  117. case '+':
  118. oled_write_P(div_off, false);
  119. oled_write_P(mul_off, false);
  120. oled_write_P(sub_off, false);
  121. oled_write_P(add_on, false);
  122. break;
  123. case '-':
  124. oled_write_P(div_off, false);
  125. oled_write_P(mul_off, false);
  126. oled_write_P(sub_on, false);
  127. oled_write_P(add_off, false);
  128. break;
  129. case '*':
  130. oled_write_P(div_off, false);
  131. oled_write_P(mul_on, false);
  132. oled_write_P(sub_off, false);
  133. oled_write_P(add_off, false);
  134. break;
  135. case '/':
  136. oled_write_P(div_on, false);
  137. oled_write_P(mul_off, false);
  138. oled_write_P(sub_off, false);
  139. oled_write_P(add_off, false);
  140. break;
  141. case 's':
  142. case 'r':
  143. case 'n':
  144. layer_on(2);
  145. break;
  146. default:
  147. oled_write_P(div_off, false);
  148. oled_write_P(mul_off, false);
  149. oled_write_P(sub_off, false);
  150. oled_write_P(add_off, false);
  151. break;
  152. }
  153. } else if (get_highest_layer(layer_state) == 2) {
  154. oled_set_cursor(oled_max_chars()-6, 0);
  155. switch (calc_operator_display) {
  156. case '+':
  157. case '-':
  158. case '*':
  159. case '/':
  160. layer_off(2);
  161. break;
  162. case 's':
  163. oled_write_P(neg_off, false);
  164. oled_write_P(sqr_on, false);
  165. oled_write_P(rec_off, false);
  166. break;
  167. case 'r':
  168. oled_write_P(neg_off, false);
  169. oled_write_P(sqr_off, false);
  170. oled_write_P(rec_on, false);
  171. break;
  172. case 'n':
  173. oled_write_P(neg_on, false);
  174. oled_write_P(sqr_off, false);
  175. oled_write_P(rec_off, false);
  176. break;
  177. default:
  178. oled_write_P(neg_off, false);
  179. oled_write_P(sqr_off, false);
  180. oled_write_P(rec_off, false);
  181. break;
  182. }
  183. }
  184. if (calc_display_lines == 1) {
  185. oled_set_cursor(oled_max_chars()-strlen(calc_result_display)-2, 3);
  186. oled_write_char(calc_operator_display, false);
  187. } else if (calc_display_lines == 2) {
  188. oled_set_cursor(oled_max_chars()-strlen(calc_status_display), 2);
  189. oled_write(calc_status_display, false);
  190. }
  191. oled_set_cursor(oled_max_chars()-strlen(calc_result_display), 3);
  192. oled_write(calc_result_display, false);
  193. }
  194. }
  195. static void render_logo(void) {
  196. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  197. }
  198. void render_frame(void) {
  199. if (oled_logo_expired) {
  200. if (oled_mode == OLED_MODE_DEFAULT) {
  201. render_mode_section();
  202. render_layer_section();
  203. render_encoder_section();
  204. render_numlock_section();
  205. } else if (oled_mode == OLED_MODE_CALC) {
  206. render_mode_section();
  207. render_calc_section();
  208. } else if (oled_mode == OLED_MODE_OFF) {
  209. if (is_oled_on()) {
  210. oled_off();
  211. }
  212. }
  213. } else {
  214. render_logo();
  215. oled_logo_expired = timer_elapsed(oled_logo_timer) > OLED_LOGO_TIMEOUT;
  216. }
  217. }
  218. bool oled_task_kb(void) {
  219. if (!oled_task_user()) { return false; }
  220. if (timer_elapsed(oled_frame_timer) > OLED_FRAME_TIMEOUT) {
  221. oled_clear();
  222. oled_frame_timer = timer_read();
  223. render_frame();
  224. }
  225. if (get_highest_layer(layer_state) == 1) {
  226. oled_mode = OLED_MODE_CALC;
  227. } else if (get_highest_layer(layer_state) == 2) {
  228. if (IS_LAYER_ON(1)) {
  229. oled_mode = OLED_MODE_CALC;
  230. } else {
  231. oled_mode = OLED_MODE_DEFAULT;
  232. }
  233. } else if (get_highest_layer(layer_state) == 3) {
  234. oled_mode = OLED_MODE_OFF;
  235. } else {
  236. oled_mode = OLED_MODE_DEFAULT;
  237. }
  238. return false;
  239. }
  240. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  241. oled_logo_timer = timer_read();
  242. oled_frame_timer = timer_read();
  243. return rotation;
  244. }