custom_oled.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "custom_oled.h"
  2. #include "process_records.h"
  3. #include <stdio.h>
  4. #ifdef OLED_DRIVER_ENABLE
  5. #ifdef RGBLIGHT_ENABLE
  6. rgblight_config_t rgblight_config;
  7. #endif
  8. static void render_logo(void)
  9. {
  10. static const char PROGMEM font_logo[] = {
  11. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  12. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  13. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  14. oled_write_P(font_logo, false);
  15. }
  16. #if defined(OLED_90ROTATION)
  17. // TODO: Need to define this function / extern only for helix based split common keyboards
  18. extern uint8_t is_master;
  19. bool is_keyboard_master(void)
  20. {
  21. return is_master;
  22. }
  23. static void render_layer(uint8_t layer)
  24. {
  25. switch (layer)
  26. {
  27. case _QWERTY:
  28. oled_write_P(PSTR("DFLT "), false);
  29. break;
  30. #ifndef GAMELAYER_DISABLE
  31. case _GAME:
  32. oled_write_P(PSTR("GAME "), false);
  33. break;
  34. #endif
  35. case _LOWER:
  36. oled_write_P(PSTR("LOWER"), false);
  37. break;
  38. case _RAISE:
  39. oled_write_P(PSTR("RAISE"), false);
  40. break;
  41. #ifdef TRILAYER_ENABLED
  42. case _ADJUST:
  43. oled_write_P(PSTR("ADJST"), false);
  44. break;
  45. #endif
  46. }
  47. }
  48. static void render_status(void)
  49. {
  50. // Render to mode icon
  51. static const char PROGMEM mode_logo[2][4] = {
  52. {0x97,0x98,0x0a,0},
  53. {0xb7,0xb8,0x0a,0} };
  54. oled_write_P(mode_logo[0], false);
  55. oled_write_P(mode_logo[1], false);
  56. oled_write_P(PSTR("Layer"), false);
  57. uint8_t layer = biton(layer_state);
  58. if (layer != _QWERTY)
  59. render_layer(layer);
  60. else
  61. render_layer(biton32(default_layer_state));
  62. // Host Keyboard LED Status
  63. uint8_t led_usb_state = host_keyboard_leds();
  64. oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("-----NUMLK") : PSTR("----- "), false);
  65. oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false);
  66. oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false);
  67. #if defined(RGB_MATRIX_ENABLE)
  68. oled_set_cursor(0, oled_max_lines() - 7);
  69. oled_write_P(PSTR("-----"), false);
  70. static char buffer[26] = {0};
  71. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d\n", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode);
  72. oled_write(buffer, false);
  73. #elif defined(RGBLIGHT_ENABLE)
  74. oled_set_cursor(0, oled_max_lines() - 7);
  75. oled_write_P(PSTR("-----"), false);
  76. static char buffer[31] = {0};
  77. snprintf(buffer, sizeof(buffer), "h%3d s%3d v%3d s%3d m%3d\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val, rgblight_config.speed, rgblight_config.mode);
  78. oled_write(buffer, false);
  79. #endif
  80. }
  81. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  82. if (is_keyboard_master())
  83. return OLED_ROTATION_270;
  84. return OLED_ROTATION_180;
  85. }
  86. #else // OLED_90ROTATION
  87. static void render_layer(uint8_t layer)
  88. {
  89. switch (layer)
  90. {
  91. case _QWERTY:
  92. oled_write_P(PSTR("Default\n"), false);
  93. break;
  94. #ifndef GAMELAYER_DISABLE
  95. case _GAME:
  96. oled_write_P(PSTR("Game\n"), false);
  97. break;
  98. #endif
  99. case _LOWER:
  100. oled_write_P(PSTR("Lower\n"), false);
  101. break;
  102. case _RAISE:
  103. oled_write_P(PSTR("Raise\n"), false);
  104. break;
  105. #ifdef TRILAYER_ENABLED
  106. case _ADJUST:
  107. oled_write_P(PSTR("Adjust\n"), false);
  108. break;
  109. #endif
  110. }
  111. }
  112. static void render_status(void)
  113. {
  114. // Render to mode icon
  115. static const char PROGMEM mode_logo[2][3] = {
  116. {0x97,0x98,0},
  117. {0xb7,0xb8,0}
  118. };
  119. oled_write_P(mode_logo[0], false);
  120. #if defined(RGB_MATRIX_ENABLE)
  121. static char buffer[20] = {0};
  122. snprintf(buffer, sizeof(buffer), " h%3d s%3d v%3d\n", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
  123. oled_write(buffer, false);
  124. #elif defined(RGBLIGHT_ENABLE)
  125. static char buffer[20] = {0};
  126. snprintf(buffer, sizeof(buffer), " h%3d s%3d v%3d\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
  127. oled_write(buffer, false);
  128. #else
  129. oled_write_P(PSTR("\n"));
  130. #endif
  131. oled_write_P(mode_logo[1], false);
  132. #if defined(RGB_MATRIX_ENABLE)
  133. snprintf(buffer, sizeof(buffer), " s%3d m%3d\n", rgb_matrix_config.speed, rgb_matrix_config.mode);
  134. oled_write(buffer, false);
  135. #elif defined(RGBLIGHT_ENABLE)
  136. snprintf(buffer, sizeof(buffer), " s%3d m%3d\n", rgblight_config.speed, rgblight_config.mode);
  137. oled_write(buffer, false);
  138. #else
  139. oled_write_P(PSTR("\n"));
  140. #endif
  141. // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
  142. oled_write_P(PSTR("Layer: "), false);
  143. uint8_t layer = biton(layer_state);
  144. if (layer != _QWERTY)
  145. render_layer(layer);
  146. else
  147. render_layer(biton32(default_layer_state));
  148. // Host Keyboard LED Status
  149. uint8_t led_usb_state = host_keyboard_leds();
  150. oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false);
  151. oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPLCK ") : PSTR(" "), false);
  152. oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCRLCK ") : PSTR(" "), false);
  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. }
  165. #endif