2 * Copyright (c) 2010-2022 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.openhab.binding.sonyprojector.internal.SonyProjectorException;
21 import org.openhab.core.types.StateOption;
22 import org.openhab.core.util.HexUtils;
25 * Represents the different gamma corrections available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorGammaCorrection {
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,
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 }),
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 }),
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 }),
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 }),
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 }),
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 });
97 private byte[] dataCode;
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
106 private SonyProjectorGammaCorrection(int category, String name, byte[] dataCode) {
107 this.category = category;
109 this.dataCode = dataCode;
113 * Get the category of projector models for the current gamma correction
115 * @return the category of projector models
117 public int getCategory() {
122 * Get the data code identifying the current gamma correction
124 * @return the data code
126 public byte[] getDataCode() {
131 * Get the name of the current gamma correction
135 public String getName() {
140 * Get the list of {@link StateOption} associated to the available gamma corrections for a particular category of
143 * @param category a category of projector models
145 * @return the list of {@link StateOption} associated to the available gamma corrections for a provided category of
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()));
159 * Get the gamma correction associated to a name for a particular category of projector models
161 * @param category a category of projector models
162 * @param name the name used to identify the gamma correction
164 * @return the gamma correction associated to the searched name for the provided category of projector models
166 * @throws SonyProjectorException - If no gamma correction is associated to the searched name for the provided
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)) {
175 throw new SonyProjectorException("Invalid nam for a gamma correctione: " + name);
179 * Get the gamma correction associated to a data code for a particular category of projector models
181 * @param category a category of projector models
182 * @param dataCode the data code used to identify the gamma correction
184 * @return the gamma correction associated to the searched data code for the provided category of projector models
186 * @throws SonyProjectorException - If no gamma correction is associated to the searched data code for the provided
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())) {
196 throw new SonyProjectorException("Invalid data code for a gamma correctione: " + HexUtils.bytesToHex(dataCode));