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 contrast enhancer modes available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorContrastEnhancer {
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, HW40ES, HW45ES,
35 // HW50ES, HW55ES, HW58ES, HW60, HW65, HW68
36 CAT1_HIGH(1, "High", null, new byte[] { 0x00, 0x02 }),
37 CAT1_MIDDLE(1, "Middle", null, new byte[] { 0x00, 0x03 }),
38 CAT1_LOW(1, "Low", null, new byte[] { 0x00, 0x01 }),
39 CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
41 // Category 2: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
42 CAT2_HIGH(2, "High", null, new byte[] { 0x00, 0x02 }),
43 CAT2_LOW(2, "Low", null, new byte[] { 0x00, 0x01 }),
44 CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
46 // Category 3: VW85, VW90, VW95, HW30ES
47 CAT3_LEVEL_MINUS_3(3, "-3", null, new byte[] { (byte) 0xFF, (byte) 0xFD }),
48 CAT3_LEVEL_MINUS_2(3, "-2", null, new byte[] { (byte) 0xFF, (byte) 0xFE }),
49 CAT3_LEVEL_MINUS_1(3, "-1", null, new byte[] { (byte) 0xFF, (byte) 0xFF }),
50 CAT3_LEVEL_0(3, "0", null, new byte[] { 0x00, 0x00 }),
51 CAT3_LEVEL_PLUS_1(3, "1", null, new byte[] { 0x00, 0x01 }),
52 CAT3_LEVEL_PLUS_2(3, "2", null, new byte[] { 0x00, 0x02 }),
53 CAT3_LEVEL_PLUS_3(3, "3", null, new byte[] { 0x00, 0x03 });
57 private @Nullable String label;
58 private byte[] dataCode;
63 * @param category a category of projector models for which the contrast enhancer mode is available
64 * @param name the name of the contrast enhancer mode
65 * @param label the label of the contrast enhancer mode; can be null when the label is identical to the name
66 * @param dataCode the data code identifying the contrast enhancer mode
68 private SonyProjectorContrastEnhancer(int category, String name, @Nullable String label, byte[] dataCode) {
69 this.category = category;
72 this.dataCode = dataCode;
76 * Get the category of projector models for the current contrast enhancer mode
78 * @return the category of projector models
80 public int getCategory() {
85 * Get the data code identifying the current contrast enhancer mode
87 * @return the data code
89 public byte[] getDataCode() {
94 * Get the label of the current contrast enhancer mode
98 public @Nullable String getLabel() {
103 * Get the name of the current contrast enhancer mode
107 public String getName() {
112 * Get the list of {@link StateOption} associated to the available contrast enhancer modes for a particular category
113 * of projector models
115 * @param category a category of projector models
117 * @return the list of {@link StateOption} associated to the available contrast enhancer modes for a provided
118 * category of projector models
120 public static List<StateOption> getStateOptions(int category) {
121 List<StateOption> options = new ArrayList<>();
122 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
123 if (value.getCategory() == category) {
124 options.add(new StateOption(value.getName(),
125 value.getLabel() != null ? value.getLabel() : value.getName()));
132 * Get the contrast enhancer mode associated to a name for a particular category of projector models
134 * @param category a category of projector models
135 * @param name the name used to identify the contrast enhancer mode
137 * @return the contrast enhancer mode associated to the searched name for the provided category of projector models
139 * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched name for the provided
142 public static SonyProjectorContrastEnhancer getFromName(int category, String name) throws SonyProjectorException {
143 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
144 if (value.getCategory() == category && value.getName().equals(name)) {
148 throw new SonyProjectorException("Invalid name for a contrast enhancer mode: " + name);
152 * Get the contrast enhancer mode associated to a data code for a particular category of projector models
154 * @param category a category of projector models
155 * @param dataCode the data code used to identify the contrast enhancer mode
157 * @return the contrast enhancer mode associated to the searched data code for the provided category of projector
160 * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched data code for the
163 public static SonyProjectorContrastEnhancer getFromDataCode(int category, byte[] dataCode)
164 throws SonyProjectorException {
165 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
166 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
170 throw new SonyProjectorException(
171 "Invalid data code for a contrast enhancer mode: " + HexUtils.bytesToHex(dataCode));