Browse Source

Use brightness when _light_use_white is disabled

rfm69
Xose Pérez 6 years ago
parent
commit
627b9874d1
4 changed files with 3087 additions and 3075 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +45
    -35
      code/espurna/light.ino
  3. +3041
    -3039
      code/espurna/static/index.html.gz.h
  4. +1
    -1
      code/html/index.html

BIN
code/espurna/data/index.html.gz View File


+ 45
- 35
code/espurna/light.ino View File

@ -77,47 +77,57 @@ const unsigned char _light_gamma_table[] = {
// -----------------------------------------------------------------------------
void _setRGBInputValue(unsigned char red, unsigned char green, unsigned char blue) {
_light_channel[0].inputValue = red;
_light_channel[1].inputValue = green;
_light_channel[2].inputValue = blue;
_light_channel[0].inputValue = red;
_light_channel[1].inputValue = green;
_light_channel[2].inputValue = blue;
}
void _generateBrightness() {
double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS;
// Convert RGB to RGBW
if (_light_has_color && _light_use_white) {
unsigned char white, max_in, max_out;
double factor = 0;
double brightness = (double) _light_brightness / LIGHT_MAX_BRIGHTNESS;
white = std::min(_light_channel[0].inputValue, std::min(_light_channel[1].inputValue, _light_channel[2].inputValue));
max_in = std::max(_light_channel[0].inputValue, std::max(_light_channel[1].inputValue, _light_channel[2].inputValue));
// Convert RGB to RGBW
if (_light_has_color && _light_use_white) {
for (unsigned int i=0; i < 3; i++) {
_light_channel[i].value = _light_channel[i].inputValue - white;
}
_light_channel[3].value = white;
unsigned char white, max_in, max_out;
double factor = 0;
max_out = std::max(std::max(_light_channel[0].value, _light_channel[1].value), std::max(_light_channel[2].value, _light_channel[3].value));
white = std::min(_light_channel[0].inputValue, std::min(_light_channel[1].inputValue, _light_channel[2].inputValue));
max_in = std::max(_light_channel[0].inputValue, std::max(_light_channel[1].inputValue, _light_channel[2].inputValue));
if (max_out > 0) {
factor = (double) (max_in / max_out);
}
for (unsigned int i=0; i < 3; i++) {
_light_channel[i].value = _light_channel[i].inputValue - white;
}
_light_channel[3].value = white;
max_out = std::max(std::max(_light_channel[0].value, _light_channel[1].value), std::max(_light_channel[2].value, _light_channel[3].value));
if (max_out > 0) {
factor = (double) (max_in / max_out);
}
// Scale up to equal input values. So [250,150,50] -> [200,100,0,50] -> [250, 125, 0, 63]
for (unsigned int i=0; i < 4; i++) {
_light_channel[i].value = round((double) _light_channel[i].value * factor * brightness);
}
// Don't apply brightness, it is already in the inputValue:
if (_light_channel.size() == 5) {
_light_channel[4].value = _light_channel[4].inputValue;
}
} else {
// Don't apply brightness, it is already in the inputValue:
for (unsigned char i=0; i < _light_channel.size(); i++) {
if (_light_has_color & (i<3)) {
_light_channel[i].value = _light_channel[i].inputValue * brightness;
} else {
_light_channel[i].value = _light_channel[i].inputValue;
}
}
// Scale up to equal input values. So [250,150,50] -> [200,100,0,50] -> [250, 125, 0, 63]
for (unsigned int i=0; i < 4; i++) {
_light_channel[i].value = round((double) _light_channel[i].value * factor * brightness);
}
// Don't apply brightness, it is already in the inputValue:
if (_light_channel.size() == 5) {
_light_channel[4].value = _light_channel[4].inputValue;
}
} else {
// Don't apply brightness, it is already in the inputValue:
for (unsigned char i=0; i < _light_channel.size(); i++) {
_light_channel[i].value = _light_channel[i].inputValue;
}
}
}
// -----------------------------------------------------------------------------
@ -240,7 +250,7 @@ void _fromHSV(const char * hsv) {
_setRGBInputValue(255, p, q);
break;
default:
_setRGBInputValue(0,0,0);
_setRGBInputValue(0, 0, 0);
break;
}
}
@ -270,9 +280,9 @@ void _fromKelvin(unsigned long kelvin, bool setMireds) {
: 138.5177312231 * log(kelvin - 10) - 305.0447927307);
_setRGBInputValue(
constrain(red, 0, LIGHT_MAX_VALUE),
constrain(green, 0, LIGHT_MAX_VALUE),
constrain(blue, 0, LIGHT_MAX_VALUE)
constrain(red, 0, LIGHT_MAX_VALUE),
constrain(green, 0, LIGHT_MAX_VALUE),
constrain(blue, 0, LIGHT_MAX_VALUE)
);
}


+ 3041
- 3039
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 1
- 1
code/html/index.html View File

@ -408,7 +408,7 @@
<div class="pure-u-1 pure-u-lg-1-4"><input type="checkbox" name="useWhite" action="reload" tabindex="9" /></div>
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use forth dimmable channel as white when first 3 have the same RGB value.<br />Will only work if the device has at least 4 dimmable channels.<br />Reload the page to update the web interface.</div>
<div class="pure-u-1 pure-u-lg-3-4 hint">Use forth dimmable channel as white when first 3 have the same RGB value.<br />Will only work if the device has at least 4 dimmable channels.<br />Enabling this will render useless the "Channel 4" slider in the status page.<br />Reload the page to update the web interface.</div>
</div>
<div class="pure-g">


Loading…
Cancel
Save