aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgblight.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgblight.c')
-rw-r--r--quantum/rgblight.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 119d3eab2..e4c4d555e 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -722,23 +722,41 @@ static void rgblight_layers_write(void) {
722} 722}
723 723
724# ifdef RGBLIGHT_LAYER_BLINK 724# ifdef RGBLIGHT_LAYER_BLINK
725rgblight_layer_mask_t _blinked_layer_mask = 0; 725rgblight_layer_mask_t _blinking_layer_mask = 0;
726static uint16_t _blink_timer; 726static uint16_t _repeat_timer;
727static uint8_t _times_remaining;
728static uint16_t _dur;
727 729
728void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { 730void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
731 rgblight_blink_layer_repeat(layer, duration_ms, 1);
732}
733
734void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
735 _times_remaining = times * 2;
736 _dur = duration_ms;
737
729 rgblight_set_layer_state(layer, true); 738 rgblight_set_layer_state(layer, true);
730 _blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer; 739 _times_remaining--;
731 _blink_timer = sync_timer_read() + duration_ms; 740 _blinking_layer_mask |= (rgblight_layer_mask_t)1 << layer;
741 _repeat_timer = sync_timer_read() + duration_ms;
732} 742}
733 743
734void rgblight_unblink_layers(void) { 744void rgblight_blink_layer_repeat_helper(void) {
735 if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { 745 if (_blinking_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) {
736 for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { 746 for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
737 if ((_blinked_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { 747 if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) {
738 rgblight_set_layer_state(layer, false); 748 if (_times_remaining % 2 == 1) {
749 rgblight_set_layer_state(layer, false);
750 } else {
751 rgblight_set_layer_state(layer, true);
752 }
753 _times_remaining--;
754 _repeat_timer = sync_timer_read() + _dur;
739 } 755 }
740 } 756 }
741 _blinked_layer_mask = 0; 757 if (_times_remaining <= 0) {
758 _blinking_layer_mask = 0;
759 }
742 } 760 }
743} 761}
744# endif 762# endif
@@ -755,8 +773,8 @@ void rgblight_suspend(void) {
755 773
756# ifdef RGBLIGHT_LAYER_BLINK 774# ifdef RGBLIGHT_LAYER_BLINK
757 // make sure any layer blinks don't come back after suspend 775 // make sure any layer blinks don't come back after suspend
758 rgblight_status.enabled_layer_mask &= ~_blinked_layer_mask; 776 rgblight_status.enabled_layer_mask &= ~_blinking_layer_mask;
759 _blinked_layer_mask = 0; 777 _blinking_layer_mask = 0;
760# endif 778# endif
761 779
762 rgblight_disable_noeeprom(); 780 rgblight_disable_noeeprom();
@@ -1030,7 +1048,7 @@ void rgblight_task(void) {
1030 } 1048 }
1031 1049
1032# ifdef RGBLIGHT_LAYER_BLINK 1050# ifdef RGBLIGHT_LAYER_BLINK
1033 rgblight_unblink_layers(); 1051 rgblight_blink_layer_repeat_helper();
1034# endif 1052# endif
1035} 1053}
1036 1054