aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgblight.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgblight.c')
-rw-r--r--quantum/rgblight.c31
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 */
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