Skip to content

Commit 0e45198

Browse files
committed
Add breathe effect when idle
1 parent 439aeba commit 0e45198

File tree

6 files changed

+58
-3
lines changed

6 files changed

+58
-3
lines changed

keyboards/gmmk/pro/iso/keymaps/vitoni/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define RGB_DISABLE_WHEN_USB_SUSPENDED
1414
// number of milliseconds to wait until activating RGB idle effects
1515
#define RGB_IDLE_TIMEOUT 4500 // 4.5 seconds
16+
// activate breathe effect when idle
17+
#define RGB_IDLE_BREATHE
1618
// fade in when we have been suspended
1719
#define RGB_FADE_IN
1820
#endif

keyboards/gmmk/pro/iso/keymaps/vitoni/readme.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ Used to calculate lead time for fade out before suspend timeout.
8181

8282
|===
8383

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

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

9495
|RGB_IDLE_MINIMUM_BRIGHTNESS
9596
|`RGB_MATRIX_MAXIMUM_BRIGHTNESS` / 5
96-
|Brightness value RGB is dimmed to when starting to idle.
97+
|Brightness value RGB is dimmed to when starting to idle. +
98+
When breathing used as the lower bound of the brightness value.
99+
100+
|RGB_IDLE_MAXIMUM_BRIGHTNESS
101+
|`RGB_MATRIX_MAXIMUM_BRIGHTNESS` * 2/5
102+
|Upper bound of brightness value of the RGB light while breathing.
103+
97104
|===

users/vitoni/readme.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Common functions are declared in link:utils.h[]. These function are not directly
88

99
== rgb_matrix_effects.h
1010

11-
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.
11+
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.
1212

1313
== vitoni.h
1414

users/vitoni/rgb_matrix_effects.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,18 @@ bool idle_fade_out(const uint8_t time) {
219219

220220
return fade_out_ranged(time, range_min, range_max);
221221
}
222+
223+
#if defined(RGB_IDLE_BREATHE)
224+
/**
225+
* @brief Changes value/brightness to create a breathing effect based on given timer.
226+
* @details Brightness will breathe in the range starting from `RGB_IDLE_MINIMUM_BRIGHTNESS` to `RGB_IDLE_MAXIMUM_BRIGHTNESS`.
227+
* @param[in] time A (usually scaled) timer
228+
*/
229+
void idle_breathe(const uint8_t time) {
230+
static const uint8_t range_min = RGB_IDLE_MINIMUM_BRIGHTNESS;
231+
static const uint8_t range_max = RGB_IDLE_MAXIMUM_BRIGHTNESS;
232+
233+
rgb_matrix_config.hsv.v = scaled_sin(time, range_min, range_max);
234+
}
235+
#endif // RGB_IDLE_BREATHE
222236
#endif // RGB_IDLE_TIMEOUT

users/vitoni/rgb_matrix_effects.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,28 @@ bool fade_out(const uint8_t time);
147147
* @return Returns `true` if `RGB_IDLE_MINIMUM_BRIGHTNESS` has been reached, `false` otherwise.
148148
*/
149149
bool idle_fade_out(const uint8_t time);
150+
151+
#if defined(RGB_IDLE_BREATHE)
152+
# if !defined(RGB_IDLE_MAXIMUM_BRIGHTNESS)
153+
// maximum brightness when idling
154+
# define RGB_IDLE_MAXIMUM_BRIGHTNESS (RGB_MATRIX_MAXIMUM_BRIGHTNESS*3/5)
155+
# endif
156+
# if !(0 <= RGB_IDLE_MAXIMUM_BRIGHTNESS)
157+
# error "RGB_IDLE_MINIMUM_BRIGHTNESS must not be less than ZERO, was: " RGB_IDLE_MAXIMUM_BRIGHTNESS
158+
# endif // RGB_IDLE_MAXIMUM_BRIGHTNESS < 0
159+
# if !(RGB_IDLE_MINIMUM_BRIGHTNESS < RGB_IDLE_MAXIMUM_BRIGHTNESS)
160+
# error "RGB_IDLE_MINIMUM_BRIGHTNESS must be less than RGB_IDLE_MAXIMUM_BRIGHTNESS"
161+
# endif // RGB_IDLE_MAXIMUM_BRIGHTNESS <= RGB_IDLE_MINIMUM_BRIGHTNESS
162+
# if !(RGB_IDLE_MAXIMUM_BRIGHTNESS <= RGB_MATRIX_MAXIMUM_BRIGHTNESS)
163+
# error "RGB_IDLE_MAXIMUM_BRIGHTNESS must be less than or equal to RGB_MATRIX_MAXIMUM_BRIGHTNESS"
164+
# endif // RGB_MATRIX_MAXIMUM_BRIGHTNESS <= RGB_IDLE_MAXIMUM_BRIGHTNESS
165+
166+
/**
167+
* @brief Changes value/brightness to create a breathing effect based on given timer.
168+
* @details Brightness will breathe in the range starting from `RGB_IDLE_MINIMUM_BRIGHTNESS` to `RGB_IDLE_MAXIMUM_BRIGHTNESS`.
169+
* @param[in] time A (usually scaled) timer
170+
*/
171+
void idle_breathe(const uint8_t time);
172+
#endif // RGB_IDLE_BREATHE
173+
150174
#endif // RGB_IDLE_TIMEOUT

users/vitoni/vitoni.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ void matrix_scan_user_rgb(void) {
6161
}
6262
break;
6363
case IDLE:
64+
#if defined(RGB_IDLE_BREATHE)
65+
if (calc_offset) {
66+
// no need to calculate time_offset since we are aligned already due to IDLE_FADE_OUT
67+
// resetting flag for subsequent calls
68+
calc_offset = false;
69+
}
70+
idle_breathe(time + time_offset);
71+
#endif
6472
break;
6573
#endif
6674
#if defined(RGB_DISABLE_WITH_FADE_OUT)

0 commit comments

Comments
 (0)