Adding more directory structure to generated files by compiler, also script to copy...
[iot2.git] / others / tutorial / benchmarks / drivers / SmartLightBulb / BulbColor.java
1 package iotcode.LifxLightBulb;
2
3 import java.security.InvalidParameterException;
4
5 public class BulbColor {
6
7         private int hue;
8         private int saturation;
9         private int brightness;
10         private int kelvin;
11
12         public BulbColor(int _hue, int _saturation, int _brightness, int _kelvin) {
13
14                 if ((hue > 65535) || (hue < 0)) {
15                         throw new InvalidParameterException("BulbColor: Invalid parameter value for _hue (0-65535)");
16                 }
17
18                 if ((saturation > 65535) || (saturation < 0)) {
19                         throw new InvalidParameterException("BulbColor: Invalid parameter value for _saturation (0-65535)");
20                 }
21
22                 if ((brightness > 65535) || (brightness < 0)) {
23                         throw new InvalidParameterException("BulbColor: Invalid parameter value for _brightness (0-65535)");
24                 }
25
26                 if ((kelvin > 65535) || (kelvin < 0)) {
27                         throw new InvalidParameterException("BulbColor: Invalid parameter value for _kelvin (0-65535)");
28                 }
29
30                 hue = _hue;
31                 saturation = _saturation;
32                 brightness = _brightness;
33                 kelvin = _kelvin;
34         }
35
36         public BulbColor(byte[] data) {
37                 hue = ((data[1] & 0xFF) << 8);
38                 hue |= (data[0] & 0xFF);
39
40                 saturation = ((data[3] & 0xFF) << 8);
41                 saturation |= (data[2] & 0xFF);
42
43                 brightness = ((data[5] & 0xFF) << 8);
44                 brightness |= (data[4] & 0xFF);
45
46                 kelvin = ((data[7] & 0xFF) << 8);
47                 kelvin |= (data[6] & 0xFF);
48         }
49
50         public int getHue() {
51                 return hue;
52         }
53
54         public int getSaturation() {
55                 return saturation;
56         }
57
58         public int getBrightness() {
59                 return brightness;
60         }
61
62         public int getKelvin() {
63                 return kelvin;
64         }
65 }
66
67