bb-underglow.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright 2021 Batuhan Başerdem
  2. * <baserdem.batuhan@gmail.com> @bbaserdem
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  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. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "bb-underglow.h"
  18. /* UNDERGLOW IMPLEMENTATION
  19. */
  20. // Define the layer switching code
  21. // An empty layer on the base
  22. const rgblight_segment_t PROGMEM bb_base_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  23. {0, 0, HSV_WHITE}
  24. );
  25. // Gaming layer is turquoise
  26. const rgblight_segment_t PROGMEM bb_game_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  27. {RGBLIGHT_LEFT_BEG, RGBLIGHT_LEFT_NUM, HSV_PURPLE}
  28. );
  29. // Character overlay is chartereuse
  30. const rgblight_segment_t PROGMEM bb_char_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  31. {0, RGBLED_NUM, HSV_GOLD}
  32. );
  33. // Right-hand layers
  34. // Media layer is orange
  35. const rgblight_segment_t PROGMEM bb_medi_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  36. {RGBLIGHT_RIGHT_BEG, RGBLIGHT_RIGHT_NUM, HSV_MAGENTA}
  37. );
  38. // Navigation layer is green
  39. const rgblight_segment_t PROGMEM bb_navi_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  40. {RGBLIGHT_RIGHT_BEG, RGBLIGHT_RIGHT_NUM, HSV_GREEN}
  41. );
  42. // Symbol layer is purple
  43. const rgblight_segment_t PROGMEM bb_symb_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  44. {RGBLIGHT_RIGHT_BEG, RGBLIGHT_RIGHT_NUM, HSV_YELLOW}
  45. );
  46. // Left-hand layers
  47. // Number layer is blue
  48. const rgblight_segment_t PROGMEM bb_numb_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  49. {RGBLIGHT_LEFT_BEG, RGBLIGHT_LEFT_NUM, HSV_BLUE}
  50. );
  51. // Function layer is red
  52. const rgblight_segment_t PROGMEM bb_func_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  53. {RGBLIGHT_LEFT_BEG, RGBLIGHT_LEFT_NUM, HSV_RED}
  54. );
  55. // Pointer layer is yellow
  56. const rgblight_segment_t PROGMEM bb_mous_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  57. {RGBLIGHT_LEFT_BEG, RGBLIGHT_LEFT_NUM, HSV_SPRINGGREEN}
  58. );
  59. // Music playback layer is magenta
  60. const rgblight_segment_t PROGMEM bb_musi_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  61. {0, RGBLED_NUM, HSV_ORANGE}
  62. );
  63. const rgblight_segment_t* const PROGMEM bb_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  64. bb_base_layer,
  65. bb_char_layer,
  66. bb_game_layer,
  67. bb_medi_layer,
  68. bb_navi_layer,
  69. bb_symb_layer,
  70. bb_numb_layer,
  71. bb_func_layer,
  72. bb_mous_layer,
  73. bb_musi_layer
  74. );
  75. // Enable the LED switching layers
  76. void keyboard_post_init_underglow(void) {
  77. rgblight_layers = bb_rgb_layers;
  78. // Default rgb mode is rainbow swirl; set this
  79. rgblight_sethsv_noeeprom(100, 255, 255);
  80. rgblight_mode_noeeprom(RGBLIGHT_MODE_RAINBOW_SWIRL + 0);
  81. }
  82. // Set RGBLIGHT state depending on layer
  83. layer_state_t layer_state_set_underglow(layer_state_t state) {
  84. // Activate layers if on that region
  85. rgblight_set_layer_state(_BASE, layer_state_cmp(state, _BASE));
  86. rgblight_set_layer_state(_GAME, layer_state_cmp(state, _GAME));
  87. rgblight_set_layer_state(_CHAR, layer_state_cmp(state, _CHAR));
  88. rgblight_set_layer_state(_MEDI, layer_state_cmp(state, _MEDI));
  89. rgblight_set_layer_state(_NAVI, layer_state_cmp(state, _NAVI));
  90. rgblight_set_layer_state(_SYMB, layer_state_cmp(state, _SYMB));
  91. rgblight_set_layer_state(_NUMB, layer_state_cmp(state, _NUMB));
  92. rgblight_set_layer_state(_FUNC, layer_state_cmp(state, _FUNC));
  93. rgblight_set_layer_state(_MOUS, layer_state_cmp(state, _MOUS));
  94. rgblight_set_layer_state(_MUSI, layer_state_cmp(state, _MUSI));
  95. // Return so other stuff can be done
  96. return state;
  97. }
  98. // Hook into shutdown code
  99. void shutdown_underglow(void) {
  100. // Make the LED's red on shutdown
  101. rgblight_enable_noeeprom();
  102. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  103. rgblight_sethsv(HSV_WHITE);
  104. }