]> git.basschouten.com Git - openhab-addons.git/blob
f32a4ebcaafdfbe9ab0f9e530d93e2b469e9c2e0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyprojector.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
22 import org.openhab.core.types.StateOption;
23 import org.openhab.core.util.HexUtils;
24
25 /**
26  * Represents the different gamma corrections available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorGammaCorrection {
32
33     // Category 1: VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515, VW520,
34     // VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, VW1000ES, VW1100ES, HW50ES, HW55ES,
35     // HW60, HW65, HW68
36     CAT1_18(1, "1.8", null, new byte[] { 0x00, 0x01 }),
37     CAT1_20(1, "2.0", null, new byte[] { 0x00, 0x02 }),
38     CAT1_21(1, "2.1", null, new byte[] { 0x00, 0x03 }),
39     CAT1_22(1, "2.2", null, new byte[] { 0x00, 0x04 }),
40     CAT1_24(1, "2.4", null, new byte[] { 0x00, 0x05 }),
41     CAT1_26(1, "2.6", null, new byte[] { 0x00, 0x06 }),
42     CAT1_GAMMA7(1, "Gamma7", "Gamma 7", new byte[] { 0x00, 0x07 }),
43     CAT1_GAMMA8(1, "Gamma8", "Gamma 8", new byte[] { 0x00, 0x08 }),
44     CAT1_GAMMA9(1, "Gamma9", "Gamma 9", new byte[] { 0x00, 0x09 }),
45     CAT1_GAMMA10(1, "Gamma10", "Gamma 10", new byte[] { 0x00, 0x0A }),
46     CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
47
48     // Category 2: VW40, VW50, VW60, VW100, VW200, HW10
49     CAT2_GAMMA1(2, "Gamma1", "Gamma 1", new byte[] { 0x00, 0x01 }),
50     CAT2_GAMMA2(2, "Gamma2", "Gamma 2", new byte[] { 0x00, 0x02 }),
51     CAT2_GAMMA3(2, "Gamma3", "Gamma 3", new byte[] { 0x00, 0x03 }),
52     CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
53
54     // Category 3: VW70, VW80, HW15, HW20
55     CAT3_GAMMA1(3, "Gamma1", "Gamma 1", new byte[] { 0x00, 0x01 }),
56     CAT3_GAMMA2(3, "Gamma2", "Gamma 2", new byte[] { 0x00, 0x02 }),
57     CAT3_GAMMA3(3, "Gamma3", "Gamma 3", new byte[] { 0x00, 0x03 }),
58     CAT3_GAMMA4(3, "Gamma4", "Gamma 4", new byte[] { 0x00, 0x04 }),
59     CAT3_GAMMA5(3, "Gamma5", "Gamma 5", new byte[] { 0x00, 0x05 }),
60     CAT3_GAMMA6(3, "Gamma6", "Gamma 6", new byte[] { 0x00, 0x06 }),
61     CAT3_OFF(3, "Off", null, new byte[] { 0x00, 0x00 }),
62
63     // Category 4: HW30ES
64     CAT4_GAMMA1(4, "Gamma1", "Gamma 1", new byte[] { 0x00, 0x01 }),
65     CAT4_GAMMA2(4, "Gamma2", "Gamma 2", new byte[] { 0x00, 0x02 }),
66     CAT4_GAMMA3(4, "Gamma3", "Gamma 3", new byte[] { 0x00, 0x03 }),
67     CAT4_GAMMA4(4, "Gamma4", "Gamma 4", new byte[] { 0x00, 0x04 }),
68     CAT4_GAMMA5(4, "Gamma5", "Gamma 5", new byte[] { 0x00, 0x05 }),
69     CAT4_GAMMA6(4, "Gamma6", "Gamma 6", new byte[] { 0x00, 0x06 }),
70     CAT4_GAMMA7(4, "Gamma7", "Gamma 7", new byte[] { 0x00, 0x07 }),
71     CAT4_GAMMA8(4, "Gamma8", "Gamma 8", new byte[] { 0x00, 0x08 }),
72     CAT4_OFF(4, "Off", null, new byte[] { 0x00, 0x00 }),
73
74     // Category 5: VW85, VW90, VW95
75     CAT5_GAMMA1(5, "Gamma1", "Gamma 1", new byte[] { 0x00, 0x01 }),
76     CAT5_GAMMA2(5, "Gamma2", "Gamma 2", new byte[] { 0x00, 0x02 }),
77     CAT5_GAMMA3(5, "Gamma3", "Gamma 3", new byte[] { 0x00, 0x03 }),
78     CAT5_GAMMA4(5, "Gamma4", "Gamma 4", new byte[] { 0x00, 0x04 }),
79     CAT5_GAMMA5(5, "Gamma5", "Gamma 5", new byte[] { 0x00, 0x05 }),
80     CAT5_GAMMA6(5, "Gamma6", "Gamma 6", new byte[] { 0x00, 0x06 }),
81     CAT5_GAMMA7(5, "Gamma7", "Gamma 7", new byte[] { 0x00, 0x07 }),
82     CAT5_GAMMA8(5, "Gamma8", "Gamma 8", new byte[] { 0x00, 0x08 }),
83     CAT5_GAMMA9(5, "Gamma9", "Gamma 9", new byte[] { 0x00, 0x09 }),
84     CAT5_GAMMA10(5, "Gamma10", "Gamma 10", new byte[] { 0x00, 0x0A }),
85     CAT5_OFF(5, "Off", null, new byte[] { 0x00, 0x00 }),
86
87     // Category 6: HW35ES, HW40ES, HW45ES, HW58ES
88     CAT6_20(6, "2.0", null, new byte[] { 0x00, 0x02 }),
89     CAT6_22(6, "2.2", null, new byte[] { 0x00, 0x04 }),
90     CAT6_24(6, "2.4", null, new byte[] { 0x00, 0x05 }),
91     CAT6_GAMMA4(6, "Gamma4", "Gamma 4", new byte[] { 0x00, 0x08 }),
92     CAT6_GAMMA5(6, "Gamma5", "Gamma 5", new byte[] { 0x00, 0x09 }),
93     CAT6_GAMMA6(6, "Gamma6", "Gamma 6", new byte[] { 0x00, 0x0A }),
94     CAT6_OFF(6, "Off", null, new byte[] { 0x00, 0x00 });
95
96     private int category;
97     private String name;
98     private @Nullable String label;
99     private byte[] dataCode;
100
101     /**
102      * Constructor
103      *
104      * @param category a category of projector models for which the gamma correction is available
105      * @param name the name of the gamma correction
106      * @param label the label of the gamma correction; can be null when the label is identical to the name
107      * @param dataCode the data code identifying the gamma correction
108      */
109     private SonyProjectorGammaCorrection(int category, String name, @Nullable String label, byte[] dataCode) {
110         this.category = category;
111         this.name = name;
112         this.label = label;
113         this.dataCode = dataCode;
114     }
115
116     /**
117      * Get the category of projector models for the current gamma correction
118      *
119      * @return the category of projector models
120      */
121     public int getCategory() {
122         return category;
123     }
124
125     /**
126      * Get the data code identifying the current gamma correction
127      *
128      * @return the data code
129      */
130     public byte[] getDataCode() {
131         return dataCode;
132     }
133
134     /**
135      * Get the label of the current gamma correction
136      *
137      * @return the label
138      */
139     public @Nullable String getLabel() {
140         return label;
141     }
142
143     /**
144      * Get the name of the current gamma correction
145      *
146      * @return the name
147      */
148     public String getName() {
149         return name;
150     }
151
152     /**
153      * Get the list of {@link StateOption} associated to the available gamma corrections for a particular category of
154      * projector models
155      *
156      * @param category a category of projector models
157      *
158      * @return the list of {@link StateOption} associated to the available gamma corrections for a provided category of
159      *         projector models
160      */
161     public static List<StateOption> getStateOptions(int category) {
162         List<StateOption> options = new ArrayList<>();
163         for (SonyProjectorGammaCorrection value : SonyProjectorGammaCorrection.values()) {
164             if (value.getCategory() == category) {
165                 options.add(new StateOption(value.getName(),
166                         value.getLabel() != null ? value.getLabel() : value.getName()));
167             }
168         }
169         return options;
170     }
171
172     /**
173      * Get the gamma correction associated to a name for a particular category of projector models
174      *
175      * @param category a category of projector models
176      * @param name the name used to identify the gamma correction
177      *
178      * @return the gamma correction associated to the searched name for the provided category of projector models
179      *
180      * @throws SonyProjectorException - If no gamma correction is associated to the searched name for the provided
181      *             category
182      */
183     public static SonyProjectorGammaCorrection getFromName(int category, String name) throws SonyProjectorException {
184         for (SonyProjectorGammaCorrection value : SonyProjectorGammaCorrection.values()) {
185             if (value.getCategory() == category && value.getName().equals(name)) {
186                 return value;
187             }
188         }
189         throw new SonyProjectorException("Invalid nam for a gamma correctione: " + name);
190     }
191
192     /**
193      * Get the gamma correction associated to a data code for a particular category of projector models
194      *
195      * @param category a category of projector models
196      * @param dataCode the data code used to identify the gamma correction
197      *
198      * @return the gamma correction associated to the searched data code for the provided category of projector models
199      *
200      * @throws SonyProjectorException - If no gamma correction is associated to the searched data code for the provided
201      *             category
202      */
203     public static SonyProjectorGammaCorrection getFromDataCode(int category, byte[] dataCode)
204             throws SonyProjectorException {
205         for (SonyProjectorGammaCorrection value : SonyProjectorGammaCorrection.values()) {
206             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
207                 return value;
208             }
209         }
210         throw new SonyProjectorException("Invalid data code for a gamma correctione: " + HexUtils.bytesToHex(dataCode));
211     }
212 }