2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

added realtimePicker option

git-svn-id: https://svn.fhem.de/fhem/trunk@4405 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2013-12-16 23:27:12 +00:00
parent f1f3a5cbee
commit c8efc64bfe
3 changed files with 45 additions and 11 deletions

View File

@ -60,6 +60,7 @@ sub HUEDevice_Initialize($)
$hash->{GetFn} = "HUEDevice_Get"; $hash->{GetFn} = "HUEDevice_Get";
$hash->{AttrList} = "IODev ". $hash->{AttrList} = "IODev ".
"delayedUpdate:1 ". "delayedUpdate:1 ".
"realtimePicker:1 ".
"color-icons:1,2 ". "color-icons:1,2 ".
"model:".join(",", sort keys %hueModels)." ". "model:".join(",", sort keys %hueModels)." ".
"subType:colordimmer,dimmer,switch ". "subType:colordimmer,dimmer,switch ".
@ -312,6 +313,8 @@ HUEDevice_SetParam($$@)
$defs{$name}->{fhem}->{update_timeout} = 1; $defs{$name}->{fhem}->{update_timeout} = 1;
} elsif( $cmd eq "immediateUpdate" ) { } elsif( $cmd eq "immediateUpdate" ) {
$defs{$name}->{fhem}->{update_timeout} = 0; $defs{$name}->{fhem}->{update_timeout} = 0;
} elsif( $cmd eq "noUpdate" ) {
$defs{$name}->{fhem}->{update_timeout} = -1;
} else { } else {
return 0; return 0;
} }
@ -345,6 +348,18 @@ HUEDevice_Set($@)
HUEDevice_SetParam($name, \%obj, $cmd, $value, $value2); HUEDevice_SetParam($name, \%obj, $cmd, $value, $value2);
} }
# if( $defs{$name}->{fhem}->{update_timeout} == -1 ) {
# my $diff;
# my ($seconds, $microseconds) = gettimeofday();
# if( $defs{$name}->{fhem}->{timestamp} ) {
# my ($seconds2, $microseconds2) = @{$defs{$name}->{fhem}->{timestamp}};
#
# $diff = (($seconds-$seconds2)*1000000 + $microseconds-$microseconds2)/1000;
# }
# $defs{$name}->{fhem}->{timestamp} = [$seconds, $microseconds];
#
# return undef if( $diff < 100 );
# }
if( scalar keys %obj ) { if( scalar keys %obj ) {
my $result; my $result;
@ -358,7 +373,8 @@ HUEDevice_Set($@)
return undef; return undef;
} }
if( $defs{$name}->{fhem}->{update_timeout} if( $defs{$name}->{fhem}->{update_timeout} == -1 ) {
} elsif( $defs{$name}->{fhem}->{update_timeout}
&& !$hash->{fhem}->{group} ) { && !$hash->{fhem}->{group} ) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
InternalTimer(gettimeofday()+1, "HUEDevice_GetUpdate", $hash, 1); InternalTimer(gettimeofday()+1, "HUEDevice_GetUpdate", $hash, 1);

View File

@ -46,6 +46,13 @@ FHEM_colorpickerFn($$$)
'border:1px solid #fff;border-radius:8px;background-color:#'. $args[1] .';"></div>'. 'border:1px solid #fff;border-radius:8px;background-color:#'. $args[1] .';"></div>'.
'</a>'. '</a>'.
'</td>'; '</td>';
} elsif(AttrVal($d,"realtimePicker",0)) {
my $c = "$FW_ME?XHR=1&cmd=set $d $cmd %$srf";
my $ci = $c;
$ci = "$FW_ME?XHR=1&cmd=set $d $cmd % : transitiontime 0 : noUpdate$srf" if($defs{$d}->{TYPE} eq "HUEDevice");
return '<td align="center">'.
"<input maxlength='6' size='6' id='colorpicker.$d-RGB' class=\"color {pickerMode:'$mode',pickerFaceColor:'transparent',pickerFace:3,pickerBorder:0,pickerInsetColor:'red',command:'$ci',onImmediateChange:'colorpicker_setColor(this)'}\" value='$cv' onChange='colorpicker_setColor(this,\"$mode\",\"$c\")'>".
'</td>';
} else { } else {
my $c = "$FW_ME?XHR=1&cmd=set $d $cmd %$srf"; my $c = "$FW_ME?XHR=1&cmd=set $d $cmd %$srf";
return '<td align="center">'. return '<td align="center">'.
@ -112,7 +119,7 @@ RgbToChannels($$) {
sub sub
ChannelsToRgb(@) { ChannelsToRgb(@) {
my @channels = @_; my @channels = @_;
return sprintf("%02X" x @_, @_); return sprintf("%02X" x @_, @_);
} }
sub sub
@ -124,14 +131,15 @@ ChannelsToBrightness(@) {
$max = $value if ($max < $value); $max = $value if ($max < $value);
} }
return {
bri => 0,
channels => \(255 x @channels),
} unless ($max > 0);
my @bri = (); my @bri = ();
if( $max == 0) { my $norm = 255/$max;
@bri = (0) x @channels; foreach my $value (@channels) {
} else { push @bri,int($value*$norm);
my $norm = 255/$max;
foreach my $value (@channels) {
push @bri,int($value*$norm);
}
} }
return { return {

View File

@ -9,13 +9,23 @@ FW_colorpickerUpdateLine(d)
if(el) { if(el) {
el.color.fromString(d[1]); el.color.fromString(d[1]);
} }
} }
function function
colorpicker_setColor(el,mode,cmd) colorpicker_setColor(el,mode,cmd)
{ {
var v = el.color; var v = el.color;
if(mode==undefined) {
mode=el.pickerMode;
}
if(cmd==undefined) {
cmd=el.command;
}
if(v==undefined) {
v=el.toString();
}
if(mode=="HSV") { if(mode=="HSV") {
v = (0x100 | Math.round(42*el.color.hsv[0])).toString(16).substr(1) + v = (0x100 | Math.round(42*el.color.hsv[0])).toString(16).substr(1) +
(0x100 | Math.round(255*el.color.hsv[1])).toString(16).substr(1) + (0x100 | Math.round(255*el.color.hsv[1])).toString(16).substr(1) +
@ -31,7 +41,7 @@ colorpicker_setColor(el,mode,cmd)
document.location = cmd.replace('%',v); document.location = cmd.replace('%',v);
} }
FW_widgets['colorpicker'] = { FW_widgets['colorpicker'] = {
updateLine:FW_colorpickerUpdateLine updateLine:FW_colorpickerUpdateLine
}; };