@ -77,47 +77,57 @@ const unsigned char _light_gamma_table[] = {
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void _setRGBInputValue ( unsigned char red , unsigned char green , unsigned char blue ) {
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 ( ) {
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 ) ;
_setRGBInputValue ( 255 , p , q ) ;
break ;
break ;
default :
default :
_setRGBInputValue ( 0 , 0 , 0 ) ;
_setRGBInputValue ( 0 , 0 , 0 ) ;
break ;
break ;
}
}
}
}
@ -270,9 +280,9 @@ void _fromKelvin(unsigned long kelvin, bool setMireds) {
: 138.5177312231 * log ( kelvin - 10 ) - 305.0447927307 ) ;
: 138.5177312231 * log ( kelvin - 10 ) - 305.0447927307 ) ;
_setRGBInputValue (
_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 )
) ;
) ;
}
}