From e2b647b437fd1351563924743db47c207a2a72e9 Mon Sep 17 00:00:00 2001 From: Tero Marttila Date: Sun, 20 Oct 2024 01:40:48 +0300 Subject: [PATCH 1/2] leds: fix leds_power_total() with single led < 100% breaking test mode chase psu active --- components/leds/power.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/leds/power.c b/components/leds/power.c index c3285887..f49b9d64 100644 --- a/components/leds/power.c +++ b/components/leds/power.c @@ -3,6 +3,11 @@ #include +static inline unsigned div_ceil(unsigned x, unsigned y) +{ + return (x / y) + (x % y ? 1 : 0); +} + static inline unsigned leds_power_rgb(struct leds_color color) { return color.r + color.g + color.b; @@ -52,21 +57,22 @@ unsigned leds_power_total(const struct leds_color *pixels, unsigned index, unsig } } + // use div_ceil() to ensure that we return >0 in case any led is set switch (power_mode) { case LEDS_POWER_NONE: return 0; case LEDS_POWER_RGB: - return power / (3 * 255); + return div_ceil(power, (3 * 255)); case LEDS_POWER_RGBA: - return power / (3 * 255 * 31); + return div_ceil(power, (3 * 255 * 31)); case LEDS_POWER_RGBW: - return power / (4 * 255); + return div_ceil(power, (4 * 255)); case LEDS_POWER_RGB2W: - return power / (5 * 255); + return div_ceil(power, (5 * 255)); default: LOG_FATAL("invalid power_mode=%d", power_mode); From 9d827c744fdb3aa4ccda3a551b4bf35514a9b039 Mon Sep 17 00:00:00 2001 From: Tero Marttila Date: Sun, 20 Oct 2024 01:41:21 +0300 Subject: [PATCH 2/2] leds: use full RGBW white for test chase --- components/leds/test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/leds/test.c b/components/leds/test.c index 9246c06b..1c3db83a 100644 --- a/components/leds/test.c +++ b/components/leds/test.c @@ -30,7 +30,7 @@ int leds_test_chase_frame(struct leds *leds, unsigned frame, struct leds_color c break; case LEDS_PARAMETER_WHITE: - color.white = 0; + color.white = 255; break; }