nz64.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright 2021 JasonRen(biu)
  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 "nz64.h"
  17. #ifdef RGB_MATRIX_ENABLE
  18. typedef union {
  19. uint32_t raw;
  20. uint8_t underground_rgb_sw :8;
  21. } kb_cums_t;
  22. kb_cums_t kb_cums;
  23. bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
  24. if (!rgb_matrix_indicators_advanced_user(led_min, led_max)) {
  25. return false;
  26. }
  27. if (rgb_matrix_is_enabled()) {
  28. if (kb_cums.underground_rgb_sw == 1) {
  29. for (uint8_t i = led_min; i < led_max; ++i) {
  30. if ((g_led_config.flags[i] == 4)) {
  31. rgb_matrix_set_color(i, 0, 0, 0);
  32. }
  33. }
  34. } else if (kb_cums.underground_rgb_sw == 2) {
  35. for (uint8_t i = led_min; i < led_max; ++i) {
  36. if ((g_led_config.flags[i] == 2)) {
  37. rgb_matrix_set_color(i, 0, 0, 0);
  38. }
  39. }
  40. }
  41. } else {
  42. rgb_matrix_set_color_all(0,0,0);
  43. }
  44. return true;
  45. }
  46. void eeconfig_init_kb(void) {
  47. kb_cums.raw = 0;
  48. eeconfig_update_kb(kb_cums.raw);
  49. eeconfig_init_user();
  50. }
  51. void keyboard_post_init_kb(void) {
  52. kb_cums.underground_rgb_sw = eeconfig_read_kb();
  53. keyboard_post_init_user();
  54. }
  55. #endif
  56. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  57. if (!process_record_user(keycode, record)) {
  58. return false;
  59. }
  60. switch(keycode) {
  61. #ifdef RGB_MATRIX_ENABLE
  62. case URGB_K:
  63. if (rgb_matrix_config.enable && record->event.pressed) {
  64. kb_cums.underground_rgb_sw += 1;
  65. kb_cums.underground_rgb_sw %= 3;
  66. }
  67. eeconfig_update_kb(kb_cums.raw);
  68. return false;
  69. #endif
  70. default:
  71. return true;
  72. }
  73. return true;
  74. }