diff options
| author | XScorpion2 <rcalt2vt@gmail.com> | 2020-12-01 12:04:42 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-01 10:04:42 -0800 |
| commit | a8d0ec0749046b0ab89c18b1b7083b1e8674de2a (patch) | |
| tree | 06c81bed47c6f4128bf0fc33697646994bffab00 /quantum/rgblight.c | |
| parent | 9c03a8959621016d27fdd7cdfbabce28fd7d1757 (diff) | |
| download | qmk_firmware-a8d0ec0749046b0ab89c18b1b7083b1e8674de2a.tar.gz qmk_firmware-a8d0ec0749046b0ab89c18b1b7083b1e8674de2a.zip | |
[Split] Sync Timer feature (#10997)
A timer that is kept in sync between the halves of a split keyboard
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7f9e330d3..65308572d 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | #endif | 29 | #endif |
| 30 | #include "wait.h" | 30 | #include "wait.h" |
| 31 | #include "progmem.h" | 31 | #include "progmem.h" |
| 32 | #include "timer.h" | 32 | #include "sync_timer.h" |
| 33 | #include "rgblight.h" | 33 | #include "rgblight.h" |
| 34 | #include "color.h" | 34 | #include "color.h" |
| 35 | #include "debug.h" | 35 | #include "debug.h" |
| @@ -684,18 +684,16 @@ static void rgblight_layers_write(void) { | |||
| 684 | 684 | ||
| 685 | # ifdef RGBLIGHT_LAYER_BLINK | 685 | # ifdef RGBLIGHT_LAYER_BLINK |
| 686 | rgblight_layer_mask_t _blinked_layer_mask = 0; | 686 | rgblight_layer_mask_t _blinked_layer_mask = 0; |
| 687 | uint16_t _blink_duration = 0; | ||
| 688 | static uint16_t _blink_timer; | 687 | static uint16_t _blink_timer; |
| 689 | 688 | ||
| 690 | void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { | 689 | void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { |
| 691 | rgblight_set_layer_state(layer, true); | 690 | rgblight_set_layer_state(layer, true); |
| 692 | _blinked_layer_mask |= 1 << layer; | 691 | _blinked_layer_mask |= 1 << layer; |
| 693 | _blink_timer = timer_read(); | 692 | _blink_timer = sync_timer_read() + duration_ms; |
| 694 | _blink_duration = duration_ms; | ||
| 695 | } | 693 | } |
| 696 | 694 | ||
| 697 | void rgblight_unblink_layers(void) { | 695 | void rgblight_unblink_layers(void) { |
| 698 | if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { | 696 | if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { |
| 699 | for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { | 697 | for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { |
| 700 | if ((_blinked_layer_mask & 1 << layer) != 0) { | 698 | if ((_blinked_layer_mask & 1 << layer) != 0) { |
| 701 | rgblight_set_layer_state(layer, false); | 699 | rgblight_set_layer_state(layer, false); |
| @@ -799,7 +797,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { | |||
| 799 | animation_status.restart = true; | 797 | animation_status.restart = true; |
| 800 | } | 798 | } |
| 801 | # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ | 799 | # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ |
| 802 | # endif /* RGBLIGHT_USE_TIMER */ | 800 | # endif /* RGBLIGHT_USE_TIMER */ |
| 803 | } | 801 | } |
| 804 | #endif /* RGBLIGHT_SPLIT */ | 802 | #endif /* RGBLIGHT_SPLIT */ |
| 805 | 803 | ||
| @@ -832,7 +830,7 @@ void rgblight_timer_enable(void) { | |||
| 832 | if (!is_static_effect(rgblight_config.mode)) { | 830 | if (!is_static_effect(rgblight_config.mode)) { |
| 833 | rgblight_status.timer_enabled = true; | 831 | rgblight_status.timer_enabled = true; |
| 834 | } | 832 | } |
| 835 | animation_status.last_timer = timer_read(); | 833 | animation_status.last_timer = sync_timer_read(); |
| 836 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; | 834 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; |
| 837 | dprintf("rgblight timer enabled.\n"); | 835 | dprintf("rgblight timer enabled.\n"); |
| 838 | } | 836 | } |
| @@ -941,18 +939,19 @@ void rgblight_task(void) { | |||
| 941 | # endif | 939 | # endif |
| 942 | if (animation_status.restart) { | 940 | if (animation_status.restart) { |
| 943 | animation_status.restart = false; | 941 | animation_status.restart = false; |
| 944 | animation_status.last_timer = timer_read() - interval_time - 1; | 942 | animation_status.last_timer = sync_timer_read(); |
| 945 | animation_status.pos16 = 0; // restart signal to local each effect | 943 | animation_status.pos16 = 0; // restart signal to local each effect |
| 946 | } | 944 | } |
| 947 | if (timer_elapsed(animation_status.last_timer) >= interval_time) { | 945 | uint16_t now = sync_timer_read(); |
| 946 | if (timer_expired(now, animation_status.last_timer)) { | ||
| 948 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 947 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 949 | static uint16_t report_last_timer = 0; | 948 | static uint16_t report_last_timer = 0; |
| 950 | static bool tick_flag = false; | 949 | static bool tick_flag = false; |
| 951 | uint16_t oldpos16; | 950 | uint16_t oldpos16; |
| 952 | if (tick_flag) { | 951 | if (tick_flag) { |
| 953 | tick_flag = false; | 952 | tick_flag = false; |
| 954 | if (timer_elapsed(report_last_timer) >= 30000) { | 953 | if (timer_expired(now, report_last_timer)) { |
| 955 | report_last_timer = timer_read(); | 954 | report_last_timer += 30000; |
| 956 | dprintf("rgblight animation tick report to slave\n"); | 955 | dprintf("rgblight animation tick report to slave\n"); |
| 957 | RGBLIGHT_SPLIT_ANIMATION_TICK; | 956 | RGBLIGHT_SPLIT_ANIMATION_TICK; |
| 958 | } | 957 | } |
