You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.3 KiB

  1. /* Copyright 2020 Guillaume Gérard
  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 "underglow.h"
  17. void keyboard_post_init_rgb(void) {
  18. user_config_t user_config;
  19. user_config.raw = eeconfig_read_user();
  20. if (!user_config.rgb_layer_change) {
  21. return;
  22. }
  23. rgblight_enable_noeeprom();
  24. rgblight_sethsv_noeeprom_orange();
  25. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  26. }
  27. bool process_record_rgb(uint16_t keycode, keyrecord_t *record) {
  28. switch (keycode) {
  29. case RGB_LAYER:
  30. if (record->event.pressed) {
  31. user_config_t user_config;
  32. user_config.raw = eeconfig_read_user();
  33. user_config.rgb_layer_change ^= 1;
  34. eeconfig_update_user(user_config.raw);
  35. if (user_config.rgb_layer_change) {
  36. layer_state_set(layer_state);
  37. }
  38. }
  39. return false;
  40. case RGB_MODE_FORWARD ... RGB_MODE_RGBTEST:
  41. if (record->event.pressed) {
  42. user_config_t user_config;
  43. user_config.raw = eeconfig_read_user();
  44. if (user_config.rgb_layer_change) {
  45. user_config.rgb_layer_change = false;
  46. eeconfig_update_user(user_config.raw);
  47. }
  48. }
  49. return true;
  50. }
  51. return true;
  52. }
  53. layer_state_t layer_state_set_rgb(layer_state_t state) {
  54. user_config_t user_config;
  55. user_config.raw = eeconfig_read_user();
  56. if (!user_config.rgb_layer_change) {
  57. return state;
  58. }
  59. switch (get_highest_layer(state)) {
  60. case _QWERTY:
  61. #ifdef LAYERS_PROGRAMMER
  62. case _PROGRAMMER_SHIFTED:
  63. #endif
  64. rgblight_sethsv_noeeprom_orange();
  65. break;
  66. #ifdef LAYERS_ORTHO
  67. case _LOWER:
  68. rgblight_sethsv_noeeprom_red();
  69. break;
  70. case _RAISE:
  71. rgblight_sethsv_noeeprom_blue();
  72. break;
  73. case _ADJUST:
  74. rgblight_sethsv_noeeprom_purple();
  75. break;
  76. #endif
  77. #ifdef LAYER_FN
  78. case _FN:
  79. rgblight_sethsv_noeeprom_chartreuse();
  80. break;
  81. #endif
  82. #ifdef LAYER_GIT
  83. case _GIT:
  84. rgblight_sethsv_noeeprom_teal();
  85. break;
  86. #endif
  87. default:
  88. rgblight_sethsv_noeeprom_white();
  89. break;
  90. }
  91. return state;
  92. }
  93. bool led_update_rgb(led_t led_state) {
  94. user_config_t user_config;
  95. user_config.raw = eeconfig_read_user();
  96. if (!user_config.rgb_layer_change) {
  97. return true;
  98. }
  99. if (led_state.caps_lock) {
  100. rgblight_mode_noeeprom(RGBLIGHT_MODE_BREATHING + 3);
  101. } else {
  102. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  103. }
  104. return true;
  105. }