Skip to content

Commit

Permalink
Add ability to blink lighting layer for a specified duration (qmk#8760)
Browse files Browse the repository at this point in the history
* Implement momentarily blink of lighting layers

* Refactor spidey3 userspace to use rgb layer blink

* Remove un-necessary line from example in documentation

* Revert "Refactor spidey3 userspace to use rgb layer blink"

This reverts commit 831649b.

* Adds a missing bit of documentation about lighting layer blink

* Update docs/feature_rgblight.md per suggestions

Co-authored-by: James Young <[email protected]>

* Update docs/feature_rgblight.md per suggestions

Co-authored-by: James Young <[email protected]>

* Update docs/feature_rgblight.md per suggestions

Co-authored-by: James Young <[email protected]>

* cformat, as suggested

Co-authored-by: James Young <[email protected]>
  • Loading branch information
2 people authored and fdidron committed Jun 12, 2020
1 parent f91afd0 commit d487e0f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,31 @@ static void rgblight_layers_write(void) {
}
}
}

# ifdef RGBLIGHT_LAYER_BLINK
uint8_t _blinked_layer_mask = 0;
uint16_t _blink_duration = 0;
static uint16_t _blink_timer;

void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
rgblight_set_layer_state(layer, true);
_blinked_layer_mask |= 1 << layer;
_blink_timer = timer_read();
_blink_duration = duration_ms;
}

void rgblight_unblink_layers(void) {
if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) {
for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
if ((_blinked_layer_mask & 1 << layer) != 0) {
rgblight_set_layer_state(layer, false);
}
}
_blinked_layer_mask = 0;
}
}
# endif

#endif

__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); }
Expand Down Expand Up @@ -908,6 +933,10 @@ void rgblight_task(void) {
# endif
}
}

# ifdef RGBLIGHT_LAYER_BLINK
rgblight_unblink_layers();
# endif
}

#endif /* RGBLIGHT_USE_TIMER */
Expand Down
6 changes: 6 additions & 0 deletions quantum/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ bool rgblight_get_layer_state(uint8_t layer);

// Point this to an array of rgblight_segment_t arrays in keyboard_post_init_user to use rgblight layers
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);
# endif

# endif

extern LED_TYPE led[RGBLED_NUM];
Expand Down

0 comments on commit d487e0f

Please sign in to comment.