]> git.basschouten.com Git - openhab-addons.git/blob
877d1ad5f3159eb701ca24036429db4dad2e0f95
[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 calibration presets available for the projector
27  *
28  * @author Markus Wehrle - Initial contribution
29  * @author Laurent Garnier - Transform into an enum and consider differences between models
30  */
31 @NonNullByDefault
32 public enum SonyProjectorCalibrationPreset {
33
34     // Category 1: VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515, VW520,
35     // VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW40ES, HW45ES, HW50ES, HW55ES,
36     // HW58ES, HW60, HW65, HW68
37     CAT1_CINEMA_FILM1(1, "Film1", "Cinema Film 1", new byte[] { 0x00, 0x00 }),
38     CAT1_CINEMA_FILM2(1, "Film2", "Cinema Film 2", new byte[] { 0x00, 0x01 }),
39     CAT1_REFERENCE(1, "Reference", null, new byte[] { 0x00, 0x02 }),
40     CAT1_TV(1, "TV", null, new byte[] { 0x00, 0x03 }),
41     CAT1_PHOTO(1, "Photo", null, new byte[] { 0x00, 0x04 }),
42     CAT1_GAME(1, "Game", null, new byte[] { 0x00, 0x05 }),
43     CAT1_BRT_CINE(1, "BRTCINE", "Bright Cinema", new byte[] { 0x00, 0x06 }),
44     CAT1_BRT_TV(1, "BRTTV", "Bright TV", new byte[] { 0x00, 0x07 }),
45     CAT1_USER(1, "User", null, new byte[] { 0x00, 0x08 }),
46
47     // Category 2: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
48     CAT2_DYNAMIC(2, "Dynamic", null, new byte[] { 0x00, 0x00 }),
49     CAT2_STANDARD(2, "Standard", null, new byte[] { 0x00, 0x01 }),
50     CAT2_CINEMA(2, "Cinema", null, new byte[] { 0x00, 0x02 }),
51     CAT2_USER1(2, "User1", "User 1", new byte[] { 0x00, 0x03 }),
52     CAT2_USER2(2, "User2", "User 2", new byte[] { 0x00, 0x04 }),
53     CAT2_USER3(2, "User3", "User 3", new byte[] { 0x00, 0x05 }),
54
55     // Category 3: VW85, VW90
56     CAT3_DYNAMIC(3, "Dynamic", null, new byte[] { 0x00, 0x00 }),
57     CAT3_STANDARD(3, "Standard", null, new byte[] { 0x00, 0x01 }),
58     CAT3_CINEMA1(3, "Cinema1", "Cinema 1", new byte[] { 0x00, 0x02 }),
59     CAT3_CINEMA2(3, "Cinema2", "Cinema 2", new byte[] { 0x00, 0x03 }),
60     CAT3_CINEMA3(3, "Cinema3", "Cinema 3", new byte[] { 0x00, 0x04 }),
61     CAT3_USER(3, "User", null, new byte[] { 0x00, 0x05 }),
62
63     // Category 4: VW95, HW30ES
64     CAT4_DYNAMIC(4, "Dynamic", null, new byte[] { 0x00, 0x00 }),
65     CAT4_STANDARD(4, "Standard", null, new byte[] { 0x00, 0x01 }),
66     CAT4_CINEMA1(4, "Cinema1", "Cinema 1", new byte[] { 0x00, 0x02 }),
67     CAT4_CINEMA2(4, "Cinema2", "Cinema 2", new byte[] { 0x00, 0x03 }),
68     CAT4_CINEMA3(4, "Cinema3", "Cinema 3", new byte[] { 0x00, 0x04 }),
69     CAT4_GAME(4, "Game", null, new byte[] { 0x00, 0x05 }),
70     CAT4_PHOTO(4, "Photo", null, new byte[] { 0x00, 0x06 }),
71     CAT4_USER1(4, "User1", "User 1", new byte[] { 0x00, 0x07 }),
72     CAT4_USER2(4, "User2", "User 2", new byte[] { 0x00, 0x08 }),
73
74     // Category 5: VW1000ES, VW1100ES
75     CAT5_CINEMA_FILM1(5, "Film1", "Cinema Film 1", new byte[] { 0x00, 0x00 }),
76     CAT5_CINEMA_FILM2(5, "Film2", "Cinema Film 2", new byte[] { 0x00, 0x01 }),
77     CAT5_CINEMA_DIGITAL(5, "Digital", "Cinema Digital", new byte[] { 0x00, 0x02 }),
78     CAT5_REFERENCE(5, "Reference", null, new byte[] { 0x00, 0x03 }),
79     CAT5_TV(5, "TV", null, new byte[] { 0x00, 0x04 }),
80     CAT5_PHOTO(5, "Photo", null, new byte[] { 0x00, 0x05 }),
81     CAT5_GAME(5, "Game", null, new byte[] { 0x00, 0x06 }),
82     CAT5_BRT_CINE(5, "BRTCINE", "Bright Cinema", new byte[] { 0x00, 0x07 }),
83     CAT5_BRT_TV(5, "BRTTV", "Bright TV", new byte[] { 0x00, 0x08 });
84
85     private int category;
86     private String name;
87     private @Nullable String label;
88     private byte[] dataCode;
89
90     /**
91      * Constructor
92      *
93      * @param category a category of projector models for which the calibration preset is available
94      * @param name the name of the calibration preset
95      * @param label the label of the calibration preset; can be null when the label is identical to the name
96      * @param dataCode the data code identifying the calibration preset
97      */
98     private SonyProjectorCalibrationPreset(int category, String name, @Nullable String label, byte[] dataCode) {
99         this.category = category;
100         this.name = name;
101         this.label = label;
102         this.dataCode = dataCode;
103     }
104
105     /**
106      * Get the category of projector models for the current calibration preset
107      *
108      * @return the category of projector models
109      */
110     public int getCategory() {
111         return category;
112     }
113
114     /**
115      * Get the data code identifying the current calibration preset
116      *
117      * @return the data code
118      */
119     public byte[] getDataCode() {
120         return dataCode;
121     }
122
123     /**
124      * Get the label of the current calibration preset
125      *
126      * @return the label
127      */
128     public @Nullable String getLabel() {
129         return label;
130     }
131
132     /**
133      * Get the name of the current calibration preset
134      *
135      * @return the name
136      */
137     public String getName() {
138         return name;
139     }
140
141     /**
142      * Get the list of {@link StateOption} associated to the available calibration presets for a particular category of
143      * projector models
144      *
145      * @param category a category of projector models
146      *
147      * @return the list of {@link StateOption} associated to the available calibration presets for a provided category
148      *         of projector models
149      */
150     public static List<StateOption> getStateOptions(int category) {
151         List<StateOption> options = new ArrayList<>();
152         for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
153             if (value.getCategory() == category) {
154                 options.add(new StateOption(value.getName(),
155                         value.getLabel() != null ? value.getLabel() : value.getName()));
156             }
157         }
158         return options;
159     }
160
161     /**
162      * Get the calibration preset associated to a name for a particular category of projector models
163      *
164      * @param category a category of projector models
165      * @param name the name used to identify the calibration preset
166      *
167      * @return the calibration preset associated to the searched name for the provided category of projector models
168      *
169      * @throws SonyProjectorException - If no calibration preset is associated to the searched name for the provided
170      *             category
171      */
172     public static SonyProjectorCalibrationPreset getFromName(int category, String name) throws SonyProjectorException {
173         for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
174             if (value.getCategory() == category && value.getName().equals(name)) {
175                 return value;
176             }
177         }
178         throw new SonyProjectorException("Invalid name for a calibration preset: " + name);
179     }
180
181     /**
182      * Get the calibration preset associated to a data code for a particular category of projector models
183      *
184      * @param category a category of projector models
185      * @param dataCode the data code used to identify the calibration preset
186      *
187      * @return the calibration preset associated to the searched data code for the provided category of projector models
188      *
189      * @throws SonyProjectorException - If no calibration preset is associated to the searched data code for the
190      *             provided category
191      */
192     public static SonyProjectorCalibrationPreset getFromDataCode(int category, byte[] dataCode)
193             throws SonyProjectorException {
194         for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
195             if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
196                 return value;
197             }
198         }
199         throw new SonyProjectorException(
200                 "Invalid data code for a calibration preset: " + HexUtils.bytesToHex(dataCode));
201     }
202 }