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