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

rgblight: Add functions to stop blinking one or all but one layer #16859

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
```
would turn the layer 0 (or 1) on and off again three times when `DEBUG` is pressed.

Blinking accumulates layers so if multiple layers are set blinking at the same time they will all blink for the duration and repeat times of the last layer to be blinked.
To stop these other layers from blinking use `rgblight_unblink_layer` or `rgblight_unblink_all_but_layer`:

```c
rgblight_blink_layer(1, 500);
rgblight_unblink_all_but_layer(1);
```

```c
rgblight_unblink_layer(3);
rgblight_blink_layer(2, 500);
```

!> Lighting layers on split keyboards will require layer state synced to the slave half (e.g. `#define SPLIT_LAYER_STATE_ENABLE`). See [data sync options](feature_split_keyboard.md#data-sync-options) for more details.

### Overriding RGB Lighting on/off status
Expand Down
15 changes: 15 additions & 0 deletions quantum/rgblight/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,21 @@ void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t ti
_repeat_timer = sync_timer_read() + duration_ms;
}

void rgblight_unblink_layer(uint8_t layer) {
rgblight_set_layer_state(layer, false);
_blinking_layer_mask &= ~((rgblight_layer_mask_t)1 << layer);
}

void rgblight_unblink_all_but_layer(uint8_t layer) {
for (uint8_t i = 0; i < RGBLIGHT_MAX_LAYERS; i++) {
if (i != layer) {
if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << i) != 0) {
rgblight_unblink_layer(i);
}
}
}
}

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++) {
Expand Down
20 changes: 19 additions & 1 deletion quantum/rgblight/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,25 @@ 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);
void rgblight_blink_layer_repeat(uint8_t layer, uint16_ duration_ms, uint8_t times);
/**
* \brief Stop blinking on one layer.
*
* Stop a layer that is blinking. If the layer is not blinking it will
* be unaffected.
*
* \param layer Layer number to stop blinking.
*/
void rgblight_unblink_layer(uint8_t layer);
/**
* \brief Stop blinking all layers except one.
*
* Stop all layers that are blinking except for one specific layer.
* Layers that are not blinking are unaffected.
*
* \param layer Layer number to keep blinking.
*/
void rgblight_unblink_all_but_layer(uint8_t layer);
# endif

#endif
Expand Down