From 057ca06ad529d0731c8cbd221012e2435958f151 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sat, 9 Apr 2022 16:33:43 +0100 Subject: [PATCH] rgblight: Fix rgblight_blink_layer when multiple layers are active The change to support repeated blinking (#12237) does not work correctly when there are multiple blinking layers active at the same time. It is decrementing the number of times remaining for every active layer which will cause it to reach 0 prematurely and ignore some of the layers. Decrement times remaining only once for each timer event. --- quantum/rgblight/rgblight.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 8f933a6e510c..635ce0d0410b 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -825,18 +825,19 @@ void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t ti void rgblight_blink_layer_repeat_helper(void) { if (_blinking_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { - if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) { + if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { if (_times_remaining % 2 == 1) { rgblight_set_layer_state(layer, false); } else { rgblight_set_layer_state(layer, true); } - _times_remaining--; - _repeat_timer = sync_timer_read() + _dur; } } + _times_remaining--; if (_times_remaining <= 0) { _blinking_layer_mask = 0; + } else { + _repeat_timer = sync_timer_read() + _dur; } } }