indicator.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_list.h"
  18. #include "rgblight.h"
  19. // caps led
  20. const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  21. {18, 1, HSV_RED}
  22. );
  23. // scroll led
  24. const rgblight_segment_t PROGMEM dp60_scrolllock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  25. {19, 1, HSV_GREEN}
  26. );
  27. // num led
  28. const rgblight_segment_t PROGMEM dp60_numlock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  29. {20, 1, HSV_BLUE}
  30. );
  31. // light 21 to 26 for layer 1-5
  32. const rgblight_segment_t PROGMEM dp60_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  33. {21, 1, HSV_PURPLE}
  34. );
  35. const rgblight_segment_t PROGMEM dp60_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  36. {22, 1, HSV_CYAN}
  37. );
  38. const rgblight_segment_t PROGMEM dp60_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  39. {23, 1, HSV_YELLOW}
  40. );
  41. const rgblight_segment_t PROGMEM dp60_layer4_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  42. {24, 1, HSV_PINK}
  43. );
  44. const rgblight_segment_t PROGMEM dp60_layer5_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  45. {25, 1, HSV_ORANGE}
  46. );
  47. // rgb light layers
  48. const rgblight_segment_t* const PROGMEM dp60_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  49. dp60_capslock_layer,
  50. dp60_scrolllock_layer,
  51. dp60_numlock_layer,
  52. dp60_layer1_layer,
  53. dp60_layer2_layer,
  54. dp60_layer3_layer,
  55. dp60_layer4_layer,
  56. dp60_layer5_layer
  57. );
  58. void keyboard_post_init_user(void) {
  59. // Enable the LED layers
  60. rgblight_layers = dp60_rgb_layers;
  61. }
  62. extern rgblight_config_t rgblight_config;
  63. extern void rgblight_layers_write(void);
  64. extern void indicator_write(LED_TYPE *start_led, uint8_t num_leds);
  65. void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds)
  66. {
  67. ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM);
  68. indicator_write(start_led + (RGBLED_NUM - RGB_INDICATOR_NUM), RGB_INDICATOR_NUM);
  69. }
  70. bool led_update_kb(led_t led_state) {
  71. bool res = led_update_user(led_state);
  72. if (res) {
  73. rgblight_set_layer_state(0, led_state.caps_lock);
  74. rgblight_set_layer_state(1, led_state.scroll_lock);
  75. rgblight_set_layer_state(2, led_state.num_lock);
  76. }
  77. return res;
  78. }
  79. layer_state_t layer_state_set_kb(layer_state_t state) {
  80. state = layer_state_set_user(state);
  81. rgblight_set_layer_state(3, layer_state_cmp(state, 1));
  82. rgblight_set_layer_state(4, layer_state_cmp(state, 2));
  83. rgblight_set_layer_state(5, layer_state_cmp(state, 3));
  84. rgblight_set_layer_state(6, layer_state_cmp(state, 4));
  85. rgblight_set_layer_state(7, layer_state_cmp(state, 5));
  86. return state;
  87. }