rgblayers.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Copyright 2020 Stephen J. Bush
  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. #ifdef RGBLIGHT_ENABLE
  17. # include QMK_KEYBOARD_H
  18. # include "rgblayers.h"
  19. static rgblight_config_t home_rgb;
  20. __attribute__((weak)) void set_layer_hsv(layer_state_t state, HSV* offset) {}
  21. /* Placeholder function
  22. * If defined in a keymap.c, this will be ignored.
  23. */
  24. __attribute__((weak)) void post_process_record_keymap(uint16_t keycode, keyrecord_t* record) { return; }
  25. void post_process_record_user(uint16_t keycode, keyrecord_t* record) {
  26. // Regular user keycode case statement
  27. switch (keycode) {
  28. # ifdef RGBLIGHT_ENABLE
  29. case RGB_HUD:
  30. case RGB_HUI:
  31. case RGB_SAD:
  32. case RGB_SAI:
  33. case RGB_VAD:
  34. case RGB_VAI:
  35. set_rgb_home();
  36. break;
  37. # endif
  38. default:
  39. break;
  40. }
  41. }
  42. void set_rgb_home(void) {
  43. home_rgb.raw = eeconfig_read_rgblight();
  44. // these get the current -- not eeprom
  45. // home_rgb.hue = rgblight_get_hue();
  46. // home_rgb.sat = rgblight_get_sat();
  47. // home_rgb.val = rgblight_get_val();
  48. }
  49. void set_rgb_by_layer(layer_state_t state) {
  50. if (!rgblight_is_enabled()) {
  51. return; // lighting not enabled
  52. }
  53. HSV layer_color = {home_rgb.hue, home_rgb.sat, home_rgb.val};
  54. set_layer_hsv(state, &layer_color);
  55. rgblight_sethsv_noeeprom( //
  56. layer_color.h, // all 3 MUST be btwn 0 and 255
  57. layer_color.s, //
  58. layer_color.v //
  59. );
  60. }
  61. #endif