1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace DaveRandom\LibLifxLan\DataTypes\Light; |
4
|
|
|
|
5
|
|
|
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException; |
6
|
|
|
use const DaveRandom\LibLifxLan\UINT32_MAX; |
7
|
|
|
use const DaveRandom\LibLifxLan\UINT32_MIN; |
8
|
|
|
|
9
|
|
|
final class Effect |
10
|
|
|
{ |
11
|
|
|
public const SET_HUE = 0b0001; |
12
|
|
|
public const SET_SATURATION = 0b0010; |
13
|
|
|
public const SET_BRIGHTNESS = 0b0100; |
14
|
|
|
public const SET_TEMPERATURE = 0b1000; |
15
|
|
|
public const SET_ALL = self::SET_HUE | self::SET_SATURATION | self::SET_BRIGHTNESS | self::SET_TEMPERATURE; |
16
|
|
|
|
17
|
|
|
private $transient; |
18
|
|
|
private $color; |
19
|
|
|
private $period; |
20
|
|
|
private $cycles; |
21
|
|
|
private $skewRatio; |
22
|
|
|
private $waveform; |
23
|
|
|
private $options; |
24
|
|
|
|
25
|
32 |
|
private function setTransient(bool $transient): void |
26
|
|
|
{ |
27
|
32 |
|
$this->transient = $transient; |
28
|
|
|
} |
29
|
|
|
|
30
|
32 |
|
private function setColor(HsbkColor $color): void |
31
|
|
|
{ |
32
|
32 |
|
$this->color = $color; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param int $period |
37
|
|
|
* @throws InvalidValueException |
38
|
|
|
*/ |
39
|
32 |
|
private function setPeriod(int $period): void |
40
|
|
|
{ |
41
|
32 |
|
if ($period < UINT32_MIN || $period > UINT32_MAX) { |
42
|
2 |
|
throw new InvalidValueException( |
43
|
2 |
|
"Period {$period} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
30 |
|
$this->period = $period; |
48
|
|
|
} |
49
|
|
|
|
50
|
30 |
|
private function setCycles(float $cycles): void |
51
|
|
|
{ |
52
|
30 |
|
$this->cycles = $cycles; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param int $skewRatio |
57
|
|
|
* @throws InvalidValueException |
58
|
|
|
*/ |
59
|
30 |
|
private function setSkewRatio(int $skewRatio): void |
60
|
|
|
{ |
61
|
30 |
|
if ($skewRatio < -32768 || $skewRatio > 32767) { |
62
|
4 |
|
throw new InvalidValueException("Skew ratio {$skewRatio} outside allowable range of -32768 - 32767"); |
63
|
|
|
} |
64
|
|
|
|
65
|
26 |
|
$this->skewRatio = $skewRatio; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param int $waveform |
70
|
|
|
* @throws InvalidValueException |
71
|
|
|
*/ |
72
|
26 |
|
private function setWaveform(int $waveform): void |
73
|
|
|
{ |
74
|
26 |
|
if ($waveform < 0 || $waveform > 255) { |
75
|
4 |
|
throw new InvalidValueException("Waveform {$waveform} outside allowable range of 0 - 255"); |
76
|
|
|
} |
77
|
|
|
|
78
|
22 |
|
$this->waveform = $waveform; |
79
|
|
|
} |
80
|
|
|
|
81
|
22 |
|
private function setOptions(int $options): void |
82
|
|
|
{ |
83
|
22 |
|
$this->options = $options; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param bool $transient |
88
|
|
|
* @param HsbkColor $color |
89
|
|
|
* @param int $period |
90
|
|
|
* @param float $cycles |
91
|
|
|
* @param int $skewRatio |
92
|
|
|
* @param int $waveform |
93
|
|
|
* @param int $options |
94
|
|
|
* @throws InvalidValueException |
95
|
|
|
*/ |
96
|
32 |
|
public function __construct( |
97
|
|
|
bool $transient, |
98
|
|
|
HsbkColor $color, |
99
|
|
|
int $period, |
100
|
|
|
float $cycles, |
101
|
|
|
int $skewRatio, |
102
|
|
|
int $waveform, |
103
|
|
|
int $options = self::SET_ALL |
104
|
|
|
) { |
105
|
32 |
|
$this->setTransient($transient); |
106
|
32 |
|
$this->setColor($color); |
107
|
32 |
|
$this->setPeriod($period); |
108
|
30 |
|
$this->setCycles($cycles); |
109
|
30 |
|
$this->setSkewRatio($skewRatio); |
110
|
26 |
|
$this->setWaveform($waveform); |
111
|
22 |
|
$this->setOptions($options); |
112
|
|
|
} |
113
|
|
|
|
114
|
2 |
|
public function isTransient(): bool |
115
|
|
|
{ |
116
|
2 |
|
return $this->transient; |
117
|
|
|
} |
118
|
|
|
|
119
|
2 |
|
public function getColor(): HsbkColor |
120
|
|
|
{ |
121
|
2 |
|
return $this->color; |
122
|
|
|
} |
123
|
|
|
|
124
|
2 |
|
public function getPeriod(): int |
125
|
|
|
{ |
126
|
2 |
|
return $this->period; |
127
|
|
|
} |
128
|
|
|
|
129
|
2 |
|
public function getCycles(): float |
130
|
|
|
{ |
131
|
2 |
|
return $this->cycles; |
132
|
|
|
} |
133
|
|
|
|
134
|
2 |
|
public function getSkewRatio(): int |
135
|
|
|
{ |
136
|
2 |
|
return $this->skewRatio; |
137
|
|
|
} |
138
|
|
|
|
139
|
2 |
|
public function getWaveform(): int |
140
|
|
|
{ |
141
|
2 |
|
return $this->waveform; |
142
|
|
|
} |
143
|
|
|
|
144
|
2 |
|
public function getOptions(): int |
145
|
|
|
{ |
146
|
2 |
|
return $this->options; |
147
|
|
|
} |
148
|
|
|
|
149
|
2 |
|
public function hasOption(int $option): bool |
150
|
|
|
{ |
151
|
2 |
|
return (bool)($this->options & $option); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|