diff options
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 8d01bcf0e..4f227794f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -1201,33 +1201,32 @@ void rgblight_effect_alternating(animation_status_t *anim) { | |||
| 1201 | __attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10}; | 1201 | __attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10}; |
| 1202 | 1202 | ||
| 1203 | typedef struct PACKED { | 1203 | typedef struct PACKED { |
| 1204 | HSV hsv; | 1204 | HSV hsv; |
| 1205 | uint8_t life; | 1205 | uint8_t life; |
| 1206 | bool up; | 1206 | bool up; |
| 1207 | } TwinkleState; | 1207 | } TwinkleState; |
| 1208 | 1208 | ||
| 1209 | static TwinkleState led_twinkle_state[RGBLED_NUM]; | 1209 | static TwinkleState led_twinkle_state[RGBLED_NUM]; |
| 1210 | 1210 | ||
| 1211 | void rgblight_effect_twinkle(animation_status_t *anim) { | 1211 | void rgblight_effect_twinkle(animation_status_t *anim) { |
| 1212 | |||
| 1213 | bool random_color = anim->delta / 3; | 1212 | bool random_color = anim->delta / 3; |
| 1214 | bool restart = anim->pos == 0; | 1213 | bool restart = anim->pos == 0; |
| 1215 | anim->pos = 1; | 1214 | anim->pos = 1; |
| 1216 | 1215 | ||
| 1217 | for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { | 1216 | for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1218 | TwinkleState *t = &(led_twinkle_state[i]); | 1217 | TwinkleState *t = &(led_twinkle_state[i]); |
| 1219 | HSV *c = &(t->hsv); | 1218 | HSV * c = &(t->hsv); |
| 1220 | if (restart) { | 1219 | if (restart) { |
| 1221 | // Restart | 1220 | // Restart |
| 1222 | t->life = 0; | 1221 | t->life = 0; |
| 1223 | t->hsv.v = 0; | 1222 | t->hsv.v = 0; |
| 1224 | } else if (t->life) { | 1223 | } else if (t->life) { |
| 1225 | // This LED is already on, either brightening or dimming | 1224 | // This LED is already on, either brightening or dimming |
| 1226 | t->life--; | 1225 | t->life--; |
| 1227 | uint8_t on = t->up ? RGBLIGHT_EFFECT_TWINKLE_LIFE - t->life : t->life; | 1226 | uint8_t on = t->up ? RGBLIGHT_EFFECT_TWINKLE_LIFE - t->life : t->life; |
| 1228 | c->v = (uint16_t) rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; | 1227 | c->v = (uint16_t)rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; |
| 1229 | if (t->life == 0 && t->up) { | 1228 | if (t->life == 0 && t->up) { |
| 1230 | t->up = false; | 1229 | t->up = false; |
| 1231 | t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; | 1230 | t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; |
| 1232 | } | 1231 | } |
| 1233 | if (!random_color) { | 1232 | if (!random_color) { |
| @@ -1236,11 +1235,11 @@ void rgblight_effect_twinkle(animation_status_t *anim) { | |||
| 1236 | } | 1235 | } |
| 1237 | } else if (rand() < RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY) { | 1236 | } else if (rand() < RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY) { |
| 1238 | // This LED is off, but was randomly selected to start brightening | 1237 | // This LED is off, but was randomly selected to start brightening |
| 1239 | c->h = random_color ? rand() % 0xFF : rgblight_config.hue; | 1238 | c->h = random_color ? rand() % 0xFF : rgblight_config.hue; |
| 1240 | c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; | 1239 | c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; |
| 1241 | c->v = 0; | 1240 | c->v = 0; |
| 1242 | t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; | 1241 | t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; |
| 1243 | t->up = true; | 1242 | t->up = true; |
| 1244 | } else { | 1243 | } else { |
| 1245 | // This LED is off, and was NOT selected to start brightening | 1244 | // This LED is off, and was NOT selected to start brightening |
| 1246 | } | 1245 | } |
