diff options
| author | Max Rumpf <max.rumpf1998@gmail.com> | 2020-07-26 01:00:33 +0200 |
|---|---|---|
| committer | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-08-29 14:30:02 -0700 |
| commit | 4b74f985ec7b14f5517df4e591f0c36b24f85f5c (patch) | |
| tree | 241f9f678df1485314e15f9e2aa9e59727131ff4 /quantum/rgblight.c | |
| parent | d4be07dad368c57669c88ead6c093c9e23086855 (diff) | |
| download | qmk_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
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 31 |
1 files changed, 27 insertions, 4 deletions
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 | */ | ||
| 1166 | void rgblight_effect_christmas(animation_status_t *anim) { | 1171 | void 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 | ||
