solid_reactive_anim.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED)
  3. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
  4. extern rgb_config_t rgb_matrix_config;
  5. extern last_hit_t g_last_hit_tracker;
  6. bool rgb_matrix_solid_reactive(effect_params_t* params) {
  7. RGB_MATRIX_USE_LIMITS(led_min, led_max);
  8. HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val };
  9. // Max tick based on speed scale ensures results from scale16by8 with rgb_matrix_config.speed are no greater than 255
  10. uint16_t max_tick = 65535 / rgb_matrix_config.speed;
  11. // Relies on hue being 8-bit and wrapping
  12. for (uint8_t i = led_min; i < led_max; i++) {
  13. RGB_MATRIX_TEST_LED_FLAGS();
  14. uint16_t tick = max_tick;
  15. for(uint8_t j = 0; j < g_last_hit_tracker.count; j++) {
  16. if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
  17. tick = g_last_hit_tracker.tick[j];
  18. break;
  19. }
  20. }
  21. uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
  22. hsv.h = rgb_matrix_config.hue + qsub8(130, offset);
  23. RGB rgb = hsv_to_rgb(hsv);
  24. rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
  25. }
  26. return led_max < DRIVER_LED_TOTAL;
  27. }
  28. #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
  29. #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED)