keymap.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Copyright 2019 Thomas Baart
  2. * Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  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 QMK_KEYBOARD_H
  18. #include <stdio.h>
  19. #ifdef HAPTIC_ENABLE
  20. # include "haptic.h"
  21. extern haptic_config_t haptic_config;
  22. #endif
  23. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  24. [0] = LAYOUT_ortho_4x3( /* Base */
  25. KC_MUTE, TG(1), TG(2),
  26. KC_P7, KC_P8, KC_P9,
  27. KC_P4, KC_P5, KC_P6,
  28. KC_P1, KC_P2, KC_P3
  29. ),
  30. [1] = LAYOUT_ortho_4x3( /* Layer 1 */
  31. RESET, _______, XXXXXXX,
  32. AU_ON, AU_OFF, XXXXXXX,
  33. CK_TOGG, XXXXXXX, CK_UP,
  34. CK_RST, XXXXXXX, CK_DOWN
  35. ),
  36. [2] = LAYOUT_ortho_4x3( /* Layer 2*/
  37. RGB_TOG, RGB_MOD, _______,
  38. RGB_HUI, RGB_SAI, RGB_VAI,
  39. RGB_HUD, RGB_SAD, RGB_VAD,
  40. HPT_TOG, HPT_FBK, HPT_CONT
  41. )
  42. };
  43. static bool is_asleep = false;
  44. static uint32_t oled_timer;
  45. void render_oled_logo(void) {
  46. // clang-format off
  47. static const char PROGMEM qmk_logo[] = {
  48. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  49. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  50. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  51. // clang-format on
  52. oled_write_ln_P(qmk_logo, false);
  53. }
  54. void render_user_status(void) {
  55. static const char PROGMEM audio_status[2][3] = {{0xE0, 0xE1, 0}, {0xE2, 0xE3, 0}};
  56. oled_write_P(audio_status[is_audio_on()], false);
  57. static const char PROGMEM audio_clicky_status[2][3] = {{0xF4, 0xF5, 0}, {0xF6, 0xF7, 0}};
  58. oled_write_P(audio_clicky_status[is_clicky_on() && is_audio_on()], false);
  59. static const char PROGMEM rgb_layer_status[2][3] = {{0xEE, 0xEF, 0}, {0xF0, 0xF1, 0}};
  60. oled_write_P(rgb_layer_status[rgblight_is_enabled()], false);
  61. static const char PROGMEM nukem_good[2][3] = {{0xF8, 0xF9, 0}, {0xF6, 0xF7, 0}};
  62. oled_write_P(nukem_good[0], haptic_config.enable);
  63. }
  64. void keyboard_post_init_user(void) {
  65. oled_scroll_set_speed(0);
  66. }
  67. void oled_task_user(void) {
  68. if (is_asleep) {
  69. oled_off();
  70. return;
  71. }
  72. if (timer_elapsed32(oled_timer) < 30000) {
  73. oled_on();
  74. oled_scroll_off();
  75. oled_write_P(PSTR("SplitKB's Zima"), false);
  76. char layer[2] = {0};
  77. snprintf(layer, sizeof(layer), "%d", get_highest_layer(layer_state));
  78. oled_write_P(PSTR(" L:"), false);
  79. oled_write_ln(layer, false);
  80. oled_write_ln_P(PSTR("--------------"), false);
  81. if (rgblight_is_enabled()) {
  82. oled_write_P(PSTR("HSV: "), false);
  83. char rgbs[14];
  84. snprintf(rgbs, sizeof(rgbs), "%3d, %3d, %3d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
  85. oled_write_ln(rgbs, false);
  86. } else {
  87. oled_write_ln_P(PSTR("RGB LIGHT DISABLED"), false);
  88. }
  89. render_user_status();
  90. } else {
  91. if (timer_elapsed32(oled_timer) < 120000) {
  92. oled_on();
  93. render_oled_logo();
  94. oled_scroll_right();
  95. } else {
  96. oled_off();
  97. }
  98. }
  99. }
  100. void suspend_power_down_user(void) {
  101. is_asleep = true;
  102. }
  103. void suspend_wakeup_init_user(void) {
  104. is_asleep = false;
  105. }
  106. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  107. oled_timer = timer_read32();
  108. return true;
  109. }
  110. bool encoder_update_user(uint8_t index, bool clockwise) {
  111. if (clockwise) {
  112. tap_code16(KC_VOLU);
  113. } else {
  114. tap_code16(KC_VOLD);
  115. }
  116. return true;
  117. }