- #ifdef TRACK_PREVIOUS_EFFECT
- static uint8_t toggle_enable_last = 255;
- #endif
- if (!rgb_matrix_config.enable) {
- rgb_matrix_all_off();
- rgb_matrix_indicators();
- #ifdef TRACK_PREVIOUS_EFFECT
- toggle_enable_last = rgb_matrix_config.enable;
- #endif
- return;
- }
- // delay 1 second before driving LEDs or doing anything else
- static uint8_t startup_tick = 0;
- if ( startup_tick < 20 ) {
- startup_tick++;
- return;
- }
-
- g_tick++;
-
- if ( g_any_key_hit < 0xFFFFFFFF ) {
- g_any_key_hit++;
- }
-
- for ( int led = 0; led < DRIVER_LED_TOTAL; led++ ) {
- if ( g_key_hit[led] < 255 ) {
- if (g_key_hit[led] == 254)
- g_last_led_count = MAX(g_last_led_count - 1, 0);
- g_key_hit[led]++;
- }
- }
-
- // Factory default magic value
- if ( rgb_matrix_config.mode == 255 ) {
- rgb_matrix_test();
- return;
- }
-
- // Ideally we would also stop sending zeros to the LED driver PWM buffers
- // while suspended and just do a software shutdown. This is a cheap hack for now.
- bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) ||
- (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
- uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode;
-
- #ifdef TRACK_PREVIOUS_EFFECT
- // Keep track of the effect used last time,
- // detect change in effect, so each effect can
- // have an optional initialization.
-
- static uint8_t effect_last = 255;
- bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last);
- effect_last = effect;
- toggle_enable_last = rgb_matrix_config.enable;
- #endif
-
- // this gets ticked at 20 Hz.
- // each effect can opt to do calculations
- // and/or request PWM buffer updates.
- switch ( effect ) {
- case RGB_MATRIX_SOLID_COLOR:
- rgb_matrix_solid_color();
- break;
- #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
- case RGB_MATRIX_ALPHAS_MODS:
- rgb_matrix_alphas_mods();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
- case RGB_MATRIX_DUAL_BEACON:
- rgb_matrix_dual_beacon();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
- case RGB_MATRIX_GRADIENT_UP_DOWN:
- rgb_matrix_gradient_up_down();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINDROPS
- case RGB_MATRIX_RAINDROPS:
- rgb_matrix_raindrops( initialize );
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
- case RGB_MATRIX_CYCLE_ALL:
- rgb_matrix_cycle_all();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
- case RGB_MATRIX_CYCLE_LEFT_RIGHT:
- rgb_matrix_cycle_left_right();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
- case RGB_MATRIX_CYCLE_UP_DOWN:
- rgb_matrix_cycle_up_down();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
- case RGB_MATRIX_RAINBOW_BEACON:
- rgb_matrix_rainbow_beacon();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
- case RGB_MATRIX_RAINBOW_PINWHEELS:
- rgb_matrix_rainbow_pinwheels();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
- case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
- rgb_matrix_rainbow_moving_chevron();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
- case RGB_MATRIX_JELLYBEAN_RAINDROPS:
- rgb_matrix_jellybean_raindrops( initialize );
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
- case RGB_MATRIX_DIGITAL_RAIN:
- rgb_matrix_digital_rain( initialize );
- break;
- #endif
- #ifdef RGB_MATRIX_KEYPRESSES
- #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
- case RGB_MATRIX_SOLID_REACTIVE:
- rgb_matrix_solid_reactive();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
- case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
- rgb_matrix_solid_reactive_simple();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SPLASH
- case RGB_MATRIX_SPLASH:
- rgb_matrix_splash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
- case RGB_MATRIX_MULTISPLASH:
- rgb_matrix_multisplash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
- case RGB_MATRIX_SOLID_SPLASH:
- rgb_matrix_solid_splash();
- break;
- #endif
- #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
- case RGB_MATRIX_SOLID_MULTISPLASH:
- rgb_matrix_solid_multisplash();
- break;
- #endif
- #endif
- default:
- rgb_matrix_custom();
- break;
- }
-
- if ( ! suspend_backlight ) {
- rgb_matrix_indicators();
- }