mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-16 23:06:05 +00:00
31_HUEDevice.pm: allow ct presets in webCmd
git-svn-id: https://svn.fhem.de/fhem/trunk@7282 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
909ead6946
commit
680e27717c
2989
fhem/CHANGED
2989
fhem/CHANGED
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,8 @@ use POSIX;
|
||||
use JSON;
|
||||
use SetExtensions;
|
||||
|
||||
use vars qw(%FW_webArgs); # all arguments specified in the GET
|
||||
|
||||
my %hueModels = (
|
||||
LCT001 => {name => 'Hue Bulb' ,type => 'Extended Color light' ,subType => 'colordimmer',},
|
||||
LCT002 => {name => 'Hue Bulb BR30' ,type => 'Extended Color light' ,subType => 'colordimmer',},
|
||||
@ -454,7 +456,13 @@ HUEDevice_Set($@)
|
||||
$list .= " pct:slider,0,1,100 bri:slider,0,1,254 alert:none,select,lselect" if( AttrVal($name, "subType", "colordimmer") =~ m/dimmer/ );
|
||||
$list .= " dimUp:noArg dimDown:noArg" if( !$hash->{helper}->{group} && AttrVal($name, "subType", "colordimmer") =~ m/dimmer/ );
|
||||
#$list .= " dim06% dim12% dim18% dim25% dim31% dim37% dim43% dim50% dim56% dim62% dim68% dim75% dim81% dim87% dim93% dim100%" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/dimmer/ );
|
||||
$list .= " rgb:colorpicker,RGB color:slider,2000,1,6500 ct:slider,154,1,500 hue:slider,0,1,65535 sat:slider,0,1,254 xy effect:none,colorloop" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ );
|
||||
if( defined($FW_webArgs{detail}) ) {
|
||||
$list .= " rgb color:slider,2000,1,6500 ct" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ );
|
||||
} else {
|
||||
$list .= " rgb:colorpicker,RGB color:colorpicker,CT,2000,1,6500 ct:colorpicker,CT,154,1,500" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ );
|
||||
}
|
||||
$list .= " hue:slider,0,1,65535 sat:slider,0,1,254 xy effect:none,colorloop" if( AttrVal($hash->{NAME}, "subType", "colordimmer") =~ m/color/ );
|
||||
|
||||
return SetExtensions($hash, $list, $name, @aa);
|
||||
}
|
||||
|
||||
|
@ -22,18 +22,32 @@ FHEM_colorpickerInit()
|
||||
}
|
||||
|
||||
sub
|
||||
FHEM_colorpickerFn($$$)
|
||||
FHEM_colorpickerFn($$$$$)
|
||||
{
|
||||
my ($FW_wname, $d, $FW_room, $cmd, $values) = @_;
|
||||
|
||||
my @args = split("[ \t]+", $cmd);
|
||||
|
||||
return undef if($values !~ m/^colorpicker,(.*)$/);
|
||||
my @value = split( ',', $values );
|
||||
return undef if($values !~ m/^colorpicker,([^,]*)/);
|
||||
|
||||
my ($mode) = ($1);
|
||||
my $mode = $1;
|
||||
$mode = "RGB" if( !defined($mode) );
|
||||
|
||||
my $trigger = $cmd; #default trigger is event from reading with the same name as the command
|
||||
if( $mode eq "CT" ) {
|
||||
if( !$args[1] && $data{webCmdFn}{slider} ) {
|
||||
no strict "refs";
|
||||
my $values = "slider,". join( ',', @value[2..4] );
|
||||
my $htmlTxt = &{$data{webCmdFn}{slider}}($FW_wname, $d, $FW_room, $cmd, $values);
|
||||
use strict "refs";
|
||||
|
||||
return $htmlTxt;
|
||||
}
|
||||
|
||||
return undef if( !$args[1] );
|
||||
}
|
||||
|
||||
my $trigger = $cmd; #default trigger is the event from the reading with the same name as the command
|
||||
my $cv = ReadingsVal($d,$cmd,""); #get default value from this reading
|
||||
if( !$cv ) { #if this reading does not exist ->
|
||||
$trigger = "RGB"; # trigger name will be RGB
|
||||
@ -45,6 +59,13 @@ FHEM_colorpickerFn($$$)
|
||||
if( $args[1] ) {
|
||||
my $c = "cmd=set $d $cmd$srf";
|
||||
|
||||
if( $mode eq "CT" ) {
|
||||
my $ct = $args[1];
|
||||
$ct = int(1000000/$args[1]) if( $ct > 1000 );
|
||||
my ($r, $g, $b) = Color::ct2rgb( $ct );
|
||||
$args[1] = Color::rgb2hex( $r, $g, $b );
|
||||
}
|
||||
|
||||
return '<td align="center">'.
|
||||
"<div onClick=\"FW_cmd('$FW_ME?XHR=1&$c')\" style=\"width:32px;height:19px;".
|
||||
'border:1px solid #fff;border-radius:8px;background-color:#'. $args[1] .';"></div>'.
|
||||
@ -359,4 +380,41 @@ rgb2hex($$$) {
|
||||
return uc($return);
|
||||
}
|
||||
|
||||
sub
|
||||
ct2rgb($)
|
||||
{
|
||||
my ($ct) = @_;
|
||||
|
||||
# calculation from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code
|
||||
# adjusted by 1000K
|
||||
my $temp = (1000000/$ct)/100 + 10;
|
||||
|
||||
my $r = 0;
|
||||
my $g = 0;
|
||||
my $b = 0;
|
||||
|
||||
$r = 255;
|
||||
$r = 329.698727446 * ($temp - 60) ** -0.1332047592 if( $temp > 66 );
|
||||
$r = 0 if( $r < 0 );
|
||||
$r = 255 if( $r > 255 );
|
||||
|
||||
if( $temp <= 66 ) {
|
||||
$g = 99.4708025861 * log($temp) - 161.1195681661;
|
||||
} else {
|
||||
$g = 288.1221695283 * ($temp - 60) ** -0.0755148492;
|
||||
}
|
||||
$g = 0 if( $g < 0 );
|
||||
$g = 255 if( $g > 255 );
|
||||
|
||||
$b = 255;
|
||||
$b = 0 if( $temp <= 19 );
|
||||
if( $temp < 66 ) {
|
||||
$b = 138.5177312231 * log($temp-10) - 305.0447927307;
|
||||
}
|
||||
$b = 0 if( $b < 0 );
|
||||
$b = 255 if( $b > 255 );
|
||||
|
||||
return( $r, $g, $b );
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user