logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

oled_display.c (4269B)


  1. /* Copyright 2020 yushakobo
  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 <stdio.h>
  17. #include <string.h>
  18. #include QMK_KEYBOARD_H
  19. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  20. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  21. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  22. // entirely and just use numbers.
  23. enum layer_number {
  24. _QWERTY = 0,
  25. _COLEMAK,
  26. _DVORAK,
  27. _LOWER,
  28. _RAISE,
  29. _ADJUST
  30. };
  31. //assign the right code to your layers for OLED display
  32. #define L_BASE 0
  33. #define L_LOWER (1<<_LOWER)
  34. #define L_RAISE (1<<_RAISE)
  35. #define L_ADJUST (1<<_ADJUST)
  36. #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
  37. //OLED update loop
  38. #ifdef OLED_ENABLE
  39. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  40. if (is_keyboard_master()) {
  41. return OLED_ROTATION_0;
  42. } else {
  43. return OLED_ROTATION_180;
  44. }
  45. }
  46. static void render_rgbled_status(bool full) {
  47. # ifdef RGBLIGHT_ENABLE
  48. char buf[30];
  49. if (RGBLIGHT_MODES > 1 && rgblight_is_enabled()) {
  50. if (full) {
  51. snprintf(buf, sizeof(buf), " LED %2d: %d,%d,%d ",
  52. rgblight_get_mode(),
  53. rgblight_get_hue()/RGBLIGHT_HUE_STEP,
  54. rgblight_get_sat()/RGBLIGHT_SAT_STEP,
  55. rgblight_get_val()/RGBLIGHT_VAL_STEP);
  56. } else {
  57. snprintf(buf, sizeof(buf), "[%2d] ", rgblight_get_mode());
  58. }
  59. oled_write(buf, false);
  60. }
  61. # endif
  62. }
  63. static void render_layer_status(void) {
  64. // 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
  65. char buf[10];
  66. oled_write_P(PSTR("Layer: "), false);
  67. switch (layer_state) {
  68. case L_BASE:
  69. oled_write_P(PSTR("Default"), false);
  70. break;
  71. case L_RAISE:
  72. oled_write_P(PSTR("Raise"), false);
  73. break;
  74. case L_LOWER:
  75. oled_write_P(PSTR("Lower"), false);
  76. break;
  77. case L_ADJUST:
  78. case L_ADJUST_TRI:
  79. oled_write_P(PSTR("Adjust"), false);
  80. break;
  81. default:
  82. oled_write_P(PSTR("Undef-"), false);
  83. snprintf(buf,sizeof(buf), "%u", layer_state);
  84. oled_write(buf, false);
  85. }
  86. oled_write_P(PSTR("\n"), false);
  87. }
  88. void render_status(void) {
  89. // Render to mode icon
  90. static const char os_logo[][2][3] PROGMEM = {{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
  91. if (is_mac_mode()) {
  92. oled_write_P(os_logo[0][0], false);
  93. oled_write_P(PSTR("\n"), false);
  94. oled_write_P(os_logo[0][1], false);
  95. } else {
  96. oled_write_P(os_logo[1][0], false);
  97. oled_write_P(PSTR("\n"), false);
  98. oled_write_P(os_logo[1][1], false);
  99. }
  100. oled_write_P(PSTR(" "), false);
  101. render_layer_status();
  102. // Host Keyboard LED Status
  103. led_t led_state = host_keyboard_led_state();
  104. oled_write_P(led_state.num_lock ? PSTR("NUMLOCK") : PSTR(" "), false);
  105. oled_write_P(led_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);
  106. oled_write_P(led_state.scroll_lock ? PSTR("SCLK") : PSTR(" "), false);
  107. oled_advance_page(true);
  108. render_rgbled_status(true);
  109. oled_write_P(PSTR("\n"), false);
  110. }
  111. bool oled_task_user(void) {
  112. # if DEBUG_TO_SCREEN
  113. if (debug_enable) {
  114. return;
  115. }
  116. # endif
  117. if (is_keyboard_master()) {
  118. render_status();
  119. } else {
  120. render_helix_logo();
  121. render_rgbled_status(false);
  122. render_layer_status();
  123. }
  124. return false;
  125. }
  126. #endif // end of OLED_ENABLE