zima.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright 2019 Thomas Baart
  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 "zima.h"
  17. #include <stdio.h>
  18. #ifdef HAPTIC_ENABLE
  19. # include "haptic.h"
  20. extern haptic_config_t haptic_config;
  21. #endif
  22. #ifdef OLED_ENABLE
  23. static bool is_asleep = false;
  24. static uint32_t oled_timer;
  25. void suspend_power_down_kb(void) {
  26. is_asleep = true;
  27. suspend_power_down_user();
  28. }
  29. void suspend_wakeup_init_kb(void) {
  30. is_asleep = false;
  31. suspend_wakeup_init_user();
  32. }
  33. __attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_180; }
  34. __attribute__((weak)) void oled_task_user(void) {
  35. if (is_asleep) {
  36. oled_off();
  37. return;
  38. }
  39. if (timer_elapsed32(oled_timer) < 30000) {
  40. oled_on();
  41. oled_scroll_off();
  42. oled_write_P(PSTR("SplitKB's Zima"), false);
  43. char layer[2] = {0};
  44. snprintf(layer, sizeof(layer), "%d", get_highest_layer(layer_state));
  45. oled_write_P(PSTR(" L:"), false);
  46. oled_write_ln(layer, false);
  47. oled_write_ln_P(PSTR("--------------"), false);
  48. if (rgblight_is_enabled()) {
  49. oled_write_P(PSTR("HSV: "), false);
  50. char rgbs[14];
  51. snprintf(rgbs, sizeof(rgbs), "%3d, %3d, %3d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
  52. oled_write_ln(rgbs, false);
  53. } else {
  54. oled_write_ln_P(PSTR("RGB LIGHT DISABLED"), false);
  55. }
  56. # ifdef AUDIO_ENABLE
  57. oled_write_P(PSTR("Audio:"), false);
  58. is_audio_on() ? oled_write_P(PSTR(" on"), false) : oled_write_P(PSTR("off"), false);
  59. # ifdef AUDIO_CLICKY
  60. oled_write_P(PSTR(" Clicky:"), false);
  61. (is_clicky_on() && is_audio_on()) ? oled_write_P(PSTR(" on"), false) : oled_write_P(PSTR("off"), false);
  62. # endif
  63. # endif
  64. } else {
  65. if (timer_elapsed32(oled_timer) < 120000) {
  66. oled_on();
  67. // clang-format off
  68. static const char PROGMEM qmk_logo[] = {
  69. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  70. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  71. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  72. // clang-format on
  73. oled_write_ln_P(qmk_logo, false);
  74. oled_scroll_right();
  75. } else {
  76. oled_off();
  77. }
  78. }
  79. }
  80. bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
  81. oled_timer = timer_read32();
  82. return process_record_user(keycode, record);
  83. }
  84. #endif
  85. #ifdef ENCODER_ENABLE
  86. bool encoder_update_kb(uint8_t index, bool clockwise) {
  87. # ifdef OLED_ENABLE
  88. oled_timer = timer_read32();
  89. # endif
  90. # if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
  91. if (is_audio_on() && is_clicky_on()) clicky_play();
  92. # endif
  93. # ifdef HAPTIC_ENABLE
  94. if (haptic_config.enable) haptic_play();
  95. # endif
  96. if (!encoder_update_user(index, clockwise)) return false;
  97. if (clockwise) {
  98. tap_code16(KC_VOLU);
  99. } else {
  100. tap_code16(KC_VOLD);
  101. }
  102. return true;
  103. }
  104. #endif