Use White channel on RGBW LEDs

Co-authored-by: kwerdenker <sebastian.spindler@gmail.com>
This commit is contained in:
Drashna Jael're 2019-12-08 12:09:48 -08:00
parent a860da8914
commit 20bfd1fc8f
No known key found for this signature in database
GPG Key ID: DBA1FD3A860D1B11
4 changed files with 26 additions and 2 deletions

View File

@ -85,3 +85,17 @@ RGB hsv_to_rgb(HSV hsv) {
return rgb;
}
#ifdef RGBW
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
void convert_rgb_to_rgbw(LED_TYPE *led) {
// Determine lowest value in all three colors, put that into
// the white channel and then shift all colors by that amount
led->w = MIN(led->r, MIN(led->g, led->b));
led->r -= led->w;
led->g -= led->w;
led->b -= led->w;
}
#endif

View File

@ -64,5 +64,7 @@ typedef struct PACKED {
#endif
RGB hsv_to_rgb(HSV hsv);
#ifdef RGBW
void convert_rgb_to_rgbw(LED_TYPE *led);
#endif
#endif // COLOR_H

View File

@ -114,6 +114,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
led[i].b = b;
# ifdef RGBW
led[i].w = 0;
convert_rgb_to_rgbw(led[i]);
# endif
}

View File

@ -611,6 +611,9 @@ void rgblight_set(void) {
# endif
}
}
# ifdef RGBLIGHT_LED_MAP
LED_TYPE led0[RGBLED_NUM];
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
@ -620,7 +623,11 @@ void rgblight_set(void) {
# else
start_led = led + clipping_start_pos;
# endif
ws2812_setleds(start_led, num_leds);
#ifdef RGBW
convert_rgb_to_rgbw(start_led);
#endif
ws2812_setleds(start_led, num_leds);
}
#endif