effect_runner_reactive.h 984 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  3. typedef uint8_t (*reactive_f)(uint8_t val, uint16_t offset);
  4. bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
  5. LED_MATRIX_USE_LIMITS(led_min, led_max);
  6. uint16_t max_tick = 65535 / led_matrix_eeconfig.speed;
  7. for (uint8_t i = led_min; i < led_max; i++) {
  8. LED_MATRIX_TEST_LED_FLAGS();
  9. uint16_t tick = max_tick;
  10. // Reverse search to find most recent key hit
  11. for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) {
  12. if (g_last_hit_tracker.index[j] == i && g_last_hit_tracker.tick[j] < tick) {
  13. tick = g_last_hit_tracker.tick[j];
  14. break;
  15. }
  16. }
  17. uint16_t offset = scale16by8(tick, led_matrix_eeconfig.speed);
  18. led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset));
  19. }
  20. return led_matrix_check_finished_leds(led_max);
  21. }
  22. #endif // LED_MATRIX_KEYREACTIVE_ENABLED