logo

qmk_firmware

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

c3_pro.c (3715B)


  1. /* Copyright 2024 @ 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 "c3_pro.h"
  17. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  18. if (!process_record_user(keycode, record)) {
  19. return false;
  20. }
  21. switch (keycode) {
  22. #ifdef RGB_MATRIX_ENABLE
  23. case QK_RGB_MATRIX_TOGGLE:
  24. if (record->event.pressed) {
  25. switch (rgb_matrix_get_flags()) {
  26. case LED_FLAG_ALL: {
  27. rgb_matrix_set_flags(LED_FLAG_NONE);
  28. rgb_matrix_set_color_all(0, 0, 0);
  29. } break;
  30. default: {
  31. rgb_matrix_set_flags(LED_FLAG_ALL);
  32. } break;
  33. }
  34. }
  35. if (!rgb_matrix_is_enabled()) {
  36. rgb_matrix_set_flags(LED_FLAG_ALL);
  37. rgb_matrix_enable();
  38. }
  39. return false;
  40. #endif
  41. #ifdef LED_MATRIX_ENABLE
  42. case QK_LED_MATRIX_TOGGLE:
  43. if (record->event.pressed) {
  44. switch (led_matrix_get_flags()) {
  45. case LED_FLAG_ALL: {
  46. led_matrix_set_flags(LED_FLAG_NONE);
  47. led_matrix_set_value_all(0);
  48. } break;
  49. default: {
  50. led_matrix_set_flags(LED_FLAG_ALL);
  51. } break;
  52. }
  53. }
  54. if (!led_matrix_is_enabled()) {
  55. led_matrix_set_flags(LED_FLAG_ALL);
  56. led_matrix_enable();
  57. }
  58. return false;
  59. #endif
  60. case KC_OSSW:
  61. if (record->event.pressed) {
  62. default_layer_xor(1U << 0);
  63. default_layer_xor(1U << 2);
  64. eeconfig_update_default_layer(default_layer_state);
  65. }
  66. return false;
  67. default:
  68. return true;
  69. }
  70. }
  71. #if defined(RGB_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX)
  72. bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
  73. if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
  74. return false;
  75. }
  76. // RGB_MATRIX_INDICATOR_SET_COLOR(index, red, green, blue);
  77. if (host_keyboard_led_state().caps_lock) {
  78. RGB_MATRIX_INDICATOR_SET_COLOR(CAPS_LOCK_LED_INDEX, 255, 255, 255);
  79. } else {
  80. if (!rgb_matrix_get_flags()) {
  81. RGB_MATRIX_INDICATOR_SET_COLOR(CAPS_LOCK_LED_INDEX, 0, 0, 0);
  82. }
  83. }
  84. return true;
  85. }
  86. #endif // RGB_MATRIX_ENABLE && CAPS_LOCK_LED_INDEX
  87. #if defined(LED_MATRIX_ENABLE) && defined(CAPS_LOCK_LED_INDEX)
  88. bool led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
  89. if (!led_matrix_indicators_advanced_user(led_min, led_max)) {
  90. return false;
  91. }
  92. if (host_keyboard_led_state().caps_lock) {
  93. led_matrix_set_value(CAPS_LOCK_LED_INDEX, 255);
  94. } else {
  95. if (!led_matrix_get_flags()) {
  96. led_matrix_set_value(CAPS_LOCK_LED_INDEX, 0);
  97. }
  98. }
  99. return true;
  100. }
  101. #endif // LED_MATRIX_ENABLE && CAPS_LOCK_LED_INDEX