leeloo.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright 2022 Clickety Split Ltd.
  2. * https://clicketysplit.ca
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "leeloo.h"
  18. #ifdef OLED_ENABLE
  19. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  20. if (!is_keyboard_master()) {
  21. return OLED_ROTATION_180;
  22. } else {
  23. return rotation;
  24. }
  25. }
  26. static void render_keylock_status(led_t led_state) {
  27. oled_write_P(PSTR("Lock: "), false);
  28. oled_write_P(PSTR("CAPS"), led_state.caps_lock);
  29. oled_write_P(PSTR(" "), false);
  30. oled_write_P(PSTR("NUML"), led_state.num_lock);
  31. oled_write_P(PSTR(" "), false);
  32. oled_write_ln_P(PSTR("SCLK"), led_state.scroll_lock);
  33. }
  34. static void render_mod_status(uint8_t modifiers) {
  35. oled_write_P(PSTR("Mods: "), false);
  36. oled_write_P(PSTR("Sft"), (modifiers & MOD_MASK_SHIFT));
  37. oled_write_P(PSTR(" "), false);
  38. oled_write_P(PSTR("Ctl"), (modifiers & MOD_MASK_CTRL));
  39. oled_write_P(PSTR(" "), false);
  40. oled_write_P(PSTR("Alt"), (modifiers & MOD_MASK_ALT));
  41. oled_write_P(PSTR(" "), false);
  42. oled_write_P(PSTR("GUI"), (modifiers & MOD_MASK_GUI));
  43. }
  44. static void render_secondary_oled(void) {
  45. // Version Information
  46. oled_write_P(PSTR("Leeloo\n\n"), false);
  47. oled_write_P(PSTR("Firmware: "), false);
  48. oled_write_P(PSTR("v1.0"), false);
  49. oled_write_P(PSTR("\n"), false);
  50. oled_write_P(PSTR("Clickety Split Ltd."), false);
  51. }
  52. static void render_status(void) {
  53. // Host Keyboard Layer Status
  54. switch (get_highest_layer(default_layer_state)) {
  55. case _BASE:
  56. oled_write_P(PSTR("QWERTY | "), false);
  57. break;
  58. }
  59. // Host Keyboard Layer Status
  60. switch (get_highest_layer(layer_state)) {
  61. case 0:
  62. oled_write_P(PSTR("Base \n"), false);
  63. break;
  64. case _LOWER:
  65. oled_write_P(PSTR("Lower \n"), false);
  66. break;
  67. case _RAISE:
  68. oled_write_P(PSTR("Raise \n"), false);
  69. break;
  70. case _ADJUST:
  71. oled_write_P(PSTR("Adjust \n"), false);
  72. break;
  73. default:
  74. oled_write_P(PSTR("Unknown \n"), false);
  75. }
  76. oled_write_P(PSTR("\n"), false);
  77. render_keylock_status(host_keyboard_led_state());
  78. render_mod_status(get_mods() | get_oneshot_mods());
  79. }
  80. bool oled_task_kb(void) {
  81. if (!oled_task_user()) {
  82. return false;
  83. }
  84. if (is_keyboard_master()) {
  85. // Renders the current keyboard state (layer, lock, caps, scroll, etc)
  86. render_status();
  87. } else {
  88. // Version Information
  89. render_secondary_oled();
  90. }
  91. return false;
  92. }
  93. #endif // OLED_ENABLE
  94. #ifdef ENCODER_ENABLE
  95. bool encoder_update_kb(uint8_t index, bool clockwise) {
  96. if (!encoder_update_user(index, clockwise)) { return false; }
  97. if (index == 0) {
  98. // Volume control
  99. if (clockwise) {
  100. tap_code_delay(KC_VOLD, 10);
  101. } else {
  102. tap_code_delay(KC_VOLU, 10);
  103. }
  104. } else if (index == 1) {
  105. // Page up/Page down
  106. if (clockwise) {
  107. tap_code(KC_PGDN);
  108. } else {
  109. tap_code(KC_PGUP);
  110. }
  111. }
  112. return true;
  113. }
  114. #endif