snap.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright 2021 Jay Greco
  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 "snap.h"
  17. // Macro variables
  18. bool is_alt_tab_active = false;
  19. uint16_t alt_tab_timer = 0;
  20. bool muted = false;
  21. void matrix_init_kb(void) {
  22. set_bitc_LED(LED_OFF);
  23. matrix_init_remote_kb();
  24. matrix_init_user();
  25. }
  26. void keyboard_post_init_kb(void) {
  27. #ifdef CONSOLE_ENABLE
  28. debug_enable = true;
  29. debug_matrix = true;
  30. #endif
  31. keyboard_post_init_user();
  32. }
  33. void matrix_scan_kb(void) {
  34. matrix_scan_remote_kb();
  35. matrix_scan_user();
  36. if (is_alt_tab_active) {
  37. if (timer_elapsed(alt_tab_timer) > 1000) {
  38. unregister_code(KC_LALT);
  39. is_alt_tab_active = false;
  40. }
  41. }
  42. }
  43. // Use Bit-C LED to show CAPS LOCK and NUM LOCK status
  44. void led_update_ports(led_t led_state) {
  45. set_bitc_LED(led_state.caps_lock ? LED_DIM : LED_OFF);
  46. }
  47. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  48. // If console is enabled, it will print the matrix position and status of each key pressed
  49. #ifdef CONSOLE_ENABLE
  50. dprintf("kc: 0x%04X, col: %u, row: %u, pressed: %b, time: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time);
  51. #endif
  52. process_record_remote_kb(keycode, record);
  53. if (!process_record_user(keycode, record)) return false;
  54. switch (keycode) {
  55. case QK_BOOT:
  56. if (record->event.pressed) {
  57. set_bitc_LED(LED_DIM);
  58. #ifdef RGBLIGHT_ENABLE
  59. rgblight_disable_noeeprom();
  60. #endif
  61. #ifdef OLED_ENABLE
  62. oled_off();
  63. #endif
  64. bootloader_jump(); // jump to bootloader
  65. }
  66. return false;
  67. case DISC_MUTE:
  68. if (record->event.pressed) {
  69. tap_code(KC_F23);
  70. #ifdef RGBLIGHT_ENABLE
  71. if (!rgblight_is_enabled()) break;
  72. if (muted) {
  73. rgblight_enable_noeeprom();
  74. } else {
  75. rgblight_timer_disable();
  76. uint8_t val = rgblight_get_val();
  77. rgblight_sethsv_range(255, 255, val, 1, 5);
  78. }
  79. #endif
  80. muted = !muted;
  81. }
  82. break;
  83. case SUPER_ALT_TAB:
  84. if (record->event.pressed) {
  85. if (!is_alt_tab_active) {
  86. is_alt_tab_active = true;
  87. register_code(KC_LALT);
  88. }
  89. alt_tab_timer = timer_read();
  90. register_code(KC_TAB);
  91. } else {
  92. unregister_code(KC_TAB);
  93. }
  94. break;
  95. default:
  96. break;
  97. }
  98. return true;
  99. }