aboutsummaryrefslogtreecommitdiff
path: root/users/anderson/smoothled.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/anderson/smoothled.c')
-rw-r--r--users/anderson/smoothled.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/users/anderson/smoothled.c b/users/anderson/smoothled.c
new file mode 100644
index 000000000..3af729563
--- /dev/null
+++ b/users/anderson/smoothled.c
@@ -0,0 +1,34 @@
1#include <smoothled.h>
2
3static uint32_t sourceColor = 0x000000;
4static uint32_t currentColor = 0x000000;
5static uint32_t targetColor = 0x000000;
6static int32_t smoothledTimer = -1;
7
8void smoothled_set(uint32_t color) {
9 smoothledTimer = timer_read32();
10 sourceColor = currentColor;
11 targetColor = color;
12}
13
14void smoothled_process(void) {
15 if (smoothledTimer < 0) {
16 return;
17 }
18 int32_t kb = timer_elapsed32(smoothledTimer);
19 int32_t ka = SMOOTH_DURATION - kb;
20 if (kb > SMOOTH_DURATION) {
21 kb = SMOOTH_DURATION;
22 ka = 0;
23 smoothledTimer = -1;
24 }
25 currentColor = 0;
26 for (int i = 2; i >= 0; i--) {
27 uint32_t shift = i * 8;
28 currentColor |= (ka * ((uint32_t)(sourceColor >> shift) & 0xFF) + kb * ((uint32_t)(targetColor >> shift) & 0xFF)) / SMOOTH_DURATION;
29 /*currentColor |= ((targetColor >> shift) & 0xFF);*/
30 currentColor <<= 8;
31 }
32 currentColor >>= 8;
33 rgblight_setrgb((currentColor >> 16) & 0xFF, (currentColor >> 8) & 0xFF, currentColor & 0xFF);
34}