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.

188 lines
5.2 KiB

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