logo

qmk_firmware

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

keychron_common.c (3444B)


  1. /* Copyright 2022 @ Keychron (https://www.keychron.com)
  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 "keychron_common.h"
  17. #include "sync_timer.h"
  18. bool is_siri_active = false;
  19. uint32_t siri_timer = 0;
  20. key_combination_t key_comb_list[4] = {
  21. {2, {KC_LWIN, KC_TAB}},
  22. {2, {KC_LWIN, KC_E}},
  23. {3, {KC_LSFT, KC_LCMD, KC_4}},
  24. {2, {KC_LWIN, KC_C}}
  25. };
  26. static uint8_t mac_keycode[4] = { KC_LOPT, KC_ROPT, KC_LCMD, KC_RCMD };
  27. void housekeeping_task_keychron(void) {
  28. if (is_siri_active) {
  29. if (sync_timer_elapsed32(siri_timer) >= 500) {
  30. unregister_code(KC_LCMD);
  31. unregister_code(KC_SPACE);
  32. is_siri_active = false;
  33. }
  34. }
  35. }
  36. bool process_record_keychron(uint16_t keycode, keyrecord_t *record) {
  37. switch (keycode) {
  38. case QK_KB_0:
  39. if (record->event.pressed) {
  40. register_code(KC_MISSION_CONTROL);
  41. } else {
  42. unregister_code(KC_MISSION_CONTROL);
  43. }
  44. return false; // Skip all further processing of this key
  45. case QK_KB_1:
  46. if (record->event.pressed) {
  47. register_code(KC_LAUNCHPAD);
  48. } else {
  49. unregister_code(KC_LAUNCHPAD);
  50. }
  51. return false; // Skip all further processing of this key
  52. case KC_LOPTN:
  53. case KC_ROPTN:
  54. case KC_LCMMD:
  55. case KC_RCMMD:
  56. if (record->event.pressed) {
  57. register_code(mac_keycode[keycode - KC_LOPTN]);
  58. } else {
  59. unregister_code(mac_keycode[keycode - KC_LOPTN]);
  60. }
  61. return false; // Skip all further processing of this key
  62. case KC_SIRI:
  63. if (record->event.pressed) {
  64. if (!is_siri_active) {
  65. is_siri_active = true;
  66. register_code(KC_LCMD);
  67. register_code(KC_SPACE);
  68. }
  69. siri_timer = sync_timer_read32();
  70. } else {
  71. // Do something else when release
  72. }
  73. return false; // Skip all further processing of this key
  74. case KC_TASK:
  75. case KC_FLXP:
  76. case KC_SNAP:
  77. case KC_CRTA:
  78. if (record->event.pressed) {
  79. for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
  80. register_code(key_comb_list[keycode - KC_TASK].keycode[i]);
  81. }
  82. } else {
  83. for (uint8_t i = 0; i < key_comb_list[keycode - KC_TASK].len; i++) {
  84. unregister_code(key_comb_list[keycode - KC_TASK].keycode[i]);
  85. }
  86. }
  87. return false; // Skip all further processing of this key
  88. default:
  89. return true; // Process all other keycodes normally
  90. }
  91. }