From fe566b29dbf80d3e6b7c42755bb4962133616071 Mon Sep 17 00:00:00 2001 From: whowe Date: Wed, 14 Feb 2024 17:10:40 +0800 Subject: [PATCH] Fix fading delta time unit error --- firmware/src/rgb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/firmware/src/rgb.c b/firmware/src/rgb.c index 5e47284..52d7f33 100644 --- a/firmware/src/rgb.c +++ b/firmware/src/rgb.c @@ -123,14 +123,18 @@ static void fade_ctrl() { static uint64_t last = 0; uint64_t now = time_us_64(); - uint64_t delta = now - last; + uint32_t delta_ms = (now - last) / 1000; + + if (delta_ms == 0) { + return; + } for (int i = 0; i < ARRAY_SIZE(rgb_ctrl); i++) { if (rgb_ctrl[i].duration == 0) { continue; } - rgb_ctrl[i].elapsed += delta; + rgb_ctrl[i].elapsed += delta_ms; if (rgb_ctrl[i].elapsed >= rgb_ctrl[i].duration) { rgb_ctrl[i].color = rgb_ctrl[i].target; rgb_ctrl[i].duration = 0;