]> git.basschouten.com Git - openhab-addons.git/blob
21cb176cb29b538bac22346907916225e2579afc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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 aspect modes available for the projector
27  *
28  * @author Laurent Garnier - Initial contribution
29  */
30 @NonNullByDefault
31 public enum SonyProjectorAspect {
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, VW885
35     CAT1_NORMAL(1, "Normal", null, new byte[] { 0x00, 0x01 }),
36     CAT1_V_STRETCH(1, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
37     CAT1_185(1, "185", "1.85:1 Zoom", new byte[] { 0x00, 0x0C }),
38     CAT1_235(1, "235", "2.35:1 Zoom", new byte[] { 0x00, 0x0D }),
39     CAT1_STRETCH(1, "Stretch", null, new byte[] { 0x00, 0x0E }),
40     CAT1_SQUEEZE(1, "Squeeze", null, new byte[] { 0x00, 0x0F }),
41
42     // Category 2: VW40, VW50, HW10, HW15, HW20, HW30
43     CAT2_FULL(2, "Full", null, new byte[] { 0x00, 0x00 }),
44     CAT2_NORMAL(2, "Normal", null, new byte[] { 0x00, 0x01 }),
45     CAT2_WIDE(2, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
46     CAT2_ZOOM(2, "Zoom", null, new byte[] { 0x00, 0x03 }),
47     CAT2_FULL1(2, "Full1", "Full 1", new byte[] { 0x00, 0x07 }),
48     CAT2_FULL2(2, "Full2", "Full 2", new byte[] { 0x00, 0x08 }),
49
50     // Category 3: VW60, VW70, VW80, VW85, VW90, VW95, VW200
51     CAT3_FULL(3, "Full", null, new byte[] { 0x00, 0x00 }),
52     CAT3_NORMAL(3, "Normal", null, new byte[] { 0x00, 0x01 }),
53     CAT3_WIDE(3, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
54     CAT3_ZOOM(3, "Zoom", null, new byte[] { 0x00, 0x03 }),
55     CAT3_FULL1(3, "Full1", "Full 1", new byte[] { 0x00, 0x07 }),
56     CAT3_FULL2(3, "Full2", "Full 2", new byte[] { 0x00, 0x08 }),
57     CAT3_ANAMORPHIC(3, "Anamorphic", null, new byte[] { 0x00, 0x0B }),
58
59     // Category 4: VW100
60     CAT4_FULL(4, "Full", null, new byte[] { 0x00, 0x00 }),
61     CAT4_NORMAL(4, "Normal", null, new byte[] { 0x00, 0x01 }),
62     CAT4_WIDE(4, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
63     CAT4_ZOOM(4, "Zoom", null, new byte[] { 0x00, 0x03 }),
64     CAT3_SUBTITLE(4, "Subtitle", null, new byte[] { 0x00, 0x04 }),
65
66     // Category 5: HW40ES, HW50ES, HW55ES, HW58ES
67     CAT5_FULL(5, "Full", null, new byte[] { 0x00, 0x00 }),
68     CAT5_NORMAL(5, "Normal", null, new byte[] { 0x00, 0x01 }),
69     CAT5_WIDE(5, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
70     CAT5_ZOOM(5, "Zoom", null, new byte[] { 0x00, 0x03 }),
71     CAT5_V_STRETCH(5, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
72     CAT5_STRETCH(5, "Stretch", null, new byte[] { 0x00, 0x0E }),
73     CAT5_SQUEEZE(5, "Squeeze", null, new byte[] { 0x00, 0x0F }),
74
75     // Category 6: HW45ES, HW60, HW65, HW68
76     CAT6_NORMAL(6, "Normal", null, new byte[] { 0x00, 0x01 }),
77     CAT6_V_STRETCH(6, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
78     CAT6_STRETCH(6, "Stretch", null, new byte[] { 0x00, 0x0E }),
79     CAT6_SQUEEZE(6, "Squeeze", null, new byte[] { 0x00, 0x0F });
80
81     private int category;
82     private String name;
83     private @Nullable String label;
84     private byte[] dataCode;
85
86     /**
87      * Constructor
88      *
89      * @param category a category of projector models for which the aspect mode is available
90      * @param name the name of the aspect mode
91      * @param label the label of the aspect mode; can be null when the label is identical to the name
92      * @param dataCode the data code identifying the aspect mode
93      */
94     private SonyProjectorAspect(int category, String name, @Nullable String label, byte[] dataCode) {
95         this.category = category;
96         this.name = name;
97         this.label = label;
98         this.dataCode = dataCode;
99     }
100
101     /**
102      * Get the category of projector models for the current aspect mode
103      *
104      * @return the category of projector models
105      */
106     public int getCategory() {
107         return category;
108     }
109
110     /**
111      * Get the data code identifying the current aspect mode
112      *
113      * @return the data code
114      */
115     public byte[] getDataCode() {
116         return dataCode;
117     }
118
119     /**
120      * Get the label of the current aspect mode
121      *
122      * @return the label
123      */
124     public @Nullable String getLabel() {
125         return label;
126     }
127
128     /**
129      * Get the name of the current aspect mode
130      *
131      * @return the name
132      */
133     public String getName() {
134         return name;
135     }
136
137     /**
138      * Get the list of {@link StateOption} associated to the available aspect modes for a particular category of
139      * projector models
140      *
141      * @param category a category of projector models
142      *
143      * @return the list of {@link StateOption} associated to the available aspect modes for a provided category of
144      *         projector models
145      */
146     public static List<StateOption> getStateOptions(int category) {
147         List<StateOption> options = new ArrayList<>();
148         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
149             if (value.getCategory() == category) {
150                 options.add(new StateOption(value.getName(),
151                         value.getLabel() != null ? value.getLabel() : value.getName()));
152             }
153         }
154         return options;
155     }
156
157     /**
158      * Get the aspect mode associated to a name for a particular category of projector models
159      *
160      * @param category a category of projector models
161      * @param name the name used to identify the aspect mode
162      *
163      * @return the aspect mode associated to the searched name for the provided category of projector models
164      *
165      * @throws SonyProjectorException - If no aspect mode is associated to the searched name for the provided category
166      */
167     public static SonyProjectorAspect getFromName(int category, String name) throws SonyProjectorException {
168         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
169             if (value.getCategory() == category && value.getName().equals(name)) {
170                 return value;
171             }
172         }
173         throw new SonyProjectorException("Invalid name for an aspect mode: " + name);
174     }
175
176     /**
177      * Get the aspect mode associated to a data code for a particular category of projector models
178      *
179      * @param category a category of projector models
180      * @param dataCode the data code used to identify the aspect mode
181      *
182      * @return the aspect mode associated to the searched data code for the provided category of projector models
183      *
184      * @throws SonyProjectorException - If no aspect mode is associated to the searched data code for the provided
185      *             category
186      */
187     public static SonyProjectorAspect getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
188         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
189             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
190                 return value;
191             }
192         }
193         throw new SonyProjectorException("Invalid data code for an aspect mode: " + HexUtils.bytesToHex(dataCode));
194     }
195 }