Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to allow repeated blinking of one layer #12237

Merged
merged 4 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
}
```

You can also use `rgblight_blink_layer_repeat` to specify the amount of times the layer is supposed to blink. Using the layers from above,
```c
void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case DEBUG:
rgblight_blink_layer_repeat(debug_enable ? 0 : 1, 200, 3);
break;
}
}
```
would turn the layer 0 (or 1) on and off again three times when `DEBUG` is pressed.

### Overriding RGB Lighting on/off status

Normally lighting layers are not shown when RGB Lighting is disabled (e.g. with `RGB_TOG` keycode). If you would like lighting layers to work even when the RGB Lighting is otherwise off, add `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF` to your `config.h`.
Expand Down
33 changes: 33 additions & 0 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,18 @@ static void rgblight_layers_write(void) {
rgblight_layer_mask_t _blinked_layer_mask = 0;
static uint16_t _blink_timer;

rgblight_layer_mask_t _repeating_layer_mask = 0;
static uint16_t _repeat_timer;
static uint8_t _times_remaining = 1;
static uint16_t _dur;

void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
rgblight_set_layer_state(layer, true);
_blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer;
_blink_timer = sync_timer_read() + duration_ms;
if (_repeat_timer) {
_repeat_timer = sync_timer_read() + 2 * duration_ms;
}
}

void rgblight_unblink_layers(void) {
Expand All @@ -741,6 +749,29 @@ void rgblight_unblink_layers(void) {
_blinked_layer_mask = 0;
}
}

void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
_times_remaining = times;
_repeating_layer_mask |= (rgblight_layer_mask_t)1 << layer;
_repeat_timer = sync_timer_read() + 2 * duration_ms;
_dur = duration_ms;
_times_remaining--;
rgblight_blink_layer(layer, duration_ms);
}

void rgblight_blink_layer_repeat_helper(void) {
if (_repeating_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) {
for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
if ((_repeating_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) {
_times_remaining--;
rgblight_blink_layer(layer, _dur);
}
}
if (_times_remaining <= 0) {
_repeating_layer_mask = 0;
}
}
}
# endif

#endif
Expand All @@ -757,6 +788,7 @@ void rgblight_suspend(void) {
// make sure any layer blinks don't come back after suspend
rgblight_status.enabled_layer_mask &= ~_blinked_layer_mask;
_blinked_layer_mask = 0;
_repeating_layer_mask = 0;
# endif

rgblight_disable_noeeprom();
Expand Down Expand Up @@ -1047,6 +1079,7 @@ void rgblight_task(void) {

# ifdef RGBLIGHT_LAYER_BLINK
rgblight_unblink_layers();
rgblight_blink_layer_repeat_helper();
# endif
}

Expand Down
1 change: 1 addition & 0 deletions quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ extern const rgblight_segment_t *const *rgblight_layers;
# ifdef RGBLIGHT_LAYER_BLINK
# define RGBLIGHT_USE_TIMER
void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms);
void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times);
# endif

# endif
Expand Down