From 4b749bf04f18e4161c87dfe1bf6a2f45552bd1d2 Mon Sep 17 00:00:00 2001 From: Ellert Date: Wed, 18 Oct 2017 16:26:58 +0000 Subject: [PATCH] 98_DOIFtools: add getter hsvColorGradient, returns a table of value, colornumber, RGB values and color bar using Color::hsv2rgb git-svn-id: https://svn.fhem.de/fhem/trunk@15281 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 ++ fhem/FHEM/98_DOIFtools.pm | 75 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 535fa4844..f1462b6b9 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: 98_DOIFtools: add getter hsvColorGradient, returns a table of + value, colornumber, RGB values and color bar using Color::hsv2rgb - new: 46_TeslaPowerwall2AC: retrieves data from a Tesla Powerwall 2AC - bugfix: 21_HEOSMaster: fix typo in define Fn - feature: 93_DbRep: V5.8.0, can set table as flexible argument for command diff --git a/fhem/FHEM/98_DOIFtools.pm b/fhem/FHEM/98_DOIFtools.pm index 28b28b6a7..fdfb3d2cc 100644 --- a/fhem/FHEM/98_DOIFtools.pm +++ b/fhem/FHEM/98_DOIFtools.pm @@ -706,6 +706,29 @@ sub DOIFtoolsLinColorGrad { return $prefix.join("",@rgb); } +sub DOIFtoolsHsvColorGrad { + my ($cur,$min,$max,$min_s,$max_s,$s,$v)=@_; + + my $m=($max_s-$min_s)/($max-$min); + my $n=$min_s-$min*$m; + if ($cur>$max) { + $cur=$max; + } elsif ($cur<$min) { + $cur=$min; + } + + my $h=$cur*$m+$n; + $h /=360; + $s /=100; + $v /=100; + + my($r,$g,$b)=Color::hsv2rgb ($h,$s,$v); + $r *= 255; + $g *= 255; + $b *= 255; + return sprintf("#%02X%02X%02X", $r+0.5, $g+0.5, $b+0.5); +} + sub DOIFtoolsRg { my ($hash,$arg) = @_; @@ -1535,6 +1558,56 @@ Syntax: <start color number>,<end color number>,<minimal va
  • <step width>, for each step a color number will be generated, example: 1.
  • Example specification: #0000FF,#FF0000,7,30,1 +
    ";
    +        return $ret
    +      }
    +  } elsif ($arg eq "hsvColorGradient") {
    +      my ($min_s,$max_s,$min,$max,$step,$s,$v)=split(",",$value);
    +      if ($value && $s >= 0 && $s <= 100 && $v >= 0 && $v <= 100  && $min_s >= 0 && $min_s <= 360 && $max_s >= 0 && $max_s <= 360) {
    +        $ret .= "
    "; + $ret .= ""; + $ret .= ""; + $ret .= ""; + for (my $i=$min;$i<=$max;$i+=$step) { + my $col = DOIFtoolsHsvColorGrad($i,$min,$max,$min_s,$max_s,$s,$v); + $col =~ /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/; + $ret .= ""; + } + $ret .= "
    Color Table
    "; + for (my $i=0;$i<=127;$i++) { + my $col = DOIFtoolsHsvColorGrad($i,0,127,$min_s,$max_s,$s,$v); + $ret .= " "; + } + $ret .= "
    Value Color Number RGB values Color
    ".sprintf("%.1f",$i)."$col ".hex($1).",".hex($2).",".hex($3)."       
    ";
    +        
    +       return $ret;
    +      } else {
    +        $ret = $DE ? "
    +Falsche Eingabe: $value
    +Syntax: <HUE-Startwert>,<HUE-Endwert>,<Minimalwert>,<Maximalwert>,<Schrittweite>,<Sättigung>,<Hellwert>
    + +Beispielangabe: 240,360,7,30,1,80,80 +
    ":"
    +Wrong input: $value
    +Syntax: <HUE start value>,<HUE end value>,<minimal value>,<maximal value>,<step width>,<saturation>,<lightness>
    + +Example specification: 240,360,7,30,1,80,80
    ";
             return $ret
           }
    @@ -1623,7 +1696,7 @@ Example specifications:
    return $ret; } else { my $hardcoded = "checkDOIF:noArg statisticsReport:noArg runningTimerInDOIF:noArg"; - return "unknown argument $arg for $pn, choose one of readingsGroup_for:multiple-strict,$dL DOIF_to_Log:multiple-strict,$dL SetAttrIconForDOIF:multiple-strict,$dL userReading_nextTimer_for:multiple-strict,$ntL ".(AttrVal($pn,"DOIFtoolsHideGetSet",0) ? $hardcoded :"")." linearColorGradient:textField modelColorGradient:textField"; + return "unknown argument $arg for $pn, choose one of readingsGroup_for:multiple-strict,$dL DOIF_to_Log:multiple-strict,$dL SetAttrIconForDOIF:multiple-strict,$dL userReading_nextTimer_for:multiple-strict,$ntL ".(AttrVal($pn,"DOIFtoolsHideGetSet",0) ? $hardcoded :"")." linearColorGradient:textField modelColorGradient:textField hsvColorGradient:textField"; } return $ret;