oled_display.c 3.8 KB

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