From 504fac620ffa54198ba14375918a084e2084ab37 Mon Sep 17 00:00:00 2001 From: markus-m <> Date: Sun, 31 Jan 2016 02:25:17 +0000 Subject: [PATCH] 30_MilightBridge/31_MilightDevice: Bugfixes, color change on low dim level git-svn-id: https://svn.fhem.de/fhem/trunk@10674 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/30_MilightBridge.pm | 1 + fhem/FHEM/31_MilightDevice.pm | 32 ++++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 9c3d24a61..96761efb8 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 31_MilightDevice: Color changes during dim on lower brightness + - bugfix: 30_MilightBridge/31_MilightDevice: Variable fallbacks, colorcast - bugfix: 44_TEK603: fixed wrong values. - bugfix: 49_SSCam: fixed the problem a recording may still stay active if fhem will be restarted after a recording was triggered and diff --git a/fhem/FHEM/30_MilightBridge.pm b/fhem/FHEM/30_MilightBridge.pm index 769efd3c3..d7407e69d 100644 --- a/fhem/FHEM/30_MilightBridge.pm +++ b/fhem/FHEM/30_MilightBridge.pm @@ -125,6 +125,7 @@ sub MilightBridge_Attr($$$$) { my ($command,$name,$attribute,$value) = @_; my $hash = $defs{$name}; + $value = "" if(!defined($value)); Log3 ($hash, 5, "$hash->{NAME}_Attr: Attr $attribute; Value $value"); # Handle "sendInterval" attribute which defaults to 100(ms) diff --git a/fhem/FHEM/31_MilightDevice.pm b/fhem/FHEM/31_MilightDevice.pm index 0115e9169..4cb23651a 100644 --- a/fhem/FHEM/31_MilightDevice.pm +++ b/fhem/FHEM/31_MilightDevice.pm @@ -190,6 +190,7 @@ sub MilightDevice_Define($$) } $hash->{helper}->{GAMMAMAP} = MilightDevice_CreateGammaMapping($hash, 1.0); + $hash->{helper}->{COLORMAP} = MilightDevice_ColorConverter($hash, split(',', "0,0,0,0,0,0")); # Define devStateIcon @@ -237,7 +238,7 @@ sub MilightDevice_Init($) if (($hash->{LEDTYPE} eq 'RGBW') || ($hash->{LEDTYPE} eq 'RGB')) { my @a = split(',', "0,0,0,0,0,0"); - if ( defined($hash->{".colorCast"} ) ) + if ( defined( $attr{$name}{colorCast} ) ) { @a = split(',', AttrVal($hash->{NAME}, "colorCast", "0,0,0,0,0,0")); @a = split(',', "0,0,0,0,0,0") unless (@a == 6); @@ -281,6 +282,7 @@ sub MilightDevice_Set(@) if ($hash->{IODev}->{STATE} ne "ok" && $hash->{IODev}->{STATE} ne "Initialized") { readingsSingleUpdate($hash, "state", "error", 1); $flags = "q"; + $args[2] = "" if(!defined($args[2])); $args[2] .= "q" if ($args[2] !~ m/.*[qQ].*/); # return SetExtensions($hash, $hash->{helper}->{COMMANDSET}, $name, $cmd, @args); # IO error, we need to keep our current state settings! @@ -1071,9 +1073,11 @@ sub MilightDevice_RGBW_SetHSV(@) $repeat = 1 if (!defined($repeat)); - my $cv = 0; - $cv = $hash->{helper}->{COLORMAP}[$hue % 360]; - $cv = 0 if(!defined($cv)); + my $cv = $hash->{helper}->{COLORMAP}[$hue % 360]; + + #check dim levels to decide wether to change color or brightness first + my $dimup = 0; + $dimup = 1 if($val > ReadingsVal($hash->{NAME}, "brightness", 100)); # apply gamma correction my $gammaVal = $hash->{helper}->{GAMMAMAP}[$val]; @@ -1094,7 +1098,7 @@ sub MilightDevice_RGBW_SetHSV(@) $sat = 100; } - Log3 ($hash, 5, "MilightDevice_RGBW_SetHSV: wl: $wl; cl: $cl; cv: $cv"); + Log3 ($hash, 5, "MilightDevice_RGBW_SetHSV: h:$hue s:$sat v:$val / cv:$cv wl:$wl cl:$cl "); # Set readings in FHEM MilightDevice_SetHSV_Readings($hash, $hue, $sat, $val); @@ -1124,12 +1128,24 @@ sub MilightDevice_RGBW_SetHSV(@) elsif ($cl > 0) # color { IOWrite($hash, @RGBWCmdsOn[$hash->{SLOTID} -5]."\x00".$RGBWCmdEnd) if (($wl > 0) || ($cl > 0)); # group on + if($dimup) + { IOWrite($hash, $RGBWCmdCol.chr($cv).$RGBWCmdEnd); # color IOWrite($hash, $RGBWCmdBri.chr($cl).$RGBWCmdEnd); # brightness + } else { + IOWrite($hash, $RGBWCmdBri.chr($cl).$RGBWCmdEnd); # brightness + IOWrite($hash, $RGBWCmdCol.chr($cv).$RGBWCmdEnd); # color + } if ($repeat eq 1) { IOWrite($hash, @RGBWCmdsOn[$hash->{SLOTID} -5]."\x00".$RGBWCmdEnd) if (($wl > 0) || ($cl > 0)); # group on + if($dimup) + { IOWrite($hash, $RGBWCmdCol.chr($cv).$RGBWCmdEnd); # color IOWrite($hash, $RGBWCmdBri.chr($cl).$RGBWCmdEnd); # brightness + } else { + IOWrite($hash, $RGBWCmdBri.chr($cl).$RGBWCmdEnd); # brightness + IOWrite($hash, $RGBWCmdCol.chr($cv).$RGBWCmdEnd); # color + } } } @@ -1665,7 +1681,7 @@ sub MilightDevice_HSV_Transition(@) $hueFrom = ReadingsVal($hash->{NAME}, "hue", 0); $satFrom = ReadingsVal($hash->{NAME}, "saturation", 0); $valFrom = ReadingsVal($hash->{NAME}, "brightness", 0); - $timeFrom = gettimeofday(); + $timeFrom = int(gettimeofday()); Log3 ($hash, 5, "$hash->{NAME}_HSV_Transition: Prepare Start (actual): $hueFrom,$satFrom,$valFrom@".$timeFrom); @@ -1777,7 +1793,7 @@ sub MilightDevice_HSV_Transition(@) } # Set target time for completion of sequence. # This may be slightly higher than what was requested since $stepWidth > minDelay (($steps * $stepWidth) > $ramp) - $hash->{helper}->{targetTime} = $timeFrom + ($steps * $stepWidth / 1000); + $hash->{helper}->{targetTime} = int($timeFrom + ($steps * $stepWidth / 1000)); Log3 ($hash, 5, "$hash->{NAME}_HSV_Transition: TargetTime: $hash->{helper}->{targetTime}"); return undef; } @@ -2050,7 +2066,7 @@ sub MilightDevice_CmdQueue_Exec(@) MilightDevice_SetHSV($hash, $actualCmd->{hue}, $actualCmd->{sat}, $actualCmd->{val}, $repeat); } $actualCmd->{inProgess} = 1; - my $next = defined($nextCmd->{targetTime})?$nextCmd->{targetTime}:gettimeofday() + ($actualCmd->{delay} / 1000); + my $next = defined($nextCmd->{targetTime})?$nextCmd->{targetTime}:int(gettimeofday() + ($actualCmd->{delay} / 1000)); Log3 ($hash, 5, "$hash->{NAME}_CmdQueue_Exec: Next Exec: $next"); InternalTimer($next, "MilightDevice_CmdQueue_Exec", $hash, 0);