qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

starlight_anim.h (1364B)


      1 #ifdef ENABLE_RGB_MATRIX_STARLIGHT
      2 RGB_MATRIX_EFFECT(STARLIGHT)
      3 #    ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
      4 
      5 static void set_starlight_color(uint8_t i, effect_params_t* params) {
      6     if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return;
      7 
      8     uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8);
      9     hsv_t    hsv  = rgb_matrix_config.hsv;
     10     hsv.v         = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
     11     rgb_t rgb     = rgb_matrix_hsv_to_rgb(hsv);
     12     rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
     13 }
     14 
     15 bool STARLIGHT(effect_params_t* params) {
     16     static uint16_t index = RGB_MATRIX_LED_COUNT + 1;
     17 
     18     // Periodic trigger for LED change
     19     if ((params->iter == 0) && (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 5)) % 5 == 0)) {
     20         index = random8_max(RGB_MATRIX_LED_COUNT);
     21     }
     22 
     23     RGB_MATRIX_USE_LIMITS(led_min, led_max);
     24     if (params->init) {
     25         for (uint8_t i = led_min; i < led_max; i++) {
     26             set_starlight_color(i, params);
     27         }
     28     }
     29     // Change LED once and set index out of range till next trigger
     30     else if (led_min <= index && index < led_max) {
     31         set_starlight_color(index, params);
     32         index = RGB_MATRIX_LED_COUNT + 1;
     33     }
     34     return rgb_matrix_check_finished_leds(led_max);
     35 }
     36 
     37 #    endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS
     38 #endif     // ENABLE_RGB_MATRIX_STARLIGHT