~ruther/qmk_firmware

ref: 127560ae223255d0e081b932e902d2da242abf06 qmk_firmware/users/anderson/smoothled.c -rw-r--r-- 1.0 KiB
127560ae — Nick Brassel Add `qmk ci-validate-aliases` (#22205) 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <smoothled.h>

static uint32_t sourceColor = 0x000000;
static uint32_t currentColor = 0x000000;
static uint32_t targetColor = 0x000000;
static int32_t smoothledTimer = -1;

void smoothled_set(uint32_t color) {
    smoothledTimer = timer_read32();
    sourceColor = currentColor;
    targetColor = color;
}

void smoothled_process(void) {
    if (smoothledTimer < 0) {
        return;
    }
    int32_t kb = timer_elapsed32(smoothledTimer);
    int32_t ka = SMOOTH_DURATION - kb;
    if (kb > SMOOTH_DURATION) {
        kb = SMOOTH_DURATION;
        ka = 0;
        smoothledTimer = -1;
    }
    currentColor = 0;
    for (int i = 2; i >= 0; i--) {
        uint32_t shift = i * 8;
        currentColor |= (ka * ((uint32_t)(sourceColor >> shift) & 0xFF) + kb * ((uint32_t)(targetColor >> shift) & 0xFF)) / SMOOTH_DURATION;
        /*currentColor |= ((targetColor >> shift) & 0xFF);*/
        currentColor <<= 8;
    }
    currentColor >>= 8;
    rgblight_setrgb((currentColor >> 16) & 0xFF, (currentColor >> 8) & 0xFF, currentColor & 0xFF);
}
Do not follow this link