]> git.basschouten.com Git - openhab-addons.git/blob
916e9383267cca45da59f8cc41e350a35b8f2ba9
[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 contrast enhancer modes available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorContrastEnhancer {
32
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 }),
40
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 }),
45
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 });
54
55     private int category;
56     private String name;
57     private @Nullable String label;
58     private byte[] dataCode;
59
60     /**
61      * Constructor
62      *
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
67      */
68     private SonyProjectorContrastEnhancer(int category, String name, @Nullable String label, byte[] dataCode) {
69         this.category = category;
70         this.name = name;
71         this.label = label;
72         this.dataCode = dataCode;
73     }
74
75     /**
76      * Get the category of projector models for the current contrast enhancer mode
77      *
78      * @return the category of projector models
79      */
80     public int getCategory() {
81         return category;
82     }
83
84     /**
85      * Get the data code identifying the current contrast enhancer mode
86      *
87      * @return the data code
88      */
89     public byte[] getDataCode() {
90         return dataCode;
91     }
92
93     /**
94      * Get the label of the current contrast enhancer mode
95      *
96      * @return the label
97      */
98     public @Nullable String getLabel() {
99         return label;
100     }
101
102     /**
103      * Get the name of the current contrast enhancer mode
104      *
105      * @return the name
106      */
107     public String getName() {
108         return name;
109     }
110
111     /**
112      * Get the list of {@link StateOption} associated to the available contrast enhancer modes for a particular category
113      * of projector models
114      *
115      * @param category a category of projector models
116      *
117      * @return the list of {@link StateOption} associated to the available contrast enhancer modes for a provided
118      *         category of projector models
119      */
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()));
126             }
127         }
128         return options;
129     }
130
131     /**
132      * Get the contrast enhancer mode associated to a name for a particular category of projector models
133      *
134      * @param category a category of projector models
135      * @param name the name used to identify the contrast enhancer mode
136      *
137      * @return the contrast enhancer mode associated to the searched name for the provided category of projector models
138      *
139      * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched name for the provided
140      *             category
141      */
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)) {
145                 return value;
146             }
147         }
148         throw new SonyProjectorException("Invalid name for a contrast enhancer mode: " + name);
149     }
150
151     /**
152      * Get the contrast enhancer mode associated to a data code for a particular category of projector models
153      *
154      * @param category a category of projector models
155      * @param dataCode the data code used to identify the contrast enhancer mode
156      *
157      * @return the contrast enhancer mode associated to the searched data code for the provided category of projector
158      *         models
159      *
160      * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched data code for the
161      *             provided category
162      */
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())) {
167                 return value;
168             }
169         }
170         throw new SonyProjectorException(
171                 "Invalid data code for a contrast enhancer mode: " + HexUtils.bytesToHex(dataCode));
172     }
173 }