indicator.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * indicator.c
  3. *
  4. Copyright 2020 astro <yuleiz@gmail.com>
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  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. 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 "dp60.h"
  17. #include "rgblight.h"
  18. // caps led
  19. const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  20. {18, 1, HSV_RED}
  21. );
  22. // scroll led
  23. const rgblight_segment_t PROGMEM dp60_scrolllock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  24. {19, 1, HSV_GREEN}
  25. );
  26. // num led
  27. const rgblight_segment_t PROGMEM dp60_numlock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  28. {20, 1, HSV_BLUE}
  29. );
  30. // light 21 to 26 for layer 1-5
  31. const rgblight_segment_t PROGMEM dp60_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  32. {21, 1, HSV_PURPLE}
  33. );
  34. const rgblight_segment_t PROGMEM dp60_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  35. {22, 1, HSV_CYAN}
  36. );
  37. const rgblight_segment_t PROGMEM dp60_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  38. {23, 1, HSV_YELLOW}
  39. );
  40. const rgblight_segment_t PROGMEM dp60_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  41. {24, 1, HSV_PINK}
  42. );
  43. const rgblight_segment_t PROGMEM dp60_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  44. {25, 1, HSV_ORANGE}
  45. );
  46. // rgb light layers
  47. const rgblight_segment_t* const PROGMEM dp60_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  48. dp60_capslock_layer,
  49. dp60_scrolllock_layer,
  50. dp60_numlock_layer,
  51. dp60_layer1_layer,
  52. dp60_layer2_layer,
  53. dp60_layer3_layer,
  54. dp60_layer4_layer,
  55. dp60_layer5_layer
  56. );
  57. void keyboard_post_init_user(void) {
  58. // Enable the LED layers
  59. rgblight_layers = dp60_rgb_layers;
  60. }
  61. extern rgblight_config_t rgblight_config;
  62. extern void rgblight_layers_write(void);
  63. extern void indicator_write(LED_TYPE *start_led, uint8_t num_leds);
  64. void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds)
  65. {
  66. ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM);
  67. indicator_write(start_led + (RGBLED_NUM - RGB_INDICATOR_NUM), RGB_INDICATOR_NUM);
  68. }
  69. void led_update_ports(led_t led_state) {
  70. rgblight_set_layer_state(0, led_state.caps_lock);
  71. rgblight_set_layer_state(1, led_state.scroll_lock);
  72. rgblight_set_layer_state(2, led_state.num_lock);
  73. }
  74. layer_state_t layer_state_set_kb(layer_state_t state) {
  75. state = layer_state_set_user(state);
  76. rgblight_set_layer_state(3, layer_state_cmp(state, 1));
  77. rgblight_set_layer_state(4, layer_state_cmp(state, 2));
  78. rgblight_set_layer_state(5, layer_state_cmp(state, 3));
  79. rgblight_set_layer_state(6, layer_state_cmp(state, 4));
  80. rgblight_set_layer_state(7, layer_state_cmp(state, 5));
  81. return state;
  82. }