]> git.basschouten.com Git - openhab-addons.git/blob
bd9fbe17f90d1441a0567a30a1d38543f1d75b1e
[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;
14
15 import java.nio.charset.StandardCharsets;
16 import java.util.ArrayList;
17 import java.util.Arrays;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorAspect;
22 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorBlockNr;
23 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorCalibrationPreset;
24 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorColorSpace;
25 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorColorTemp;
26 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorContrastEnhancer;
27 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorFilmMode;
28 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorFilmProjection;
29 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorGammaCorrection;
30 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorInput;
31 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorIrisMode;
32 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorIrisSensitivity;
33 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorLampControl;
34 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorMosquitoNr;
35 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorMotionEnhancer;
36 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorMpegNr;
37 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorNr;
38 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorPicturePosition;
39 import org.openhab.core.types.CommandOption;
40 import org.openhab.core.types.StateOption;
41
42 /**
43  * Represents the different supported projector models
44  *
45  * @author Laurent Garnier - Initial contribution
46  */
47 @NonNullByDefault
48 public enum SonyProjectorModel {
49
50     // HW models
51
52     HW10("VPL-HW10", false, 2, 2, 2, 1, true, 0, true, 2, 3, 3, true, true, 2, 2, true, true, 0, true, 3, 0, 0),
53     HW15("VPL-HW15", false, 2, 2, 2, 1, true, 0, true, 2, 3, 3, true, true, 3, 2, true, true, 0, true, 3, 0, 0),
54     HW20("VPL-HW20", false, 2, 2, 2, 1, true, 0, true, 2, 3, 3, true, true, 3, 2, true, true, 0, true, 3, 0, 0),
55     HW30ES("VPL-HW30ES", false, 4, 3, 3, 2, true, 0, true, 2, 4, 3, true, true, 4, 2, true, true, 0, true, 4, 0, 0),
56     HW35ES("VPL-HW35ES", false, 1, 3, 1, 2, true, 0, true, 5, 6, 0, false, false, 6, 2, false, false, 2, true, 6, 3, 2),
57     HW40ES("VPL-HW40ES", false, 1, 3, 1, 2, true, 0, true, 5, 6, 0, false, false, 6, 2, false, false, 2, true, 6, 3, 2),
58     HW45ES("VPL-HW45ES", false, 1, 1, 1, 1, true, 0, false, 6, 6, 0, false, false, 6, 2, false, false, 2, true, 6, 0,
59             1),
60     HW50ES("VPL-HW50ES", false, 1, 3, 1, 2, true, 0, true, 5, 7, 5, true, false, 1, 2, false, false, 2, true, 6, 3, 2),
61     HW55ES("VPL-HW55ES", false, 1, 3, 1, 2, true, 0, true, 5, 7, 5, true, false, 1, 2, false, false, 2, true, 6, 3, 2),
62     HW58ES("VPL-HW58ES", false, 1, 3, 1, 2, true, 0, true, 5, 6, 0, false, false, 6, 2, false, false, 2, true, 6, 3, 2),
63     HW60("VPL-HW60", true, 1, 1, 1, 1, true, 0, false, 6, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
64     HW65("VPL-HW65", true, 1, 1, 1, 1, true, 0, false, 6, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
65     HW68("VPL-HW68", true, 1, 1, 1, 1, true, 0, false, 6, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
66
67     // VW models
68
69     // VW10HT("VPL-VW10HT", false, 2, 1, 1, 1, true, 0, true, 1, 1, 1, true, false, 2, 2, true, true, 0, true, 3, 0, 0),
70     // VW11HT("VPL-VW11HT", false, 2, 1, 1, 1, true, 0, true, 1, 1, 1, true, false, 2, 2, true, true, 0, true, 3, 0, 0),
71     // VW12HT("VPL-VW12HT", false, 2, 1, 1, 1, true, 0, true, 1, 1, 1, true, false, 2, 2, true, true, 0, true, 3, 0, 0),
72
73     VW40("VPL-VW40", false, 2, 2, 2, 0, true, 0, true, 2, 2, 2, true, true, 2, 2, false, false, 0, false, 3, 0, 0),
74     VW50("VPL-VW50", false, 2, 2, 2, 0, true, 0, true, 2, 2, 2, true, true, 2, 2, false, false, 0, false, 3, 0, 0),
75     VW60("VPL-VW60", false, 2, 2, 2, 0, true, 0, true, 3, 2, 2, true, true, 2, 2, false, false, 0, false, 3, 0, 0),
76     VW70("VPL-VW70", false, 2, 2, 2, 1, true, 0, true, 3, 3, 3, true, true, 3, 2, true, true, 0, true, 3, 0, 0),
77     VW80("VPL-VW80", false, 2, 2, 2, 2, true, 0, true, 3, 3, 3, true, true, 3, 2, true, true, 0, true, 3, 1, 2),
78     VW85("VPL-VW85", false, 3, 2, 3, 2, true, 0, true, 3, 4, 3, true, true, 5, 2, true, true, 0, true, 4, 1, 2),
79     VW90("VPL-VW90ES", false, 3, 5, 3, 2, true, 0, true, 3, 4, 3, true, true, 5, 2, true, true, 0, true, 4, 2, 2),
80     VW95("VPL-VW95ES", false, 4, 3, 3, 2, true, 2, true, 3, 4, 3, true, true, 5, 2, true, true, 0, true, 4, 2, 2),
81
82     VW100("VPL-VW100", false, 2, 4, 2, 3, false, 0, true, 4, 2, 4, false, false, 2, 2, false, false, 0, false, 3, 0, 0),
83
84     VW200("VPL-VW200", false, 2, 2, 2, 2, false, 0, true, 3, 2, 3, true, true, 2, 2, false, false, 0, true, 3, 1, 2),
85     VW260("VPL-VW260ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 2, 0, 1),
86     VW270("VPL-VW270ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 2, 0, 3),
87     VW285("VPL-VW285ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 2, 0, 1),
88     VW295("VPL-VW295ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 2, 0, 3),
89
90     VW300("VPL-VW300ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
91     VW315("VPL-VW315", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
92     VW320("VPL-VW320", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
93     VW328("VPL-VW328", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
94     VW350("VPL-VW350ES", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
95     // VW360("VPL-VW360ES", false, 2, 4, 2, 3, true, 0, true, 1, 1, 1, true, false, 1, 2, false, false, 1, true, 1, 0,
96     // 1),
97     VW365("VPL-VW365", true, 1, 1, 1, 1, true, 0, false, 1, 1, 0, false, false, 1, 1, false, false, 1, true, 1, 0, 1),
98     VW385("VPL-VW385ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
99
100     VW500("VPL-VW500ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
101     VW515("VPL-VW515", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
102     VW520("VPL-VW520", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
103     VW528("VPL-VW528", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
104     VW550("VPL-VW550ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
105     VW570("VPL-VW570ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
106
107     VW600("VPL-VW600ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 1, 0, 1),
108     VW665("VPL-VW665", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
109     VW675("VPL-VW675ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
110     // VW685("VPL-VW685ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0,
111     // 1),
112     VW695("VPL-VW695ES", true, 1, 1, 1, 1, true, 1, false, 1, 1, 1, true, false, 1, 1, false, false, 1, true, 2, 0, 1),
113
114     VW760("VPL-VW760ES", true, 1, 1, 1, 1, false, 1, false, 1, 1, 1, false, false, 1, 1, false, false, 1, true, 2, 0,
115             1),
116
117     VW870("VPL-VW870ES", true, 1, 1, 1, 1, false, 1, false, 1, 1, 1, false, false, 1, 1, false, false, 1, true, 2, 0,
118             1),
119     VW885("VPL-VW885ES", true, 1, 1, 1, 1, false, 1, false, 1, 1, 1, false, false, 1, 1, false, false, 1, true, 2, 0,
120             1),
121
122     VW995("VPL-VW995ES", true, 1, 1, 1, 1, false, 1, false, 1, 1, 1, false, false, 1, 1, false, false, 1, true, 2, 0,
123             1),
124
125     VW1000ES("VPL-VW1000ES", false, 5, 3, 1, 2, true, 1, true, 1, 5, 5, true, false, 1, 2, false, false, 2, true, 5, 3,
126             2),
127     VW1100ES("VPL-VW1100ES", false, 5, 3, 1, 2, true, 1, true, 1, 5, 5, true, false, 1, 2, false, false, 2, true, 5, 3,
128             2);
129
130     // VW5000ES("VPL-VW5000ES", false, 5, 3, 1, 2, true, 0, true, 1, 5, 5, true, false, 1, 2, false, false, 2, true, 5,
131     // 3, 2);
132
133     private String name;
134     private boolean powerCmdAvailable;
135     private int calibrPresetsCategory;
136     private int inputCategory;
137     private int contrastEnhancerCategory;
138     private int filmModeCategory;
139     private boolean lampControlAvailable;
140     private int picturePositionCategory;
141     private boolean overscanAvailable;
142     private int aspectCategory;
143     private int colorTempCategory;
144     private int irisModeCategory;
145     private boolean irisManualAvailable;
146     private boolean irisSensitivityAvailable;
147     private int gammaCorrectionCategory;
148     private int nrCategory;
149     private boolean blockNrAvailable;
150     private boolean mosquitoNrAvailable;
151     private int mpegNrCategory;
152     private boolean xvColorAvailable;
153     private int colorSpaceCategory;
154     private int filmProjectionCategory;
155     private int motionEnhancerCategory;
156
157     /**
158      * Constructor
159      *
160      * @param name the model name
161      * @param powerCmdAvailable true if the POWER command is available
162      * @param calibrPresetsCategory the category from {@link SonyProjectorCalibrationPreset}
163      * @param inputCategory the category from {@link SonyProjectorInput}
164      * @param contrastEnhancerCategory the category from {@link SonyProjectorContrastEnhancer}
165      * @param filmModeCategory the category from {@link SonyProjectorFilmMode}
166      * @param lampControlAvailable true if the lamp control setting is available
167      * @param picturePositionCategory the category from {@link SonyProjectorPicturePosition}
168      * @param overscanAvailable true if the overscan setting is available
169      * @param aspectCategory the category from {@link SonyProjectorAspect}
170      * @param colorTempCategory the category from {@link SonyProjectorColorTemp}
171      * @param irisModeCategory the category from {@link SonyProjectorIrisMode}
172      * @param irisManualAvailable true if the iris manual setting is available
173      * @param irisSensitivityAvailable true if the iris sensitivity setting is available
174      * @param gammaCorrectionCategory the category from {@link SonyProjectorGammaCorrection}
175      * @param nrCategory the category from {@link SonyProjectorNr}
176      * @param blockNrAvailable true if the block noise reduction setting is available
177      * @param mosquitoNrAvailable true if the mosquito noise reduction setting is available
178      * @param mpegNrCategory the category from {@link SonyProjectorMpegNr}
179      * @param xvColorAvailable true if the xvColor setting is available
180      * @param colorSpaceCategory the category from {@link SonyProjectorColorSpace}
181      * @param filmProjectionCategory the category from {@link SonyProjectorFilmProjection}
182      * @param motionEnhancerCategory the category from {@link SonyProjectorMotionEnhancer}
183      */
184     private SonyProjectorModel(String name, boolean powerCmdAvailable, int calibrPresetsCategory, int inputCategory,
185             int contrastEnhancerCategory, int filmModeCategory, boolean lampControlAvailable,
186             int picturePositionCategory, boolean overscanAvailable, int aspectCategory, int colorTempCategory,
187             int irisModeCategory, boolean irisManualAvailable, boolean irisSensitivityAvailable,
188             int gammaCorrectionCategory, int nrCategory, boolean blockNrAvailable, boolean mosquitoNrAvailable,
189             int mpegNrCategory, boolean xvColorAvailable, int colorSpaceCategory, int filmProjectionCategory,
190             int motionEnhancerCategory) {
191         this.name = name;
192         this.powerCmdAvailable = powerCmdAvailable;
193         this.calibrPresetsCategory = calibrPresetsCategory;
194         this.inputCategory = inputCategory;
195         this.contrastEnhancerCategory = contrastEnhancerCategory;
196         this.filmModeCategory = filmModeCategory;
197         this.lampControlAvailable = lampControlAvailable;
198         this.picturePositionCategory = picturePositionCategory;
199         this.overscanAvailable = overscanAvailable;
200         this.aspectCategory = aspectCategory;
201         this.colorTempCategory = colorTempCategory;
202         this.irisModeCategory = irisModeCategory;
203         this.irisManualAvailable = irisManualAvailable;
204         this.irisSensitivityAvailable = irisSensitivityAvailable;
205         this.gammaCorrectionCategory = gammaCorrectionCategory;
206         this.nrCategory = nrCategory;
207         this.blockNrAvailable = blockNrAvailable;
208         this.mosquitoNrAvailable = mosquitoNrAvailable;
209         this.mpegNrCategory = mpegNrCategory;
210         this.xvColorAvailable = xvColorAvailable;
211         this.colorSpaceCategory = colorSpaceCategory;
212         this.filmProjectionCategory = filmProjectionCategory;
213         this.motionEnhancerCategory = motionEnhancerCategory;
214     }
215
216     /**
217      * Get the model name
218      *
219      * @return the model name
220      */
221     public String getName() {
222         return name;
223     }
224
225     /**
226      * Inform whether the POWER command is available
227      *
228      * @return true if the POWER command is available
229      */
230     public boolean isPowerCmdAvailable() {
231         return powerCmdAvailable;
232     }
233
234     /**
235      * Get the list of {@link StateOption} associated to the available calibration presets
236      *
237      * @return the list of {@link StateOption} associated to the available calibration presets
238      */
239     public List<StateOption> getCalibrPresetStateOptions() {
240         return SonyProjectorCalibrationPreset.getStateOptions(calibrPresetsCategory);
241     }
242
243     /**
244      * Get the list of {@link CommandOption} associated to the available calibration presets
245      *
246      * @return the list of {@link CommandOption} associated to the available calibration presets
247      */
248     public List<CommandOption> getCalibrPresetCommandOptions() {
249         return SonyProjectorCalibrationPreset.getCommandOptions(calibrPresetsCategory);
250     }
251
252     /**
253      * Get the calibration preset associated to a name
254      *
255      * @param name the name used to identify the calibration preset
256      *
257      * @return the calibration preset associated to the searched name
258      *
259      * @throws SonyProjectorException - If no calibration preset is associated to the searched name
260      */
261     public SonyProjectorCalibrationPreset getCalibrPresetFromName(String name) throws SonyProjectorException {
262         return SonyProjectorCalibrationPreset.getFromName(calibrPresetsCategory, name);
263     }
264
265     /**
266      * Get the calibration preset associated to a data code
267      *
268      * @param dataCode the data code used to identify the calibration preset
269      *
270      * @return the calibration preset associated to the searched data code
271      *
272      * @throws SonyProjectorException - If no calibration preset is associated to the searched data code
273      */
274     public String getCalibrPresetNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
275         return SonyProjectorCalibrationPreset.getFromDataCode(calibrPresetsCategory, dataCode).getName();
276     }
277
278     /**
279      * Get the list of {@link StateOption} associated to the available video inputs
280      *
281      * @return the list of {@link StateOption} associated to the available video inputs
282      */
283     public List<StateOption> getInputStateOptions() {
284         return SonyProjectorInput.getStateOptions(inputCategory);
285     }
286
287     /**
288      * Get the list of {@link CommandOption} associated to the available video inputs
289      *
290      * @return the list of {@link CommandOption} associated to the available video inputs
291      */
292     public List<CommandOption> getInputCommandOptions() {
293         return SonyProjectorInput.getCommandOptions(inputCategory);
294     }
295
296     /**
297      * Get the video input associated to a name
298      *
299      * @param name the name used to identify the video input
300      *
301      * @return the video input associated to the searched name
302      *
303      * @throws SonyProjectorException - If no video input is associated to the searched name
304      */
305     public SonyProjectorInput getInputFromName(String name) throws SonyProjectorException {
306         return SonyProjectorInput.getFromName(inputCategory, name);
307     }
308
309     /**
310      * Get the video input associated to a data code
311      *
312      * @param dataCode the data code used to identify the video input
313      *
314      * @return the video input associated to the searched data code
315      *
316      * @throws SonyProjectorException - If no video input is associated to the searched data code
317      */
318     public String getInputNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
319         return SonyProjectorInput.getFromDataCode(inputCategory, dataCode).getName();
320     }
321
322     /**
323      * Get the list of {@link StateOption} associated to the available contrast enhancer modes
324      *
325      * @return the list of {@link StateOption} associated to the available contrast enhancer modes
326      */
327     public List<StateOption> getContrastEnhancerStateOptions() {
328         return SonyProjectorContrastEnhancer.getStateOptions(contrastEnhancerCategory);
329     }
330
331     /**
332      * Get the contrast enhancer mode associated to a name
333      *
334      * @param name the name used to identify the contrast enhancer mode
335      *
336      * @return the contrast enhancer mode associated to the searched name
337      *
338      * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched name
339      */
340     public byte[] getContrastEnhancerDataCodeFromName(String name) throws SonyProjectorException {
341         return SonyProjectorContrastEnhancer.getFromName(contrastEnhancerCategory, name).getDataCode();
342     }
343
344     /**
345      * Get the contrast enhancer mode associated to a data code
346      *
347      * @param dataCode the data code used to identify the contrast enhancer mode
348      *
349      * @return the contrast enhancer mode associated to the searched data code
350      *
351      * @throws SonyProjectorException - If no contrast enhancer mode is associated to the searched data code
352      */
353     public String getContrastEnhancerNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
354         return SonyProjectorContrastEnhancer.getFromDataCode(contrastEnhancerCategory, dataCode).getName();
355     }
356
357     /**
358      * Get the list of {@link StateOption} associated to the available film modes
359      *
360      * @return the list of {@link StateOption} associated to the available film modes
361      */
362     public List<StateOption> getFilmModeStateOptions() {
363         return SonyProjectorFilmMode.getStateOptions(filmModeCategory);
364     }
365
366     /**
367      * Inform whether the film mode setting is available
368      *
369      * @return true if the film mode setting is available
370      */
371     public boolean isFilmModeAvailable() {
372         return filmModeCategory > 0;
373     }
374
375     /**
376      * Get the film mode associated to a name
377      *
378      * @param name the name used to identify the film mode
379      *
380      * @return the film mode associated to the searched name
381      *
382      * @throws SonyProjectorException - If no film mode is associated to the searched name
383      */
384     public byte[] getFilmModeDataCodeFromName(String name) throws SonyProjectorException {
385         return SonyProjectorFilmMode.getFromName(filmModeCategory, name).getDataCode();
386     }
387
388     /**
389      * Get the film mode associated to a data code
390      *
391      * @param dataCode the data code used to identify the film mode
392      *
393      * @return the film mode associated to the searched data code
394      *
395      * @throws SonyProjectorException - If no film mode is associated to the searched data code
396      */
397     public String getFilmModeNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
398         return SonyProjectorFilmMode.getFromDataCode(filmModeCategory, dataCode).getName();
399     }
400
401     /**
402      * Get the list of {@link StateOption} associated to the available lamp control modes
403      *
404      * @return the list of {@link StateOption} associated to the available lamp control modes
405      */
406     public List<StateOption> getLampControlStateOptions() {
407         return lampControlAvailable ? SonyProjectorLampControl.getStateOptions() : new ArrayList<>();
408     }
409
410     /**
411      * Inform whether the lamp control setting is available
412      *
413      * @return true if the lamp control setting is available
414      */
415     public boolean isLampControlAvailable() {
416         return lampControlAvailable;
417     }
418
419     /**
420      * Get the list of {@link StateOption} associated to the available picture positions
421      *
422      * @return the list of {@link StateOption} associated to the available picture positions
423      */
424     public List<StateOption> getPicturePositionStateOptions() {
425         return SonyProjectorPicturePosition.getStateOptions(picturePositionCategory);
426     }
427
428     /**
429      * Inform whether the picture position setting is available
430      *
431      * @return true if the picture position setting is available
432      */
433     public boolean isPicturePositionAvailable() {
434         return picturePositionCategory > 0;
435     }
436
437     /**
438      * Get the picture position associated to a name
439      *
440      * @param name the name used to identify the picture position
441      *
442      * @return the picture position associated to the searched name
443      *
444      * @throws SonyProjectorException - If no picture position is associated to the searched name
445      */
446     public byte[] getPicturePositionCodeFromName(String name) throws SonyProjectorException {
447         return SonyProjectorPicturePosition.getFromName(picturePositionCategory, name).getDataCode();
448     }
449
450     /**
451      * Get the picture position associated to a data code
452      *
453      * @param dataCode the data code used to identify the picture position
454      *
455      * @return the picture position associated to the searched data code
456      *
457      * @throws SonyProjectorException - If no picture position is associated to the searched data code
458      */
459     public String getPicturePositionNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
460         return SonyProjectorPicturePosition.getFromDataCode(picturePositionCategory, dataCode).getName();
461     }
462
463     /**
464      * Get the list of {@link StateOption} associated to the available aspect modes
465      *
466      * @return the list of {@link StateOption} associated to the available aspect modes
467      */
468     public List<StateOption> getAspectStateOptions() {
469         return SonyProjectorAspect.getStateOptions(aspectCategory);
470     }
471
472     /**
473      * Get the list of {@link CommandOption} associated to the available aspect modes
474      *
475      * @return the list of {@link CommandOption} associated to the available aspect modes
476      */
477     public List<CommandOption> getAspectCommandOptions() {
478         return SonyProjectorAspect.getCommandOptions(aspectCategory);
479     }
480
481     /**
482      * Get the aspect mode associated to a name
483      *
484      * @param name the name used to identify the aspect mode
485      *
486      * @return the aspect mode associated to the searched name
487      *
488      * @throws SonyProjectorException - If no aspect mode is associated to the searched name
489      */
490     public SonyProjectorAspect getAspectFromName(String name) throws SonyProjectorException {
491         return SonyProjectorAspect.getFromName(aspectCategory, name);
492     }
493
494     /**
495      * Get the aspect mode associated to a data code
496      *
497      * @param dataCode the data code used to identify the aspect mode
498      *
499      * @return the aspect mode associated to the searched data code
500      *
501      * @throws SonyProjectorException - If no aspect mode is associated to the searched data code
502      */
503     public String getAspectNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
504         return SonyProjectorAspect.getFromDataCode(aspectCategory, dataCode).getName();
505     }
506
507     /**
508      * Get the list of {@link StateOption} associated to the available color temperatures
509      *
510      * @return the list of {@link StateOption} associated to the available color temperatures
511      */
512     public List<StateOption> getColorTempStateOptions() {
513         return SonyProjectorColorTemp.getStateOptions(colorTempCategory);
514     }
515
516     /**
517      * Get the color temperature associated to a name
518      *
519      * @param name the name used to identify the color temperature
520      *
521      * @return the color temperature associated to the searched name
522      *
523      * @throws SonyProjectorException - If no color temperature is associated to the searched name
524      */
525     public byte[] getColorTempCodeFromName(String name) throws SonyProjectorException {
526         return SonyProjectorColorTemp.getFromName(colorTempCategory, name).getDataCode();
527     }
528
529     /**
530      * Get the color temperature associated to a data code
531      *
532      * @param dataCode the data code used to identify the color temperature
533      *
534      * @return the color temperature associated to the searched data code
535      *
536      * @throws SonyProjectorException - If no color temperature is associated to the searched data code
537      */
538     public String getColorTempNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
539         return SonyProjectorColorTemp.getFromDataCode(colorTempCategory, dataCode).getName();
540     }
541
542     /**
543      * Get the list of {@link StateOption} associated to the available iris modes
544      *
545      * @return the list of {@link StateOption} associated to the available iris modes
546      */
547     public List<StateOption> getIrisModeStateOptions() {
548         return SonyProjectorIrisMode.getStateOptions(irisModeCategory);
549     }
550
551     /**
552      * Inform whether the iris mode setting is available
553      *
554      * @return true if the iris mode setting is available
555      */
556     public boolean isIrisModeAvailable() {
557         return irisModeCategory > 0;
558     }
559
560     /**
561      * Get the iris mode associated to a name
562      *
563      * @param name the name used to identify the iris mode
564      *
565      * @return the iris mode associated to the searched name
566      *
567      * @throws SonyProjectorException - If no iris mode is associated to the searched name
568      */
569     public byte[] getIrisModeCodeFromName(String name) throws SonyProjectorException {
570         return SonyProjectorIrisMode.getFromName(irisModeCategory, name).getDataCode();
571     }
572
573     /**
574      * Get the iris mode associated to a data code
575      *
576      * @param dataCode the data code used to identify the iris mode
577      *
578      * @return the iris mode associated to the searched data code
579      *
580      * @throws SonyProjectorException - If no iris mode is associated to the searched data code
581      */
582     public String getIrisModeNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
583         return SonyProjectorIrisMode.getFromDataCode(irisModeCategory, dataCode).getName();
584     }
585
586     /**
587      * Inform whether the overscan setting is available
588      *
589      * @return true if the overscan setting is available
590      */
591     public boolean isOverscanAvailable() {
592         return overscanAvailable;
593     }
594
595     /**
596      * Inform whether the iris manual setting is available
597      *
598      * @return true if the iris manual setting is available
599      */
600     public boolean isIrisManualAvailable() {
601         return irisManualAvailable;
602     }
603
604     /**
605      * Get the list of {@link StateOption} associated to the available iris sensitivities
606      *
607      * @return the list of {@link StateOption} associated to the available iris sensitivities
608      */
609     public List<StateOption> getIrisSensitivityStateOptions() {
610         return irisSensitivityAvailable ? SonyProjectorIrisSensitivity.getStateOptions() : new ArrayList<>();
611     }
612
613     /**
614      * Inform whether the iris sensitivity setting is available
615      *
616      * @return true if the iris sensitivity setting is available
617      */
618     public boolean isIrisSensitivityAvailable() {
619         return irisSensitivityAvailable;
620     }
621
622     /**
623      * Get the list of {@link StateOption} associated to the available gamma corrections
624      *
625      * @return the list of {@link StateOption} associated to the available gamma corrections
626      */
627     public List<StateOption> getGammaCorrectionStateOptions() {
628         return SonyProjectorGammaCorrection.getStateOptions(gammaCorrectionCategory);
629     }
630
631     /**
632      * Get the gamma correction associated to a name
633      *
634      * @param name the name used to identify the gamma correction
635      *
636      * @return the gamma correction associated to the searched name
637      *
638      * @throws SonyProjectorException - If no gamma correction is associated to the searched name
639      */
640     public byte[] getGammaCorrectionCodeFromName(String name) throws SonyProjectorException {
641         return SonyProjectorGammaCorrection.getFromName(gammaCorrectionCategory, name).getDataCode();
642     }
643
644     /**
645      * Get the gamma correction associated to a data code
646      *
647      * @param dataCode the data code used to identify the gamma correction
648      *
649      * @return the gamma correction associated to the searched data code
650      *
651      * @throws SonyProjectorException - If no gamma correction is associated to the searched data code
652      */
653     public String getGammaCorrectionNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
654         return SonyProjectorGammaCorrection.getFromDataCode(gammaCorrectionCategory, dataCode).getName();
655     }
656
657     /**
658      * Get the list of {@link StateOption} associated to the available nose reduction modes
659      *
660      * @return the list of {@link StateOption} associated to the available nose reduction modes
661      */
662     public List<StateOption> getNrStateOptions() {
663         return SonyProjectorNr.getStateOptions(nrCategory);
664     }
665
666     /**
667      * Get the noise reduction mode associated to a name
668      *
669      * @param name the name used to identify the noise reduction mode
670      *
671      * @return the noise reduction mode associated to the searched name
672      *
673      * @throws SonyProjectorException - If no noise reduction mode is associated to the searched name
674      */
675     public byte[] getNrCodeFromName(String name) throws SonyProjectorException {
676         return SonyProjectorNr.getFromName(nrCategory, name).getDataCode();
677     }
678
679     /**
680      * Get the noise reduction mode associated to a data code
681      *
682      * @param dataCode the data code used to identify the noise reduction mode
683      *
684      * @return the noise reduction mode associated to the searched data code
685      *
686      * @throws SonyProjectorException - If no noise reduction mode is associated to the searched data code
687      */
688     public String getNrNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
689         return SonyProjectorNr.getFromDataCode(nrCategory, dataCode).getName();
690     }
691
692     /**
693      * Get the list of {@link StateOption} associated to the available block nose reduction modes
694      *
695      * @return the list of {@link StateOption} associated to the available block nose reduction modes
696      */
697     public List<StateOption> getBlockNrStateOptions() {
698         return blockNrAvailable ? SonyProjectorBlockNr.getStateOptions() : new ArrayList<>();
699     }
700
701     /**
702      * Inform whether the block noise reduction setting is available
703      *
704      * @return true if the block noise reduction setting is available
705      */
706     public boolean isBlockNrAvailable() {
707         return blockNrAvailable;
708     }
709
710     /**
711      * Get the list of {@link StateOption} associated to the available mosquito nose reduction modes
712      *
713      * @return the list of {@link StateOption} associated to the available mosquito nose reduction modes
714      */
715     public List<StateOption> getMosquitoNrStateOptions() {
716         return mosquitoNrAvailable ? SonyProjectorMosquitoNr.getStateOptions() : new ArrayList<>();
717     }
718
719     /**
720      * Inform whether the mosquito noise reduction setting is available
721      *
722      * @return true if the mosquito noise reduction setting is available
723      */
724     public boolean isMosquitoNrAvailable() {
725         return mosquitoNrAvailable;
726     }
727
728     /**
729      * Get the list of {@link StateOption} associated to the available MPEG nose reduction modes
730      *
731      * @return the list of {@link StateOption} associated to the available MPEG nose reduction modes
732      */
733     public List<StateOption> getMpegNrStateOptions() {
734         return SonyProjectorMpegNr.getStateOptions(mpegNrCategory);
735     }
736
737     /**
738      * Inform whether the MPEG noise reduction setting is available
739      *
740      * @return true if the MPEG noise reduction setting is available
741      */
742     public boolean isMpegNrAvailable() {
743         return mpegNrCategory > 0;
744     }
745
746     /**
747      * Get the MPEG noise reduction mode associated to a name
748      *
749      * @param name the name used to identify the MPEG noise reduction mode
750      *
751      * @return the MPEG noise reduction mode associated to the searched name
752      *
753      * @throws SonyProjectorException - If no MPEG noise reduction mode is associated to the searched name
754      */
755     public byte[] getMpegNrCodeFromName(String name) throws SonyProjectorException {
756         return SonyProjectorMpegNr.getFromName(mpegNrCategory, name).getDataCode();
757     }
758
759     /**
760      * Get the MPEG noise reduction mode associated to a data code
761      *
762      * @param dataCode the data code used to identify the MPEG noise reduction mode
763      *
764      * @return the MPEG noise reduction mode associated to the searched data code
765      *
766      * @throws SonyProjectorException - If no MPEG noise reduction mode is associated to the searched data code
767      */
768     public String getMpegNrNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
769         return SonyProjectorMpegNr.getFromDataCode(mpegNrCategory, dataCode).getName();
770     }
771
772     /**
773      * Inform whether the xvColor setting is available
774      *
775      * @return true if the xvColor setting is available
776      */
777     public boolean isXvColorAvailable() {
778         return xvColorAvailable;
779     }
780
781     /**
782      * Get the list of {@link StateOption} associated to the available color spaces
783      *
784      * @return the list of {@link StateOption} associated to the available color spaces
785      */
786     public List<StateOption> getColorSpaceStateOptions() {
787         return SonyProjectorColorSpace.getStateOptions(colorSpaceCategory);
788     }
789
790     /**
791      * Get the color space associated to a name
792      *
793      * @param name the name used to identify the color space
794      *
795      * @return the color space associated to the searched name
796      *
797      * @throws SonyProjectorException - If no color space is associated to the searched name
798      */
799     public byte[] getColorSpaceCodeFromName(String name) throws SonyProjectorException {
800         return SonyProjectorColorSpace.getFromName(colorSpaceCategory, name).getDataCode();
801     }
802
803     /**
804      * Get the color space associated to a data code
805      *
806      * @param dataCode the data code used to identify the color space
807      *
808      * @return the color space associated to the searched data code
809      *
810      * @throws SonyProjectorException - If no color space is associated to the searched data code
811      */
812     public String getColorSpaceNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
813         return SonyProjectorColorSpace.getFromDataCode(colorSpaceCategory, dataCode).getName();
814     }
815
816     /**
817      * Get the list of {@link StateOption} associated to the available film projection modes
818      *
819      * @return the list of {@link StateOption} associated to the available film projection modes
820      */
821     public List<StateOption> getFilmProjectionStateOptions() {
822         return SonyProjectorFilmProjection.getStateOptions(filmProjectionCategory);
823     }
824
825     /**
826      * Inform whether the film projection setting is available
827      *
828      * @return true if the film projection setting is available
829      */
830     public boolean isFilmProjectionAvailable() {
831         return filmProjectionCategory > 0;
832     }
833
834     /**
835      * Get the film projection mode associated to a name
836      *
837      * @param name the name used to identify the film projection mode
838      *
839      * @return the film projection mode associated to the searched name
840      *
841      * @throws SonyProjectorException - If no film projection mode is associated to the searched name
842      */
843     public byte[] getFilmProjectionCodeFromName(String name) throws SonyProjectorException {
844         return SonyProjectorFilmProjection.getFromName(filmProjectionCategory, name).getDataCode();
845     }
846
847     /**
848      * Get the film projection mode associated to a data code
849      *
850      * @param dataCode the data code used to identify the film projection mode
851      *
852      * @return the film projection mode associated to the searched data code
853      *
854      * @throws SonyProjectorException - If no film projection mode is associated to the searched data code
855      */
856     public String getFilmProjectionNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
857         return SonyProjectorFilmProjection.getFromDataCode(filmProjectionCategory, dataCode).getName();
858     }
859
860     /**
861      * Get the list of {@link StateOption} associated to the available motion enhancer modes
862      *
863      * @return the list of {@link StateOption} associated to the available motion enhancer modes
864      */
865     public List<StateOption> getMotionEnhancerStateOptions() {
866         return SonyProjectorMotionEnhancer.getStateOptions(motionEnhancerCategory);
867     }
868
869     /**
870      * Inform whether the motion enhancer setting is available
871      *
872      * @return true if the motion enhancer setting is available
873      */
874     public boolean isMotionEnhancerAvailable() {
875         return motionEnhancerCategory > 0;
876     }
877
878     /**
879      * Get the motion enhancer mode associated to a name
880      *
881      * @param name the name used to identify the motion enhancer mode
882      *
883      * @return the motion enhancer mode associated to the searched name
884      *
885      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched name
886      */
887     public byte[] getMotionEnhancerCodeFromName(String name) throws SonyProjectorException {
888         return SonyProjectorMotionEnhancer.getFromName(motionEnhancerCategory, name).getDataCode();
889     }
890
891     /**
892      * Get the motion enhancer mode associated to a data code
893      *
894      * @param dataCode the data code used to identify the motion enhancer mode
895      *
896      * @return the motion enhancer mode associated to the searched data code
897      *
898      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched data code
899      */
900     public String getMotionEnhancerNameFromDataCode(byte[] dataCode) throws SonyProjectorException {
901         return SonyProjectorMotionEnhancer.getFromDataCode(motionEnhancerCategory, dataCode).getName();
902     }
903
904     /**
905      * Get the projector model mode associated to a name
906      *
907      * @param name the name used to identify the projector model
908      * @param strict true for a strict matching with the searched name
909      *
910      * @return the projector model associated to the searched name
911      *
912      * @throws SonyProjectorException - If no projector model is associated to the searched name
913      */
914     public static SonyProjectorModel getFromName(String name, boolean strict) throws SonyProjectorException {
915         String otherName = lessStrictName(name);
916         for (SonyProjectorModel value : SonyProjectorModel.values()) {
917             if (strict && value.getName().equals(name)) {
918                 return value;
919             } else if (!strict && lessStrictName(value.getName()).equals(otherName)) {
920                 return value;
921             }
922         }
923         throw new SonyProjectorException("Invalid model name: " + name);
924     }
925
926     private static String lessStrictName(String name) {
927         // Ignore the ending letters
928         String newName = name;
929         byte[] data = name.getBytes();
930         // Search the first number, starting at right
931         int last = data.length - 1;
932         for (int i = last; i >= 0; i--) {
933             if (((char) data[i]) >= '0' && ((char) data[i]) <= '9') {
934                 last = i;
935                 break;
936             }
937         }
938         byte[] newData = Arrays.copyOf(data, last + 1);
939         newName = new String(newData, StandardCharsets.UTF_8);
940         return newName;
941     }
942 }