Skip to content

Commit

Permalink
Add breathe effect when idle
Browse files Browse the repository at this point in the history
  • Loading branch information
ViToni committed Dec 13, 2021
1 parent 439aeba commit 0e45198
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions keyboards/gmmk/pro/iso/keymaps/vitoni/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define RGB_DISABLE_WHEN_USB_SUSPENDED
// number of milliseconds to wait until activating RGB idle effects
#define RGB_IDLE_TIMEOUT 4500 // 4.5 seconds
// activate breathe effect when idle
#define RGB_IDLE_BREATHE
// fade in when we have been suspended
#define RGB_FADE_IN
#endif
11 changes: 9 additions & 2 deletions keyboards/gmmk/pro/iso/keymaps/vitoni/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Used to calculate lead time for fade out before suspend timeout.

|===

`RGB_IDLE_TIMEOUT` enables fading out after being idle for the defined time.
`RGB_IDLE_TIMEOUT` enables fading out after being idle for the defined time and allows
* `RGB_IDLE_BREATHE` also activates a brethe effect while idling.

[%header]
|===
Expand All @@ -93,5 +94,11 @@ Used to calculate lead time for fade out before suspend timeout.

|RGB_IDLE_MINIMUM_BRIGHTNESS
|`RGB_MATRIX_MAXIMUM_BRIGHTNESS` / 5
|Brightness value RGB is dimmed to when starting to idle.
|Brightness value RGB is dimmed to when starting to idle. +
When breathing used as the lower bound of the brightness value.

|RGB_IDLE_MAXIMUM_BRIGHTNESS
|`RGB_MATRIX_MAXIMUM_BRIGHTNESS` * 2/5
|Upper bound of brightness value of the RGB light while breathing.

|===
2 changes: 1 addition & 1 deletion users/vitoni/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Common functions are declared in link:utils.h[]. These function are not directly

== rgb_matrix_effects.h

Functions in link:rgb_matrix_effects.h[] make use of common function in `utils.h` and are used to create to RGB matrix effects such as fading.
Functions in link:rgb_matrix_effects.h[] make use of common function in `utils.h` and are used to create to RGB matrix effects such as fading or breathing.

== vitoni.h

Expand Down
14 changes: 14 additions & 0 deletions users/vitoni/rgb_matrix_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,18 @@ bool idle_fade_out(const uint8_t time) {

return fade_out_ranged(time, range_min, range_max);
}

#if defined(RGB_IDLE_BREATHE)
/**
* @brief Changes value/brightness to create a breathing effect based on given timer.
* @details Brightness will breathe in the range starting from `RGB_IDLE_MINIMUM_BRIGHTNESS` to `RGB_IDLE_MAXIMUM_BRIGHTNESS`.
* @param[in] time A (usually scaled) timer
*/
void idle_breathe(const uint8_t time) {
static const uint8_t range_min = RGB_IDLE_MINIMUM_BRIGHTNESS;
static const uint8_t range_max = RGB_IDLE_MAXIMUM_BRIGHTNESS;

rgb_matrix_config.hsv.v = scaled_sin(time, range_min, range_max);
}
#endif // RGB_IDLE_BREATHE
#endif // RGB_IDLE_TIMEOUT
24 changes: 24 additions & 0 deletions users/vitoni/rgb_matrix_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,28 @@ bool fade_out(const uint8_t time);
* @return Returns `true` if `RGB_IDLE_MINIMUM_BRIGHTNESS` has been reached, `false` otherwise.
*/
bool idle_fade_out(const uint8_t time);

#if defined(RGB_IDLE_BREATHE)
# if !defined(RGB_IDLE_MAXIMUM_BRIGHTNESS)
// maximum brightness when idling
# define RGB_IDLE_MAXIMUM_BRIGHTNESS (RGB_MATRIX_MAXIMUM_BRIGHTNESS*3/5)
# endif
# if !(0 <= RGB_IDLE_MAXIMUM_BRIGHTNESS)
# error "RGB_IDLE_MINIMUM_BRIGHTNESS must not be less than ZERO, was: " RGB_IDLE_MAXIMUM_BRIGHTNESS
# endif // RGB_IDLE_MAXIMUM_BRIGHTNESS < 0
# if !(RGB_IDLE_MINIMUM_BRIGHTNESS < RGB_IDLE_MAXIMUM_BRIGHTNESS)
# error "RGB_IDLE_MINIMUM_BRIGHTNESS must be less than RGB_IDLE_MAXIMUM_BRIGHTNESS"
# endif // RGB_IDLE_MAXIMUM_BRIGHTNESS <= RGB_IDLE_MINIMUM_BRIGHTNESS
# if !(RGB_IDLE_MAXIMUM_BRIGHTNESS <= RGB_MATRIX_MAXIMUM_BRIGHTNESS)
# error "RGB_IDLE_MAXIMUM_BRIGHTNESS must be less than or equal to RGB_MATRIX_MAXIMUM_BRIGHTNESS"
# endif // RGB_MATRIX_MAXIMUM_BRIGHTNESS <= RGB_IDLE_MAXIMUM_BRIGHTNESS

/**
* @brief Changes value/brightness to create a breathing effect based on given timer.
* @details Brightness will breathe in the range starting from `RGB_IDLE_MINIMUM_BRIGHTNESS` to `RGB_IDLE_MAXIMUM_BRIGHTNESS`.
* @param[in] time A (usually scaled) timer
*/
void idle_breathe(const uint8_t time);
#endif // RGB_IDLE_BREATHE

#endif // RGB_IDLE_TIMEOUT
8 changes: 8 additions & 0 deletions users/vitoni/vitoni.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ void matrix_scan_user_rgb(void) {
}
break;
case IDLE:
#if defined(RGB_IDLE_BREATHE)
if (calc_offset) {
// no need to calculate time_offset since we are aligned already due to IDLE_FADE_OUT
// resetting flag for subsequent calls
calc_offset = false;
}
idle_breathe(time + time_offset);
#endif
break;
#endif
#if defined(RGB_DISABLE_WITH_FADE_OUT)
Expand Down

0 comments on commit 0e45198

Please sign in to comment.