Add function to allow repeated blinking of one layer (#12237)

* Implement function rgblight_blink_layer_repeat to allow repeated blinking of one layer at a time

* Update doc

* Rework rgblight blinking according to requested change

* optimize storage
daktil_manuform
Matthes W 2021-05-17 02:59:02 +02:00 committed by GitHub
parent c14fa1e28f
commit 6c7450dad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 13 deletions

View File

@ -310,6 +310,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 ### 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`. 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`.

View File

@ -722,23 +722,41 @@ static void rgblight_layers_write(void) {
} }
# ifdef RGBLIGHT_LAYER_BLINK # ifdef RGBLIGHT_LAYER_BLINK
rgblight_layer_mask_t _blinked_layer_mask = 0; rgblight_layer_mask_t _blinking_layer_mask = 0;
static uint16_t _blink_timer; static uint16_t _repeat_timer;
static uint8_t _times_remaining;
static uint16_t _dur;
void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
rgblight_set_layer_state(layer, true); rgblight_blink_layer_repeat(layer, duration_ms, 1);
_blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer;
_blink_timer = sync_timer_read() + duration_ms;
} }
void rgblight_unblink_layers(void) { void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { _times_remaining = times * 2;
_dur = duration_ms;
rgblight_set_layer_state(layer, true);
_times_remaining--;
_blinking_layer_mask |= (rgblight_layer_mask_t)1 << layer;
_repeat_timer = sync_timer_read() + duration_ms;
}
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++) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
if ((_blinked_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) {
rgblight_set_layer_state(layer, false); if (_times_remaining % 2 == 1) {
rgblight_set_layer_state(layer, false);
} else {
rgblight_set_layer_state(layer, true);
}
_times_remaining--;
_repeat_timer = sync_timer_read() + _dur;
} }
} }
_blinked_layer_mask = 0; if (_times_remaining <= 0) {
_blinking_layer_mask = 0;
}
} }
} }
# endif # endif
@ -755,8 +773,8 @@ void rgblight_suspend(void) {
# ifdef RGBLIGHT_LAYER_BLINK # ifdef RGBLIGHT_LAYER_BLINK
// make sure any layer blinks don't come back after suspend // make sure any layer blinks don't come back after suspend
rgblight_status.enabled_layer_mask &= ~_blinked_layer_mask; rgblight_status.enabled_layer_mask &= ~_blinking_layer_mask;
_blinked_layer_mask = 0; _blinking_layer_mask = 0;
# endif # endif
rgblight_disable_noeeprom(); rgblight_disable_noeeprom();
@ -1030,7 +1048,7 @@ void rgblight_task(void) {
} }
# ifdef RGBLIGHT_LAYER_BLINK # ifdef RGBLIGHT_LAYER_BLINK
rgblight_unblink_layers(); rgblight_blink_layer_repeat_helper();
# endif # endif
} }

View File

@ -222,6 +222,7 @@ extern const rgblight_segment_t *const *rgblight_layers;
# ifdef RGBLIGHT_LAYER_BLINK # ifdef RGBLIGHT_LAYER_BLINK
# define RGBLIGHT_USE_TIMER # define RGBLIGHT_USE_TIMER
void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms); 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
# endif # endif