oled_display.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright 2021 Jose Luis Adelantado Torres
  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. #include "quantum.h"
  17. #include "oled_display.h"
  18. static const char PROGMEM oled_mode_messages[5][15] = {
  19. "",
  20. "Volume Up",
  21. "Volume Down",
  22. "RGB ON",
  23. "RGB OFF"
  24. };
  25. static const char PROGMEM oled_mode_icons[5][3][5] = {
  26. {{128,129,130,131,0},{160,161,162,163,0},{192,193,194,195,0}},
  27. {{132,133,134,135,0},{164,165,166,167,0},{196,197,198,199,0}},
  28. {{136,137,138,139,0},{168,169,170,171,0},{200,201,202,203,0}},
  29. {{140,141,142,143,0},{172,173,174,175,0},{204,205,206,207,0}},
  30. {{144,145,146,147,0},{176,177,178,179,0},{208,209,210,211,0}}
  31. };
  32. void set_oled_mode(oled_mode_t mode) {
  33. oled_mode = mode;
  34. }
  35. void process_record_encoder_oled(uint16_t keycode) {
  36. oled_timer = timer_read32();
  37. switch (keycode) {
  38. case KC_VOLU:
  39. set_oled_mode(OLED_MODE_VOLUME_UP);
  40. break;
  41. case KC_VOLD:
  42. set_oled_mode(OLED_MODE_VOLUME_DOWN);
  43. break;
  44. default:
  45. set_oled_mode(OLED_MODE_IDLE);
  46. break;
  47. }
  48. }
  49. void process_record_keymap_oled(uint16_t keycode) {
  50. oled_timer = timer_read32();
  51. if(rgblight_is_enabled()) {
  52. set_oled_mode(OLED_MODE_RGB_OFF);
  53. } else {
  54. set_oled_mode(OLED_MODE_RGB_ON);
  55. }
  56. }
  57. void render_wpm(void) {
  58. uint8_t n = get_current_wpm();
  59. char wpm_counter[4];
  60. wpm_counter[3] = '\0';
  61. wpm_counter[2] = '0' + n % 10;
  62. wpm_counter[1] = '0' + (n /= 10) % 10;
  63. wpm_counter[0] = '0' + n / 10 ;
  64. oled_write_P(PSTR(" "), false);
  65. oled_write(wpm_counter, false);
  66. }
  67. void render_idle(void) {
  68. // Host Keyboard LED Status
  69. led_t led_state = host_keyboard_led_state();
  70. // Printing logo, state
  71. oled_write_P(oled_mode_icons[0][0], false);
  72. oled_write_P(PSTR(" "), false);
  73. oled_write_P(led_state.scroll_lock ? PSTR("S ") : PSTR(" "), false);
  74. oled_write_P(led_state.num_lock ? PSTR("N ") : PSTR(" "), false);
  75. oled_write_P(led_state.caps_lock ? PSTR("C ") : PSTR(" "), false);
  76. oled_write_P(PSTR("\n"), false);
  77. oled_write_P(oled_mode_icons[0][1], false);
  78. oled_write_P(PSTR(" Nibble"), false);
  79. oled_write_P(PSTR("\n"), false);
  80. oled_write_P(oled_mode_icons[0][2], false);
  81. oled_write_P(PSTR("\n"), false);
  82. // Printing WPM
  83. render_wpm();
  84. }
  85. void render_status_mode_message(void) {
  86. // Printing state icon with message
  87. oled_write_P(oled_mode_icons[oled_mode][0], false);
  88. oled_write_P(PSTR("\n"), false);
  89. oled_write_P(oled_mode_icons[oled_mode][1], false);
  90. oled_write_P(PSTR(" "), false);
  91. oled_write_P(oled_mode_messages[oled_mode], false);
  92. oled_write_P(PSTR("\n"), false);
  93. oled_write_P(oled_mode_icons[oled_mode][2], false);
  94. oled_write_P(PSTR("\n\n"), false);
  95. }
  96. void render_frame(void) {
  97. switch (oled_mode) {
  98. case OLED_MODE_VOLUME_UP:
  99. case OLED_MODE_VOLUME_DOWN:
  100. case OLED_MODE_RGB_ON:
  101. case OLED_MODE_RGB_OFF:
  102. render_status_mode_message();
  103. break;
  104. default:
  105. render_idle();
  106. break;
  107. }
  108. }