]> git.basschouten.com Git - openhab-addons.git/blob
d3390482a35cbbd2f79fcb05233efc6732972adb
[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 motion enhancer modes available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorMotionEnhancer {
32
33     // Category 1: VW260, VW285, VW300, VW315, VW320, VW328, VW350, VW360, VW365, VW385, VW500, VW515, VW520, VW528,
34     // VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW45ES, HW60, HW65, HW68
35     CAT1_SMOOTH_HIGH(1, "SmoothHigh", "Smooth High", new byte[] { 0x00, 0x01 }),
36     CAT1_SMOOTH_LOW(1, "SmoothLow", "Smooth Low", new byte[] { 0x00, 0x02 }),
37     CAT1_IMPULSE(1, "Impulse", null, new byte[] { 0x00, 0x03 }),
38     CAT1_COMBINATION(1, "Combination", null, new byte[] { 0x00, 0x04 }),
39     CAT1_TRUE_CINEMA(1, "TrueCinema", "True Cinema", new byte[] { 0x00, 0x05 }),
40     CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
41
42     // Category 2: VW80, VW85, VW90, VW95, VW200, VW1000ES, VW1100ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
43     CAT2_HIGH(2, "High", null, new byte[] { 0x00, 0x02 }),
44     CAT2_LOW(2, "Low", null, new byte[] { 0x00, 0x01 }),
45     CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
46
47     // Category 3: VW270, VW295
48     CAT3_SMOOTH_HIGH(3, "SmoothHigh", "Smooth High", new byte[] { 0x00, 0x01 }),
49     CAT3_SMOOTH_LOW(3, "SmoothLow", "Smooth Low", new byte[] { 0x00, 0x02 }),
50     CAT3_TRUE_CINEMA(3, "TrueCinema", "True Cinema", new byte[] { 0x00, 0x05 }),
51     CAT3_OFF(3, "Off", null, new byte[] { 0x00, 0x00 });
52
53     private int category;
54     private String name;
55     private @Nullable String label;
56     private byte[] dataCode;
57
58     /**
59      * Constructor
60      *
61      * @param category a category of projector models for which the motion enhancer mode is available
62      * @param name the name of the motion enhancer mode
63      * @param label the label of the motion enhancer mode; can be null when the label is identical to the name
64      * @param dataCode the data code identifying the motion enhancer mode
65      */
66     private SonyProjectorMotionEnhancer(int category, String name, @Nullable String label, byte[] dataCode) {
67         this.category = category;
68         this.name = name;
69         this.label = label;
70         this.dataCode = dataCode;
71     }
72
73     /**
74      * Get the category of projector models for the current motion enhancer mode
75      *
76      * @return the category of projector models
77      */
78     public int getCategory() {
79         return category;
80     }
81
82     /**
83      * Get the data code identifying the current motion enhancer mode
84      *
85      * @return the data code
86      */
87     public byte[] getDataCode() {
88         return dataCode;
89     }
90
91     /**
92      * Get the label of the current motion enhancer mode
93      *
94      * @return the label
95      */
96     public @Nullable String getLabel() {
97         return label;
98     }
99
100     /**
101      * Get the name of the current motion enhancer mode
102      *
103      * @return the name
104      */
105     public String getName() {
106         return name;
107     }
108
109     /**
110      * Get the list of {@link StateOption} associated to the available motion enhancer modes for a particular category
111      * of projector models
112      *
113      * @param category a category of projector models
114      *
115      * @return the list of {@link StateOption} associated to the available motion enhancer modes for a provided category
116      *         of projector models
117      */
118     public static List<StateOption> getStateOptions(int category) {
119         List<StateOption> options = new ArrayList<>();
120         for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
121             if (value.getCategory() == category) {
122                 options.add(new StateOption(value.getName(),
123                         value.getLabel() != null ? value.getLabel() : value.getName()));
124             }
125         }
126         return options;
127     }
128
129     /**
130      * Get the motion enhancer mode associated to a name for a particular category of projector models
131      *
132      * @param category a category of projector models
133      * @param name the name used to identify the motion enhancer mode
134      *
135      * @return the motion enhancer mode associated to the searched name for the provided category of projector models
136      *
137      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched name for the provided
138      *             category
139      */
140     public static SonyProjectorMotionEnhancer getFromName(int category, String name) throws SonyProjectorException {
141         for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
142             if (value.getCategory() == category && value.getName().equals(name)) {
143                 return value;
144             }
145         }
146         throw new SonyProjectorException("Invalid name for a motion enhancer mode: " + name);
147     }
148
149     /**
150      * Get the motion enhancer mode associated to a data code for a particular category of projector models
151      *
152      * @param category a category of projector models
153      * @param dataCode the data code used to identify the motion enhancer mode
154      *
155      * @return the motion enhancer mode associated to the searched data code for the provided category of projector
156      *         models
157      *
158      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched data code for the
159      *             provided category
160      */
161     public static SonyProjectorMotionEnhancer getFromDataCode(int category, byte[] dataCode)
162             throws SonyProjectorException {
163         for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
164             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
165                 return value;
166             }
167         }
168         throw new SonyProjectorException(
169                 "Invalid data code for a motion enhancer mode: " + HexUtils.bytesToHex(dataCode));
170     }
171 }