rgb.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef RGBLIGHT_ENABLE
  3. extern rgblight_config_t rgblight_config;
  4. rgblight_config_t RGB_current_config;
  5. #endif
  6. #ifdef RGB_MATRIX_ENABLE
  7. extern rgb_config_t rgb_matrix_config;
  8. rgb_config_t RGB_current_config;
  9. #endif
  10. void save_rgb_config(void) {
  11. #ifdef RGBLIGHT_ENABLE
  12. RGB_current_config.enable = rgblight_config.enable;
  13. RGB_current_config.mode = rgblight_get_mode();
  14. RGB_current_config.speed = rgblight_get_speed();
  15. RGB_current_config.hue = rgblight_get_hue();
  16. RGB_current_config.sat = rgblight_get_sat();
  17. RGB_current_config.val = rgblight_get_val();
  18. #elif RGB_MATRIX_ENABLE
  19. RGB_current_config.enable = rgb_matrix_config.enable;
  20. RGB_current_config.mode = rgb_matrix_get_mode();
  21. RGB_current_config.speed = rgb_matrix_config.speed;
  22. RGB_current_config.hsv = rgb_matrix_config.hsv;
  23. #endif
  24. }
  25. void restore_rgb_config(void) {
  26. #ifdef RGBLIGHT_ENABLE
  27. rgblight_set_speed_noeeprom(RGB_current_config.speed);
  28. if (rgblight_config.mode != RGB_current_config.mode) {
  29. rgblight_mode_noeeprom(RGB_current_config.mode);
  30. }
  31. if ((RGB_current_config.hue != rgblight_config.hue) || (RGB_current_config.sat != rgblight_config.sat) || (RGB_current_config.val != rgblight_config.val)) {
  32. rgblight_sethsv_noeeprom(RGB_current_config.hue, RGB_current_config.sat, RGB_current_config.val);
  33. }
  34. if (rgblight_config.enable) {
  35. rgblight_enable_noeeprom();
  36. } else {
  37. rgblight_disable_noeeprom();
  38. }
  39. #elif RGB_MATRIX_ENABLE
  40. rgb_matrix_config.speed = RGB_current_config.speed;
  41. if (rgb_matrix_config.mode != RGB_current_config.mode) {
  42. rgb_matrix_mode_noeeprom(RGB_current_config.mode);
  43. }
  44. if ((RGB_current_config.hsv.h != rgb_matrix_config.hsv.h) || (RGB_current_config.hsv.s != rgb_matrix_config.hsv.s) || (RGB_current_config.hsv.v != rgb_matrix_config.hsv.v)) {
  45. rgb_matrix_sethsv_noeeprom(RGB_current_config.hsv.h, RGB_current_config.hsv.s, RGB_current_config.hsv.v);
  46. }
  47. if (rgb_matrix_config.enable) {
  48. rgb_matrix_enable_noeeprom();
  49. } else {
  50. rgb_matrix_disable_noeeprom();
  51. }
  52. #endif
  53. }
  54. void rgb_by_layer(int layer) {
  55. #ifdef RGBLIGHT_ENABLE
  56. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  57. #elif RGB_MATRIX_ENABLE
  58. rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
  59. #endif
  60. switch (layer) {
  61. case _ADJUST:
  62. rgblight_sethsv_noeeprom(9, 255, 255);
  63. break;
  64. case _RAISE:
  65. rgblight_sethsv_noeeprom(HSV_CYAN);
  66. break;
  67. case _LOWER:
  68. rgblight_sethsv_noeeprom(HSV_MAGENTA);
  69. break;
  70. default:
  71. rgblight_sethsv_noeeprom(HSV_RED);
  72. }
  73. }