]> git.basschouten.com Git - openhab-addons.git/blob
bd9553cc3c110ceaf556f2ed0cb4ebdc81924ec3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyprojector.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
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;
23
24 /**
25  * Represents the different color spaces available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorColorSpace {
31
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 }),
38
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 }),
47
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 }),
51
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 }),
57
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 }),
65
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 });
71
72     private int category;
73     private String name;
74     private byte[] dataCode;
75
76     /**
77      * Constructor
78      *
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
82      */
83     private SonyProjectorColorSpace(int category, String name, byte[] dataCode) {
84         this.category = category;
85         this.name = name;
86         this.dataCode = dataCode;
87     }
88
89     /**
90      * Get the category of projector models for the current color space
91      *
92      * @return the category of projector models
93      */
94     public int getCategory() {
95         return category;
96     }
97
98     /**
99      * Get the data code identifying the current color space
100      *
101      * @return the data code
102      */
103     public byte[] getDataCode() {
104         return dataCode;
105     }
106
107     /**
108      * Get the name of the current color space
109      *
110      * @return the name
111      */
112     public String getName() {
113         return name;
114     }
115
116     /**
117      * Get the list of {@link StateOption} associated to the available color spaces for a particular category of
118      * projector models
119      *
120      * @param category a category of projector models
121      *
122      * @return the list of {@link StateOption} associated to the available color spaces for a provided category of
123      *         projector models
124      */
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()));
130             }
131         }
132         return options;
133     }
134
135     /**
136      * Get the color space associated to a name for a particular category of projector models
137      *
138      * @param category a category of projector models
139      * @param name the name used to identify the color space
140      *
141      * @return the color space associated to the searched name for the provided category of projector models
142      *
143      * @throws SonyProjectorException - If no color space is associated to the searched name for the provided category
144      */
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)) {
148                 return value;
149             }
150         }
151         throw new SonyProjectorException("Invalid name for a color space: " + name);
152     }
153
154     /**
155      * Get the color space associated to a data code for a particular category of projector models
156      *
157      * @param category a category of projector models
158      * @param dataCode the data code used to identify the color space
159      *
160      * @return the color space associated to the searched data code for the provided category of projector models
161      *
162      * @throws SonyProjectorException - If no color space is associated to the searched data code for the provided
163      *             category
164      */
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())) {
168                 return value;
169             }
170         }
171         throw new SonyProjectorException("Invalid data code for a color space: " + HexUtils.bytesToHex(dataCode));
172     }
173 }