]> git.basschouten.com Git - openhab-addons.git/blob
22e071a27ab40b7b82f908688560e8e0747ebc00
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.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;
24
25 /**
26  * Represents the different color spaces available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorColorSpace {
32
33     // Category 1: VW300, VW315, VW320, VW328, VW350, VW365, VW500, VW600, HW60, HW65, HW68
34     CAT1_BT709(1, "BT709", "BT.709", new byte[] { 0x00, 0x00 }),
35     CAT1_SPACE1(1, "ColorSpace1", "Color Space 1", new byte[] { 0x00, 0x03 }),
36     CAT1_SPACE2(1, "ColorSpace2", "Color Space 2", new byte[] { 0x00, 0x04 }),
37     CAT1_SPACE3(1, "ColorSpace3", "Color Space 3", new byte[] { 0x00, 0x05 }),
38     CAT1_CUSTOM(1, "Custom", null, new byte[] { 0x00, 0x06 }),
39
40     // Category 2: VW260, VW270, VW285, VW295, VW385, VW515, VW520, VW528, VW550, VW570, VW665, VW675, VW695, VW760,
41     // VW870, VW885, VW995
42     CAT2_BT709(2, "BT709", "BT.709", new byte[] { 0x00, 0x00 }),
43     CAT2_BT2020(2, "BT2020", "BT.2020", new byte[] { 0x00, 0x08 }),
44     CAT2_SPACE1(2, "ColorSpace1", "Color Space 1", new byte[] { 0x00, 0x03 }),
45     CAT2_SPACE2(2, "ColorSpace2", "Color Space 2", new byte[] { 0x00, 0x04 }),
46     CAT2_SPACE3(2, "ColorSpace3", "Color Space 3", new byte[] { 0x00, 0x05 }),
47     CAT2_CUSTOM(2, "Custom", null, new byte[] { 0x00, 0x06 }),
48
49     // Category 3: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
50     CAT3_NORMAL(3, "Normal", null, new byte[] { 0x00, 0x00 }),
51     CAT3_WIDE(3, "Wide", null, new byte[] { 0x00, 0x01 }),
52
53     // Category 4: VW85, VW90, VW95, HW30ES
54     CAT4_NORMAL(4, "Normal", null, new byte[] { 0x00, 0x00 }),
55     CAT4_WIDE1(4, "Wide1", "Wide 1", new byte[] { 0x00, 0x01 }),
56     CAT4_WIDE2(4, "Wide2", "Wide 2", new byte[] { 0x00, 0x02 }),
57     CAT4_WIDE3(4, "Wide3", "Wide 3", new byte[] { 0x00, 0x03 }),
58
59     // Category 5: VW1000ES, VW1100ES
60     CAT5_BT709(5, "BT709", "BT.709", new byte[] { 0x00, 0x00 }),
61     CAT5_DCI(5, "DCI", null, new byte[] { 0x00, 0x01 }),
62     CAT5_ADOBE_RGB(5, "AdobeRGB", "Adobe RGB", new byte[] { 0x00, 0x02 }),
63     CAT5_SPACE1(5, "ColorSpace1", "Color Space 1", new byte[] { 0x00, 0x03 }),
64     CAT5_SPACE2(5, "ColorSpace2", "Color Space 2", new byte[] { 0x00, 0x04 }),
65     CAT5_SPACE3(5, "ColorSpace3", "Color Space 3", new byte[] { 0x00, 0x05 }),
66
67     // Category 6: HW35ES, HW40ES, HW45ES, HW50ES, HW55ES, HW58ES
68     CAT6_BT709(6, "BT709", "BT.709", new byte[] { 0x00, 0x00 }),
69     CAT6_SPACE1(6, "ColorSpace1", "Color Space 1", new byte[] { 0x00, 0x01 }),
70     CAT6_SPACE2(6, "ColorSpace2", "Color Space 2", new byte[] { 0x00, 0x02 }),
71     CAT6_SPACE3(6, "ColorSpace3", "Color Space 3", new byte[] { 0x00, 0x03 });
72
73     private int category;
74     private String name;
75     private @Nullable String label;
76     private byte[] dataCode;
77
78     /**
79      * Constructor
80      *
81      * @param category a category of projector models for which the color space is available
82      * @param name the name of the color space
83      * @param label the label of the color space; can be null when the label is identical to the name
84      * @param dataCode the data code identifying the color space
85      */
86     private SonyProjectorColorSpace(int category, String name, @Nullable String label, byte[] dataCode) {
87         this.category = category;
88         this.name = name;
89         this.label = label;
90         this.dataCode = dataCode;
91     }
92
93     /**
94      * Get the category of projector models for the current color space
95      *
96      * @return the category of projector models
97      */
98     public int getCategory() {
99         return category;
100     }
101
102     /**
103      * Get the data code identifying the current color space
104      *
105      * @return the data code
106      */
107     public byte[] getDataCode() {
108         return dataCode;
109     }
110
111     /**
112      * Get the label of the current color space
113      *
114      * @return the label
115      */
116     public @Nullable String getLabel() {
117         return label;
118     }
119
120     /**
121      * Get the name of the current color space
122      *
123      * @return the name
124      */
125     public String getName() {
126         return name;
127     }
128
129     /**
130      * Get the list of {@link StateOption} associated to the available color spaces for a particular category of
131      * projector models
132      *
133      * @param category a category of projector models
134      *
135      * @return the list of {@link StateOption} associated to the available color spaces for a provided category of
136      *         projector models
137      */
138     public static List<StateOption> getStateOptions(int category) {
139         List<StateOption> options = new ArrayList<>();
140         for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
141             if (value.getCategory() == category) {
142                 options.add(new StateOption(value.getName(),
143                         value.getLabel() != null ? value.getLabel() : value.getName()));
144             }
145         }
146         return options;
147     }
148
149     /**
150      * Get the color space associated to a name for a particular category of projector models
151      *
152      * @param category a category of projector models
153      * @param name the name used to identify the color space
154      *
155      * @return the color space associated to the searched name for the provided category of projector models
156      *
157      * @throws SonyProjectorException - If no color space is associated to the searched name for the provided category
158      */
159     public static SonyProjectorColorSpace getFromName(int category, String name) throws SonyProjectorException {
160         for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
161             if (value.getCategory() == category && value.getName().equals(name)) {
162                 return value;
163             }
164         }
165         throw new SonyProjectorException("Invalid name for a color space: " + name);
166     }
167
168     /**
169      * Get the color space associated to a data code for a particular category of projector models
170      *
171      * @param category a category of projector models
172      * @param dataCode the data code used to identify the color space
173      *
174      * @return the color space associated to the searched data code for the provided category of projector models
175      *
176      * @throws SonyProjectorException - If no color space is associated to the searched data code for the provided
177      *             category
178      */
179     public static SonyProjectorColorSpace getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
180         for (SonyProjectorColorSpace value : SonyProjectorColorSpace.values()) {
181             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
182                 return value;
183             }
184         }
185         throw new SonyProjectorException("Invalid data code for a color space: " + HexUtils.bytesToHex(dataCode));
186     }
187 }