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