aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgblight.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgblight.c')
-rw-r--r--quantum/rgblight.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 119d3eab2..baa10ec41 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -722,23 +722,39 @@ 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;
729
730void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_blink_layer_repeat(layer, duration_ms, 1); }
731
732void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
733 _times_remaining = times * 2;
734 _dur = duration_ms;
727 735
728void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
729 rgblight_set_layer_state(layer, true); 736 rgblight_set_layer_state(layer, true);
730 _blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer; 737 _times_remaining--;
731 _blink_timer = sync_timer_read() + duration_ms; 738 _blinking_layer_mask |= (rgblight_layer_mask_t)1 << layer;
739 _repeat_timer = sync_timer_read() + duration_ms;
732} 740}
733 741
734void rgblight_unblink_layers(void) { 742void rgblight_blink_layer_repeat_helper(void) {
735 if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { 743 if (_blinking_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) {
736 for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { 744 for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
737 if ((_blinked_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { 745 if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) {
738 rgblight_set_layer_state(layer, false); 746 if (_times_remaining % 2 == 1) {
747 rgblight_set_layer_state(layer, false);
748 } else {
749 rgblight_set_layer_state(layer, true);
750 }
751 _times_remaining--;
752 _repeat_timer = sync_timer_read() + _dur;
739 } 753 }
740 } 754 }
741 _blinked_layer_mask = 0; 755 if (_times_remaining <= 0) {
756 _blinking_layer_mask = 0;
757 }
742 } 758 }
743} 759}
744# endif 760# endif
@@ -755,8 +771,8 @@ void rgblight_suspend(void) {
755 771
756# ifdef RGBLIGHT_LAYER_BLINK 772# ifdef RGBLIGHT_LAYER_BLINK
757 // make sure any layer blinks don't come back after suspend 773 // make sure any layer blinks don't come back after suspend
758 rgblight_status.enabled_layer_mask &= ~_blinked_layer_mask; 774 rgblight_status.enabled_layer_mask &= ~_blinking_layer_mask;
759 _blinked_layer_mask = 0; 775 _blinking_layer_mask = 0;
760# endif 776# endif
761 777
762 rgblight_disable_noeeprom(); 778 rgblight_disable_noeeprom();
@@ -874,7 +890,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
874 animation_status.restart = true; 890 animation_status.restart = true;
875 } 891 }
876# endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ 892# endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
877# endif /* RGBLIGHT_USE_TIMER */ 893# endif /* RGBLIGHT_USE_TIMER */
878} 894}
879#endif /* RGBLIGHT_SPLIT */ 895#endif /* RGBLIGHT_SPLIT */
880 896
@@ -1030,7 +1046,7 @@ void rgblight_task(void) {
1030 } 1046 }
1031 1047
1032# ifdef RGBLIGHT_LAYER_BLINK 1048# ifdef RGBLIGHT_LAYER_BLINK
1033 rgblight_unblink_layers(); 1049 rgblight_blink_layer_repeat_helper();
1034# endif 1050# endif
1035} 1051}
1036 1052