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