diff --git a/Color Loop/module.php b/Color Loop/module.php index 1720dc9..2205353 100644 --- a/Color Loop/module.php +++ b/Color Loop/module.php @@ -45,21 +45,21 @@ public function Create() // Status variable (active) $exists = @$this->GetIDForIdent('active'); $this->RegisterVariableBoolean('active', $this->Translate('Active'), '~Switch', 0); - if($exists === false) { + if ($exists === false) { $this->SetValueBoolean('active', true); } $this->EnableAction('active'); // Status variable (increment) $exists = @$this->GetIDForIdent('increment'); $this->RegisterVariableInteger('increment', $this->Translate('Increment'), 'WWXCL.Increment', 1); - if($exists === false) { + if ($exists === false) { $this->SetValueInteger('increment', 5); } $this->EnableAction('increment'); // Status variable (transition) $exists = @$this->GetIDForIdent('transition'); $vid = $this->RegisterVariableInteger('transition', $this->Translate('Transition'), 'WWXCL.Transition', 2); - if($exists === false) { + if ($exists === false) { $this->SetValueInteger('transition', 5); } $this->EnableAction('transition'); @@ -119,11 +119,11 @@ public function ApplyChanges() foreach ($list as &$line) { if (IPS_VariableExists($line['Variable'])) { $this->RegisterReference($line['Variable']); - if($this->GetVariableProfile($line['Variable']) != '~HexColor') { + if ($this->GetVariableProfile($line['Variable']) != '~HexColor') { $this->SendDebug(__FUNCTION__, $line['Variable'] . 'has wrong Profile!'); $profile = false; } - if(empty($line['Name'])) { + if (empty($line['Name'])) { $this->SendDebug(__FUNCTION__, $line['Variable'] . 'has no Name!'); $name = false; } @@ -136,12 +136,12 @@ public function ApplyChanges() } } // No lights - if($count == 0) { + if ($count == 0) { $this->SetStatus(202); return; } // Wrong Profile - if($profile != true) { + if ($profile != true) { $this->SetStatus(203); return; } @@ -222,7 +222,7 @@ public function RequestAction($ident, $value) default: // should only be 'color_xxxxx' $this->SetValueInteger($ident, $value); - break; + break; } return true; } @@ -235,11 +235,11 @@ public function RequestAction($ident, $value) private function Active($value) { $this->SendDebug(__FUNCTION__, $value); - if($value) { // Acvitvate + if ($value) { // Acvitvate $vid = $this->ReadPropertyInteger('StateVariable'); if (IPS_VariableExists($vid)) { $value = GetValue($vid); // no modul getvalue!!! - if($value) { + if ($value) { $this->SendDebug(__FUNCTION__, 'Activate now!'); $this->Switch(true); } else { @@ -262,14 +262,14 @@ private function Switch($value) $this->SendDebug(__FUNCTION__, ($value ? 'true' : 'false')); $cact = $this->ReadPropertyBoolean('CheckActive'); $ccon = $this->ReadPropertyBoolean('CheckContinue'); - if($value) { // ON + if ($value) { // ON $ison = $this->GetValue('active'); - if($cact && !$ison) { + if ($cact && !$ison) { $ison = true; $this->SetValueBoolean('active', $ison); } // only if color loop is active switched! - if($ison) { + if ($ison) { $tran = $this->GetValue('transition'); $this->SendDebug(__FUNCTION__, 'Trans: ' . $tran); $ccol = $this->ReadPropertyBoolean('CheckColor'); @@ -285,14 +285,14 @@ private function Switch($value) $color = $this->GetValue($ident); } // color is transparent then from light - if($color == -1) { + if ($color == -1) { $color = GetValue($varid); } $data[] = [$varid, $color]; } $this->SendDebug(__FUNCTION__, 'Data: ' . print_r($data, true), 0); $buffer = $this->GetBuffer('loop_data'); - if(!$ccon || empty($buffer)) { + if (!$ccon || empty($buffer)) { $this->SetBuffer('loop_data', serialize($data)); } // Start Timer @@ -301,7 +301,7 @@ private function Switch($value) } else { // OFF $this->SetTimerInterval('ColorLoopTrigger', 0); // continue with the last colors? - if(!$ccon) { + if (!$ccon) { $this->SetBuffer('loop_data', ''); } } @@ -318,7 +318,7 @@ private function Cycle() $step = $this->GetValue('increment'); $this->SendDebug(__FUNCTION__, 'Step size: ' . $step); $next = []; - foreach($last as $index => $data) { + foreach ($last as $index => $data) { $this->SendDebug(__FUNCTION__, '(1): ' . $data[1]); $rgb = $this->int2rgb($data[1]); $this->SendDebug(__FUNCTION__, '(2): ' . $rgb[0] . ', ' . $rgb[1] . ', ' . $rgb[2]); diff --git a/libs/ColorHelper.php b/libs/ColorHelper.php index bc2e5b4..a8f82b7 100644 --- a/libs/ColorHelper.php +++ b/libs/ColorHelper.php @@ -57,7 +57,7 @@ private function str2rgb(string $str): array { $str = preg_replace('~[^0-9a-f]~', '', $str); $rgb = str_split($str, 2); - for($i = 0; $i < 3; $i++) { + for ($i = 0; $i < 3; $i++) { $rgb[$i] = intval($rgb[$i], 16); } return $rgb; @@ -90,13 +90,13 @@ private function rgb2hsl(int $r, int $g, int $b): array case $r: $h = 60 * fmod((($g - $b) / $d), 6); if ($b > $g) $h += 360; - break; + break; case $g: $h = 60 * (($b - $r) / $d + 2); break; case $b: $h = 60 * (($r - $g) / $d + 4); - break; + break; } } return [intval(round($h, 0)), intval(round($s * 100, 0)), intval(round($l * 100, 0))]; @@ -117,17 +117,29 @@ private function hsl2rgb(int $h, int $s, int $l): array $x = $c * (1 - abs(fmod(($h / 60), 2) - 1)); $m = ($l / 100) - ($c / 2); if ($h < 60) { - $r = $c; $g = $x; $b = 0; + $r = $c; + $g = $x; + $b = 0; } elseif ($h < 120) { - $r = $x; $g = $c; $b = 0; + $r = $x; + $g = $c; + $b = 0; } elseif ($h < 180) { - $r = 0; $g = $c; $b = $x; + $r = 0; + $g = $c; + $b = $x; } elseif ($h < 240) { - $r = 0; $g = $x; $b = $c; + $r = 0; + $g = $x; + $b = $c; } elseif ($h < 300) { - $r = $x; $g = 0; $b = $c; + $r = $x; + $g = 0; + $b = $c; } else { - $r = $c; $g = 0; $b = $x; + $r = $c; + $g = 0; + $b = $x; } return [floor(($r + $m) * 255), floor(($g + $m) * 255), floor(($b + $m) * 255)]; }