2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sonyprojector.internal.communication;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
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;
26 * Represents the different gamma corrections available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorGammaCorrection {
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,
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 }),
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 }),
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 }),
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 }),
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 }),
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 });
98 private @Nullable String label;
99 private byte[] dataCode;
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
109 private SonyProjectorGammaCorrection(int category, String name, @Nullable String label, byte[] dataCode) {
110 this.category = category;
113 this.dataCode = dataCode;
117 * Get the category of projector models for the current gamma correction
119 * @return the category of projector models
121 public int getCategory() {
126 * Get the data code identifying the current gamma correction
128 * @return the data code
130 public byte[] getDataCode() {
135 * Get the label of the current gamma correction
139 public @Nullable String getLabel() {
144 * Get the name of the current gamma correction
148 public String getName() {
153 * Get the list of {@link StateOption} associated to the available gamma corrections for a particular category of
156 * @param category a category of projector models
158 * @return the list of {@link StateOption} associated to the available gamma corrections for a provided category of
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()));
173 * Get the gamma correction associated to a name for a particular category of projector models
175 * @param category a category of projector models
176 * @param name the name used to identify the gamma correction
178 * @return the gamma correction associated to the searched name for the provided category of projector models
180 * @throws SonyProjectorException - If no gamma correction is associated to the searched name for the provided
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)) {
189 throw new SonyProjectorException("Invalid nam for a gamma correctione: " + name);
193 * Get the gamma correction associated to a data code for a particular category of projector models
195 * @param category a category of projector models
196 * @param dataCode the data code used to identify the gamma correction
198 * @return the gamma correction associated to the searched data code for the provided category of projector models
200 * @throws SonyProjectorException - If no gamma correction is associated to the searched data code for the provided
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())) {
210 throw new SonyProjectorException("Invalid data code for a gamma correctione: " + HexUtils.bytesToHex(dataCode));