thebigpotatoe / Super-Simple-RGB-WiFi-Lamp

A project based on the ESP8266 and WS2812b
MIT License
66 stars 28 forks source link

Feature Request: Create global brightness slider in UI #23

Open tristndev opened 4 years ago

tristndev commented 4 years ago

Hi all,

Since I didn't find another space for feature requests, I'm just posting here. Please feel free to label the "issue" accordingly.

On the webpage there is already a top part that is constantly shown (showing the connection status, fade time, turn on / off button).

I think it would make much sense to integrate a global brightness setting there to control the brightness of the lamp regardless which mode it is in. What do you think?

Just as a future feature for the backlog. ;)

LarsMichelsen commented 4 years ago

Seems like the most wished feature :-) I also want to have this.

Have a look here for the maintainers thoughts: https://github.com/thebigpotatoe/Super-Simple-RGB-WiFi-Lamp/pull/9#issuecomment-546797722

thebigpotatoe commented 4 years ago

Haha, oh boy third request for this.I think given the popular request for this feature I will implement it, but it's going to require a few changes.

What will need to happen to make this viable I think is to convert the colour space from RGB to HSV. That way when the lights are set using the HSV space the "value" can be used as a global brightness. What I will also do is make it a function that must be included in new modes so that any mode that does not want to be globally dimmed (ie the visualiser mode) then it will not.

StefaanVanDooren commented 4 years ago

Changing from RGB to HSV is indeed the way to go. I have this done in my current implementation and it is working great. I only can't open a pull request, because I went a different way combining your code and some other.

But I'll keep an eye on this, maybe I'll revert back to yours and add a few mode a have running now.

tristndev commented 4 years ago

Unsure if HSV is really needed, but wouldn't this maybe be possible with FastLED's setBrightness(b) (see documentation) function?

thebigpotatoe commented 4 years ago

The set brightness method is a great feature and I use it everywhere just as nscale8() in the project, but again its not useful to use globally in this project. This is down to the way that FastLED handles colours.

The way FastLED works (and it took me ages to figures this out) is you set your colours first in RGB or HSV structures then apply transforms such as dimming over the top. So for example you set your light to rgb(128, 128, 128) which is a white light at 50% brightness through the colour picker on the web page. FastLED in the sketch would set your channels in a CRGB struct to these values, great.

Then after setting the struct colour values the global brightness function would then be applied. This is done by scaling the current values you have just set, not by scaling them appropriately into a range of 256 like you would think. So in the example where you set rgb(128, 128, 128) your light is already at 50% brightness of white, so by applying the setBrightness() function with a value of say 128 (50% again) you would actually end up with a light at 25% brightness not 50% as you may have intended.

So in all the setBrightness() function in FastLED is misleading and certainly did not produce the results I wanted when I first started using it ages ago which is why I have implemented this project the way I have. If the above explanation does not make sense I will make up a simple example sketch to show how it works.

But since everyone would like a global brightness slider, and I whole heartedly agree, we can move the colour space to HSV. In doing so the V value can be used to globally scale the brightness in a dedicated function rather than using FastLED's misleading setBrightness() function (which will also have the affect on CHSV objects too)

tristndev commented 4 years ago

Understood. Thinking about it more, HSV probably is the way to go then as all solutions with setBrightness() would be kind of hacky.

StefaanVanDooren commented 4 years ago

rgb2hsv_approximate is a handy function in this regard I think