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 color spaces available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorColorSpace {
32 // Category 1: VW300, VW315, VW320, VW328, VW350, VW365, VW500, VW600, HW60, HW65, HW68
33 CAT1_BT709(1, "BT709", new byte[] { 0x00, 0x00 }),
34 CAT1_SPACE1(1, "ColorSpace1", new byte[] { 0x00, 0x03 }),
35 CAT1_SPACE2(1, "ColorSpace2", new byte[] { 0x00, 0x04 }),
36 CAT1_SPACE3(1, "ColorSpace3", new byte[] { 0x00, 0x05 }),
37 CAT1_CUSTOM(1, "Custom", new byte[] { 0x00, 0x06 }),
39 // Category 2: VW260, VW270, VW285, VW295, VW385, VW515, VW520, VW528, VW550, VW570, VW665, VW675, VW695, VW760,
40 // VW870, VW885, VW995
41 CAT2_BT709(2, "BT709", new byte[] { 0x00, 0x00 }),
42 CAT2_BT2020(2, "BT2020", new byte[] { 0x00, 0x08 }),
43 CAT2_SPACE1(2, "ColorSpace1", new byte[] { 0x00, 0x03 }),
44 CAT2_SPACE2(2, "ColorSpace2", new byte[] { 0x00, 0x04 }),
45 CAT2_SPACE3(2, "ColorSpace3", new byte[] { 0x00, 0x05 }),
46 CAT2_CUSTOM(2, "Custom", new byte[] { 0x00, 0x06 }),
48 // Category 3: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
49 CAT3_NORMAL(3, "Normal", new byte[] { 0x00, 0x00 }),
50 CAT3_WIDE(3, "Wide", new byte[] { 0x00, 0x01 }),
52 // Category 4: VW85, VW90, VW95, HW30ES
53 CAT4_NORMAL(4, "Normal", new byte[] { 0x00, 0x00 }),
54 CAT4_WIDE1(4, "Wide1", new byte[] { 0x00, 0x01 }),
55 CAT4_WIDE2(4, "Wide2", new byte[] { 0x00, 0x02 }),
56 CAT4_WIDE3(4, "Wide3", new byte[] { 0x00, 0x03 }),
58 // Category 5: VW1000ES, VW1100ES
59 CAT5_BT709(5, "BT709", new byte[] { 0x00, 0x00 }),
60 CAT5_DCI(5, "DCI", new byte[] { 0x00, 0x01 }),
61 CAT5_ADOBE_RGB(5, "AdobeRGB", new byte[] { 0x00, 0x02 }),
62 CAT5_SPACE1(5, "ColorSpace1", new byte[] { 0x00, 0x03 }),
63 CAT5_SPACE2(5, "ColorSpace2", new byte[] { 0x00, 0x04 }),
64 CAT5_SPACE3(5, "ColorSpace3", new byte[] { 0x00, 0x05 }),
66 // Category 6: HW35ES, HW40ES, HW45ES, HW50ES, HW55ES, HW58ES
67 CAT6_BT709(6, "BT709", new byte[] { 0x00, 0x00 }),
68 CAT6_SPACE1(6, "ColorSpace1", new byte[] { 0x00, 0x01 }),
69 CAT6_SPACE2(6, "ColorSpace2", new byte[] { 0x00, 0x02 }),
70 CAT6_SPACE3(6, "ColorSpace3", new byte[] { 0x00, 0x03 });
74 private byte[] dataCode;
79 * @param category a category of projector models for which the color space is available
80 * @param name the name of the color space
81 * @param dataCode the data code identifying the color space
83 private SonyProjectorColorSpace(int category, String name, byte[] dataCode) {
84 this.category = category;
86 this.dataCode = dataCode;
90 * Get the category of projector models for the current color space
92 * @return the category of projector models
94 public int getCategory() {
99 * Get the data code identifying the current color space
101 * @return the data code
103 public byte[] getDataCode() {
108 * Get the name of the current color space
112 public String getName() {
117 * Get the list of {@link StateOption} associated to the available color spaces for a particular category of
120 * @param category a category of projector models
122 * @return the list of {@link StateOption} associated to the available color spaces for a provided category of
125 public static List<StateOption> getStateOptions(int category) {
126 List<StateOption> options = new ArrayList<>();
127 for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
128 if (value.getCategory() == category) {
129 options.add(new StateOption(value.getName(), value.getName()));
136 * Get the color space associated to a name for a particular category of projector models
138 * @param category a category of projector models
139 * @param name the name used to identify the color space
141 * @return the color space associated to the searched name for the provided category of projector models
143 * @throws SonyProjectorException - If no color space is associated to the searched name for the provided category
145 public static SonyProjectorColorSpace getFromName(int category, String name) throws SonyProjectorException {
146 for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
147 if (value.getCategory() == category && value.getName().equals(name)) {
151 throw new SonyProjectorException("Invalid name for a color space: " + name);
155 * Get the color space associated to a data code for a particular category of projector models
157 * @param category a category of projector models
158 * @param dataCode the data code used to identify the color space
160 * @return the color space associated to the searched data code for the provided category of projector models
162 * @throws SonyProjectorException - If no color space is associated to the searched data code for the provided
165 public static SonyProjectorColorSpace getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
166 for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
167 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
171 throw new SonyProjectorException("Invalid data code for a color space: " + HexUtils.bytesToHex(dataCode));