aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Rumpf <max.rumpf1998@gmail.com>2020-07-26 01:00:33 +0200
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commit4b74f985ec7b14f5517df4e591f0c36b24f85f5c (patch)
tree241f9f678df1485314e15f9e2aa9e59727131ff4
parentd4be07dad368c57669c88ead6c093c9e23086855 (diff)
downloadqmk_firmware-4b74f985ec7b14f5517df4e591f0c36b24f85f5c.tar.gz
qmk_firmware-4b74f985ec7b14f5517df4e591f0c36b24f85f5c.zip
Tweak the Christmas animation effect to be less harsh on the eyes (#7648)
* Tweak the Christmas animation effect to be less harsh on the eyes * Further improve the tweaked Christmas animation code - Use constants where it makes sense - Instead of complicated math, use a static variable to keep track if it's animating from or to red - Don't use pow (but a simple macro instead) - Using floating point math is necessary for the fraction in the cubic bezier function to work * Update docs for the tweaked Christmas animation effect * Further improve memory usage - Don't use floats, but 32 bit ints instead (where needed) - Replace limits.h with constant * Fix typo
-rw-r--r--docs/feature_rgblight.md24
-rw-r--r--quantum/rgblight.c31
-rw-r--r--quantum/rgblight.h2
3 files changed, 40 insertions, 17 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index 26e01da50..23b2886ed 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -126,19 +126,19 @@ Use these defines to add or remove animations from the firmware. When you are ru
126 126
127The following options are used to tweak the various animations: 127The following options are used to tweak the various animations:
128 128
129|Define |Default |Description | 129|Define |Default |Description |
130|------------------------------------|-------------|-------------------------------------------------------------------------------------| 130|------------------------------------|-------------|-----------------------------------------------------------------------------------------------|
131|`RGBLIGHT_EFFECT_BREATHE_CENTER` |*Not defined*|If defined, used to calculate the curve for the breathing animation. Valid values are 1.0 to 2.7 | 131|`RGBLIGHT_EFFECT_BREATHE_CENTER` |*Not defined*|If defined, used to calculate the curve for the breathing animation. Valid values are 1.0 to 2.7 |
132|`RGBLIGHT_EFFECT_BREATHE_MAX` |`255` |The maximum brightness for the breathing mode. Valid values are 1 to 255 | 132|`RGBLIGHT_EFFECT_BREATHE_MAX` |`255` |The maximum brightness for the breathing mode. Valid values are 1 to 255 |
133|`RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL`|`1000` |How long to wait between light changes for the "Christmas" animation, in milliseconds| 133|`RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL`|`40` |How long (in milliseconds) to wait between animation steps for the "Christmas" animation |
134|`RGBLIGHT_EFFECT_CHRISTMAS_STEP` |`2` |The number of LEDs to group the red/green colors by for the "Christmas" animation | 134|`RGBLIGHT_EFFECT_CHRISTMAS_STEP` |`2` |The number of LEDs to group the red/green colors by for the "Christmas" animation |
135|`RGBLIGHT_EFFECT_KNIGHT_LED_NUM` |`RGBLED_NUM` |The number of LEDs to have the "Knight" animation travel | 135|`RGBLIGHT_EFFECT_KNIGHT_LED_NUM` |`RGBLED_NUM` |The number of LEDs to have the "Knight" animation travel |
136|`RGBLIGHT_EFFECT_KNIGHT_LENGTH` |`3` |The number of LEDs to light up for the "Knight" animation | 136|`RGBLIGHT_EFFECT_KNIGHT_LENGTH` |`3` |The number of LEDs to light up for the "Knight" animation |
137|`RGBLIGHT_EFFECT_KNIGHT_OFFSET` |`0` |The number of LEDs to start the "Knight" animation from the start of the strip by | 137|`RGBLIGHT_EFFECT_KNIGHT_OFFSET` |`0` |The number of LEDs to start the "Knight" animation from the start of the strip by |
138|`RGBLIGHT_RAINBOW_SWIRL_RANGE` |`255` |Range adjustment for the rainbow swirl effect to get different swirls | 138|`RGBLIGHT_RAINBOW_SWIRL_RANGE` |`255` |Range adjustment for the rainbow swirl effect to get different swirls |
139|`RGBLIGHT_EFFECT_SNAKE_LENGTH` |`4` |The number of LEDs to light up for the "Snake" animation | 139|`RGBLIGHT_EFFECT_SNAKE_LENGTH` |`4` |The number of LEDs to light up for the "Snake" animation |
140|`RGBLIGHT_EFFECT_TWINKLE_LIFE` |`75` |Adjusts how quickly each LED brightens and dims when twinkling (in animation steps) | 140|`RGBLIGHT_EFFECT_TWINKLE_LIFE` |`75` |Adjusts how quickly each LED brightens and dims when twinkling (in animation steps) |
141|`RGBLIGHT_EFFECT_TWINKLE_PROBABILITY`|`1/127` |Adjusts how likely each LED is to twinkle (on each animation step) | 141|`RGBLIGHT_EFFECT_TWINKLE_PROBABILITY`|`1/127` |Adjusts how likely each LED is to twinkle (on each animation step) |
142 142
143### Example Usage to Reduce Memory Footprint 143### Example Usage to Reduce Memory Footprint
144 1. Remove `RGBLIGHT_ANIMATIONS` from `config.h`. 144 1. Remove `RGBLIGHT_ANIMATIONS` from `config.h`.
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index f9e9da167..52d8da181 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -1163,16 +1163,39 @@ void rgblight_effect_knight(animation_status_t *anim) {
1163#endif 1163#endif
1164 1164
1165#ifdef RGBLIGHT_EFFECT_CHRISTMAS 1165#ifdef RGBLIGHT_EFFECT_CHRISTMAS
1166# define CUBED(x) ((x) * (x) * (x))
1167
1168/**
1169 * Christmas lights effect, with a smooth animation between red & green.
1170 */
1166void rgblight_effect_christmas(animation_status_t *anim) { 1171void rgblight_effect_christmas(animation_status_t *anim) {
1167 uint8_t hue; 1172 static int8_t increment = 1;
1173 const uint8_t max_pos = 32;
1174 const uint8_t hue_green = 85;
1175
1176 uint32_t xa;
1177 uint8_t hue, val;
1168 uint8_t i; 1178 uint8_t i;
1169 1179
1170 anim->current_offset = (anim->current_offset + 1) % 2; 1180 // The effect works by animating anim->pos from 0 to 32 and back to 0.
1181 // The pos is used in a cubic bezier formula to ease-in-out between red and green, leaving the interpolated colors visible as short as possible.
1182 xa = CUBED((uint32_t) anim->pos);
1183 hue = ((uint32_t) hue_green) * xa / (xa + CUBED((uint32_t) (max_pos - anim->pos)));
1184 // Additionally, these interpolated colors get shown with a slightly darker value, to make them less prominent than the main colors.
1185 val = 255 - (3 * (hue < hue_green / 2 ? hue : hue_green - hue) / 2);
1186
1171 for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { 1187 for (i = 0; i < rgblight_ranges.effect_num_leds; i++) {
1172 hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; 1188 uint8_t local_hue = (i / RGBLIGHT_EFFECT_CHRISTMAS_STEP) % 2 ? hue : hue_green - hue;
1173 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); 1189 sethsv(local_hue, rgblight_config.sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
1174 } 1190 }
1175 rgblight_set(); 1191 rgblight_set();
1192
1193 if (anim->pos == 0) {
1194 increment = 1;
1195 } else if (anim->pos == max_pos) {
1196 increment = -1;
1197 }
1198 anim->pos += increment;
1176} 1199}
1177#endif 1200#endif
1178 1201
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 7b2696294..c3a9e94b7 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -142,7 +142,7 @@ enum RGBLIGHT_EFFECT_MODE {
142# endif 142# endif
143 143
144# ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 144# ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
145# define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000 145# define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 40
146# endif 146# endif
147 147
148# ifndef RGBLIGHT_EFFECT_CHRISTMAS_STEP 148# ifndef RGBLIGHT_EFFECT_CHRISTMAS_STEP