]> git.basschouten.com Git - openhab-addons.git/blob
465383582c8e1178da1ece50b434eeb2800796e7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.CommandOption;
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, VW1000ES, VW1100ES
35     CAT1_NORMAL(1, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
36     CAT1_V_STRETCH(1, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
37     CAT1_185(1, "185", new byte[] { 0x00, 0x0C }, new byte[] { 0x1B, 0x45 }),
38     CAT1_235(1, "235", new byte[] { 0x00, 0x0D }, new byte[] { 0x1B, 0x46 }),
39     CAT1_STRETCH(1, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
40     CAT1_SQUEEZE(1, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 }),
41
42     // Category 2: VW40, VW50, HW10, HW15, HW20, HW30
43     CAT2_FULL(2, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
44     CAT2_NORMAL(2, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
45     CAT2_WIDE(2, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
46     CAT2_ZOOM(2, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
47     CAT2_FULL1(2, "Full1", new byte[] { 0x00, 0x07 }, new byte[] { 0x1B, 0x3F }),
48     CAT2_FULL2(2, "Full2", new byte[] { 0x00, 0x08 }, new byte[] { 0x1B, 0x40 }),
49
50     // Category 3: VW60, VW70, VW80, VW85, VW90, VW95, VW200
51     CAT3_FULL(3, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
52     CAT3_NORMAL(3, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
53     CAT3_WIDE(3, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
54     CAT3_ZOOM(3, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
55     CAT3_FULL1(3, "Full1", new byte[] { 0x00, 0x07 }, new byte[] { 0x1B, 0x3F }),
56     CAT3_FULL2(3, "Full2", new byte[] { 0x00, 0x08 }, new byte[] { 0x1B, 0x40 }),
57     CAT3_ANAMORPHIC(3, "Anamorphic", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
58
59     // Category 4: VW100
60     CAT4_FULL(4, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
61     CAT4_NORMAL(4, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
62     CAT4_WIDE(4, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
63     CAT4_ZOOM(4, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
64     CAT3_SUBTITLE(4, "Subtitle", new byte[] { 0x00, 0x04 }, new byte[] { 0x1B, 0x49 }), // IR code not confirmed
65
66     // Category 5: HW40ES, HW50ES, HW55ES, HW58ES
67     CAT5_FULL(5, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
68     CAT5_NORMAL(5, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
69     CAT5_WIDE(5, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
70     CAT5_ZOOM(5, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
71     CAT5_V_STRETCH(5, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
72     CAT5_STRETCH(5, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
73     CAT5_SQUEEZE(5, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 }),
74
75     // Category 6: HW45ES, HW60, HW65, HW68
76     CAT6_NORMAL(6, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
77     CAT6_V_STRETCH(6, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
78     CAT6_STRETCH(6, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
79     CAT6_SQUEEZE(6, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 });
80
81     private int category;
82     private String name;
83     private byte[] dataCode;
84     private byte[] irCode;
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 dataCode the data code identifying the aspect mode
92      * @param irCode the IR code for the aspect mode
93      */
94     private SonyProjectorAspect(int category, String name, byte[] dataCode, byte[] irCode) {
95         this.category = category;
96         this.name = name;
97         this.dataCode = dataCode;
98         this.irCode = irCode;
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 IR code for the current aspect mode
121      *
122      * @return the IR code
123      */
124     public byte[] getIrCode() {
125         return irCode;
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(), value.getName()));
151             }
152         }
153         return options;
154     }
155
156     /**
157      * Get the list of {@link CommandOption} associated to the available aspect modes for a particular category of
158      * projector models
159      *
160      * @param category a category of projector models
161      *
162      * @return the list of {@link CommandOption} associated to the available aspect modes for a provided category of
163      *         projector models
164      */
165     public static List<CommandOption> getCommandOptions(int category) {
166         List<CommandOption> options = new ArrayList<>();
167         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
168             if (value.getCategory() == category) {
169                 options.add(new CommandOption("ASPECT_" + value.getName().toUpperCase(),
170                         "@text/channel-type.sonyprojector.aspect.state.option." + value.getName()));
171             }
172         }
173         return options;
174     }
175
176     /**
177      * Get the aspect mode associated to a name for a particular category of projector models
178      *
179      * @param category a category of projector models
180      * @param name the name used to identify the aspect mode
181      *
182      * @return the aspect mode associated to the searched name for the provided category of projector models
183      *
184      * @throws SonyProjectorException - If no aspect mode is associated to the searched name for the provided category
185      */
186     public static SonyProjectorAspect getFromName(int category, String name) throws SonyProjectorException {
187         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
188             if (value.getCategory() == category && value.getName().equalsIgnoreCase(name)) {
189                 return value;
190             }
191         }
192         throw new SonyProjectorException("Invalid name for an aspect mode: " + name);
193     }
194
195     /**
196      * Get the aspect mode associated to a data code for a particular category of projector models
197      *
198      * @param category a category of projector models
199      * @param dataCode the data code used to identify the aspect mode
200      *
201      * @return the aspect mode associated to the searched data code for the provided category of projector models
202      *
203      * @throws SonyProjectorException - If no aspect mode is associated to the searched data code for the provided
204      *             category
205      */
206     public static SonyProjectorAspect getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
207         for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
208             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
209                 return value;
210             }
211         }
212         throw new SonyProjectorException("Invalid data code for an aspect mode: " + HexUtils.bytesToHex(dataCode));
213     }
214 }