2 * Copyright (c) 2010-2023 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 contrast enhancer modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorContrastEnhancer {
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, HW40ES, HW45ES,
34 // HW50ES, HW55ES, HW58ES, HW60, HW65, HW68
35 CAT1_HIGH(1, "High", new byte[] { 0x00, 0x02 }),
36 CAT1_MIDDLE(1, "Middle", new byte[] { 0x00, 0x03 }),
37 CAT1_LOW(1, "Low", new byte[] { 0x00, 0x01 }),
38 CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
40 // Category 2: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
41 CAT2_HIGH(2, "High", new byte[] { 0x00, 0x02 }),
42 CAT2_LOW(2, "Low", new byte[] { 0x00, 0x01 }),
43 CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 }),
45 // Category 3: VW85, VW90, VW95, HW30ES
46 CAT3_LEVEL_MINUS_3(3, "-3", new byte[] { (byte) 0xFF, (byte) 0xFD }),
47 CAT3_LEVEL_MINUS_2(3, "-2", new byte[] { (byte) 0xFF, (byte) 0xFE }),
48 CAT3_LEVEL_MINUS_1(3, "-1", new byte[] { (byte) 0xFF, (byte) 0xFF }),
49 CAT3_LEVEL_0(3, "0", new byte[] { 0x00, 0x00 }),
50 CAT3_LEVEL_PLUS_1(3, "1", new byte[] { 0x00, 0x01 }),
51 CAT3_LEVEL_PLUS_2(3, "2", new byte[] { 0x00, 0x02 }),
52 CAT3_LEVEL_PLUS_3(3, "3", new byte[] { 0x00, 0x03 });
56 private byte[] dataCode;
61 * @param category a category of projector models for which the contrast enhancer mode is available
62 * @param name the name of the contrast enhancer mode
63 * @param dataCode the data code identifying the contrast enhancer mode
65 private SonyProjectorContrastEnhancer(int category, String name, byte[] dataCode) {
66 this.category = category;
68 this.dataCode = dataCode;
72 * Get the category of projector models for the current contrast enhancer mode
74 * @return the category of projector models
76 public int getCategory() {
81 * Get the data code identifying the current contrast enhancer mode
83 * @return the data code
85 public byte[] getDataCode() {
90 * Get the name of the current contrast enhancer mode
94 public String getName() {
99 * Get the list of {@link StateOption} associated to the available contrast enhancer modes for a particular category
100 * of projector models
102 * @param category a category of projector models
104 * @return the list of {@link StateOption} associated to the available contrast enhancer modes for a provided
105 * category of projector models
107 public static List<StateOption> getStateOptions(int category) {
108 List<StateOption> options = new ArrayList<>();
109 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
110 if (value.getCategory() == category) {
111 options.add(new StateOption(value.getName(), value.getName()));
118 * Get the contrast enhancer mode associated to a name for a particular category of projector models
120 * @param category a category of projector models
121 * @param name the name used to identify the contrast enhancer mode
123 * @return the contrast enhancer mode associated to the searched name for the provided category of projector models
125 * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched name for the provided
128 public static SonyProjectorContrastEnhancer getFromName(int category, String name) throws SonyProjectorException {
129 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
130 if (value.getCategory() == category && value.getName().equals(name)) {
134 throw new SonyProjectorException("Invalid name for a contrast enhancer mode: " + name);
138 * Get the contrast enhancer mode associated to a data code for a particular category of projector models
140 * @param category a category of projector models
141 * @param dataCode the data code used to identify the contrast enhancer mode
143 * @return the contrast enhancer mode associated to the searched data code for the provided category of projector
146 * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched data code for the
149 public static SonyProjectorContrastEnhancer getFromDataCode(int category, byte[] dataCode)
150 throws SonyProjectorException {
151 for (SonyProjectorContrastEnhancer value : SonyProjectorContrastEnhancer.values()) {
152 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
156 throw new SonyProjectorException(
157 "Invalid data code for a contrast enhancer mode: " + HexUtils.bytesToHex(dataCode));