Skip to content

Commit

Permalink
Merge pull request #89 from qmsk/leds-power-test-chase
Browse files Browse the repository at this point in the history
Fix power enabled for leds test chase
  • Loading branch information
SpComb authored Oct 19, 2024
2 parents acdb297 + 9d827c7 commit 8ff4055
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions components/leds/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

#include <logging.h>

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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/leds/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8ff4055

Please sign in to comment.