Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGBW leds #51

Open
directionless opened this issue May 7, 2019 · 6 comments
Open

RGBW leds #51

directionless opened this issue May 7, 2019 · 6 comments

Comments

@directionless
Copy link

I was playing with rgbw leds, using the existing ws2812 driver. It turned out to be quite easy, instead of writing the GRB bytes, I needed to write a 4th W byte. So, what might support for this look like?

I imagine there's some benefit to using the existing color.RGBA type. Does adding an optional parameter for the white array make sense?

@deadprogram
Copy link
Member

I just wonder if in this case, we should use the alpha channel for that? Your typical WS2812 does not support which is why WriteColors() currently ignores that data. Seems like the easiest thing to do, probably, would be to add an additional member to the struct type like HasWhite bool which would control if 3 or 4 bytes are sent.

What do you think?

@aykevl
Copy link
Member

aykevl commented May 7, 2019

Perhaps even better: an enum to describe the color model (or however this should be called):

  • GRB (currently hardcoded)
  • GRBW (your typical RGBW LED strip)

Some (older) strips do not follow the GRB order and it would be useful to add support for those without breaking the API.

@deadprogram
Copy link
Member

That's a much better idea.

@aykevl
Copy link
Member

aykevl commented May 7, 2019

Still, I wonder how we can best pass the white channel in this API. We could (ab)use the alpha channel for that, but I think that's wrong. Maybe we should define a new color type for that, for RGBW? Passing the white channel as a separate slice also seems wrong somehow, it makes working with RGBW colors needlessly difficult.

Come to think of it, I suspect the APA102 uses the wrong color format. I think it should use NRGBA instead of RGBA because it essentially does the alpha calculation inside the LED.

@directionless
Copy link
Author

I have some partially implemented code using functional parameters and an enum. It's pretty clean, but tinygo-org/tinygo#320. I'll look back and put up some kind of PR for it all.

I was thinking the alpha channel felt like a good fit for brightness. (#52)

But I'm still baffled about how to pass the data. I wonder if we should chat with image/color and see what their thoughts are.

@syoder
Copy link

syoder commented Jan 16, 2020

I have a 5x8 Neopixel RGBW panel that I was trying to get working and ran into this issue. And my initial thought was maybe it's not completely crazy to use the alpha channel for white. But if we want to avoid that, we could keep it simple and do something like this:

type RGBW struct {
	color.RGBA
	W uint8
}

func (d Device) WriteColorsRGBW(buf []RGBW) error {
	for _, color := range buf {
		d.WriteByte(color.G) // green
		d.WriteByte(color.R) // red
		d.WriteByte(color.B) // blue
		d.WriteByte(color.W) // white
	}
	return nil
}

That would leave the existing WriteColors as-is so that we wouldn't break it.

Thoughts? I'm happy to throw together a PR if there is some consensus on how to support RGBW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants