custom_oled.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #include "custom_oled.h"
  2. #include "process_records.h"
  3. #include <stdio.h>
  4. #ifdef RGBLIGHT_ENABLE
  5. rgblight_config_t rgblight_config;
  6. #endif
  7. #if KEYBOARD_helix_rev2
  8. extern uint8_t is_master;
  9. bool is_keyboard_master(void) { return is_master; }
  10. #endif
  11. static void render_logo(void)
  12. {
  13. static const char PROGMEM font_logo[] = {
  14. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  15. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  16. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  17. oled_write_P(font_logo, false);
  18. }
  19. static void render_icon(void)
  20. {
  21. #ifdef OLED_90ROTATION
  22. static const char PROGMEM font_icon[] = {
  23. 0x9b,0x9c,0x9d,0x9e,0x9f,
  24. 0xbb,0xbc,0xbd,0xbe,0xbf,
  25. 0xdb,0xdc,0xdd,0xde,0xdf,0
  26. };
  27. #else
  28. static const char PROGMEM font_icon[] = {
  29. // Use \r (0x0d) to jump to the next line without clearing the rest of the current line
  30. 0x9b,0x9c,0x9d,0x9e,0x9f,0x0d,
  31. 0xbb,0xbc,0xbd,0xbe,0xbf,0x0d,
  32. 0xdb,0xdc,0xdd,0xde,0xdf,0
  33. };
  34. #endif
  35. oled_write_P(font_icon, false);
  36. }
  37. static void render_layer(void)
  38. {
  39. uint8_t layer = layer_state ? biton(layer_state) : biton32(default_layer_state);
  40. #ifdef OLED_90ROTATION
  41. oled_write_P(PSTR("Layer"), false);
  42. #else
  43. oled_write_P(PSTR("Layer: "), false);
  44. #endif
  45. switch (layer)
  46. {
  47. case _QWERTY:
  48. oled_write_P(PSTR("BASE "), false);
  49. break;
  50. #ifndef GAMELAYER_DISABLE
  51. case _GAME:
  52. oled_write_P(PSTR("GAME "), false);
  53. break;
  54. #endif
  55. case _LOWER:
  56. oled_write_P(PSTR("LOWER"), false);
  57. break;
  58. case _RAISE:
  59. oled_write_P(PSTR("RAISE"), false);
  60. break;
  61. #ifdef TRILAYER_ENABLED
  62. case _ADJUST:
  63. oled_write_P(PSTR("ADJST"), false);
  64. break;
  65. #endif
  66. }
  67. }
  68. static void render_keyboard_leds(void)
  69. {
  70. // Host Keyboard LED Status
  71. uint8_t led_state = host_keyboard_leds();
  72. #ifdef OLED_90ROTATION
  73. oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR(" "), false);
  74. oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false);
  75. oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false);
  76. #else
  77. oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUM ") : PSTR(" "), false);
  78. oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false);
  79. oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRL") : PSTR(" "), false);
  80. #endif
  81. }
  82. #ifdef RGB_OLED_MENU
  83. extern uint8_t rgb_encoder_state;
  84. #endif
  85. #if defined(OLED_90ROTATION)
  86. #ifdef RGB_ENABLE
  87. static void render_rgb_state(void)
  88. {
  89. // TODO: need to do a bit more handling here for horizontal rendering
  90. #if defined(RGB_MATRIX_ENABLE)
  91. static char buffer[31] = {0};
  92. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d e%3d ", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_get_flags());
  93. #elif defined(RGBLIGHT_ENABLE)
  94. static char buffer[26] = {0};
  95. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d ", rgblight_config.hue, rgblight_config.sat, rgblight_config.val, rgblight_config.speed, rgblight_config.mode);
  96. #endif
  97. #ifdef RGB_OLED_MENU
  98. buffer[4 + rgb_encoder_state * 5] = '<';
  99. #endif
  100. oled_write(buffer, false);
  101. }
  102. #endif
  103. static void render_status(void)
  104. {
  105. render_icon();
  106. render_layer();
  107. // Host Keyboard LED Status
  108. oled_write_P(PSTR("-----"), false);
  109. render_keyboard_leds();
  110. oled_write_P(PSTR("-----"), false);
  111. #ifdef RGB_ENABLE
  112. render_rgb_state();
  113. #endif
  114. }
  115. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  116. #if KEYBOARD_helix_rev2
  117. if (is_keyboard_master())
  118. return OLED_ROTATION_270;
  119. return rotation;
  120. #else
  121. if (is_keyboard_master())
  122. return OLED_ROTATION_90;
  123. return rotation;
  124. #endif
  125. }
  126. #else // OLED_90ROTATION
  127. #ifdef RGB_ENABLE
  128. static void render_rgb_state(void)
  129. {
  130. // TODO: need to do a bit more handling here for horizontal rendering
  131. #if defined(RGB_MATRIX_ENABLE)
  132. static char buffer[37] = {0};
  133. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d e%3d ", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_get_flags());
  134. #elif defined(RGBLIGHT_ENABLE)
  135. static char buffer[32] = {0};
  136. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d ", rgblight_config.hue, rgblight_config.sat, rgblight_config.val, rgblight_config.speed, rgblight_config.mode);
  137. #endif
  138. #ifdef RGB_OLED_MENU
  139. buffer[4 + rgb_encoder_state * 5] = '<';
  140. #endif
  141. oled_write(buffer, false);
  142. }
  143. #endif
  144. static void render_status(void)
  145. {
  146. render_icon();
  147. // Host Layer Status
  148. oled_set_cursor(6, 0);
  149. render_layer();
  150. // Host Keyboard LED Status
  151. oled_set_cursor(6, 1);
  152. render_keyboard_leds();
  153. #ifdef RGB_ENABLE
  154. oled_set_cursor(6, 2);
  155. render_rgb_state();
  156. #endif
  157. }
  158. #endif // OLED_90ROTATION
  159. void oled_task_user(void)
  160. {
  161. if (is_keyboard_master())
  162. render_status();
  163. else
  164. {
  165. render_logo();
  166. oled_scroll_left();
  167. }
  168. }