2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sonyprojector.internal.communication;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
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;
26 * Represents the different calibration presets available for the projector
28 * @author Markus Wehrle - Initial contribution
29 * @author Laurent Garnier - Transform into an enum and consider differences between models
32 public enum SonyProjectorCalibrationPreset {
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", new byte[] { 0x00, 0x00 }, new byte[] { 0x19, 0x53 }),
38 CAT1_CINEMA_FILM2(1, "Film2", new byte[] { 0x00, 0x01 }, new byte[] { 0x19, 0x58 }),
39 CAT1_REFERENCE(1, "Reference", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x55 }),
40 CAT1_TV(1, "TV", new byte[] { 0x00, 0x03 }, new byte[] { 0x19, 0x52 }),
41 CAT1_PHOTO(1, "Photo", new byte[] { 0x00, 0x04 }, new byte[] { 0x19, 0x57 }),
42 CAT1_GAME(1, "Game", new byte[] { 0x00, 0x05 }, new byte[] { 0x19, 0x56 }),
43 CAT1_BRT_CINE(1, "BRTCINE", new byte[] { 0x00, 0x06 }, new byte[] { 0x19, 0x59 }),
44 CAT1_BRT_TV(1, "BRTTV", new byte[] { 0x00, 0x07 }, new byte[] { 0x19, 0x51 }),
45 CAT1_USER(1, "User", new byte[] { 0x00, 0x08 }, new byte[] { 0x19, 0x54 }),
47 // Category 2: VW40, VW50, VW60, VW70, VW80, VW100, VW200, HW10, HW15, HW20
48 CAT2_DYNAMIC(2, "Dynamic", new byte[] { 0x00, 0x00 }, new byte[] { 0x19, 0x51 }),
49 CAT2_STANDARD(2, "Standard", new byte[] { 0x00, 0x01 }, new byte[] { 0x19, 0x52 }),
50 CAT2_CINEMA(2, "Cinema", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x53 }),
51 CAT2_USER1(2, "User1", new byte[] { 0x00, 0x03 }, new byte[] { 0x19, 0x54 }),
52 CAT2_USER2(2, "User2", new byte[] { 0x00, 0x04 }, new byte[] { 0x19, 0x55 }),
53 CAT2_USER3(2, "User3", new byte[] { 0x00, 0x05 }, new byte[] { 0x19, 0x56 }),
55 // Category 3: VW85, VW90
56 CAT3_DYNAMIC(3, "Dynamic", new byte[] { 0x00, 0x00 }, new byte[] { 0x19, 0x51 }),
57 CAT3_STANDARD(3, "Standard", new byte[] { 0x00, 0x01 }, new byte[] { 0x19, 0x52 }),
58 CAT3_CINEMA1(3, "Cinema1", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x53 }),
59 CAT3_CINEMA2(3, "Cinema2", new byte[] { 0x00, 0x03 }, new byte[] { 0x19, 0x54 }),
60 CAT3_CINEMA3(3, "Cinema3", new byte[] { 0x00, 0x04 }, new byte[] { 0x19, 0x55 }),
61 CAT3_USER(3, "User", new byte[] { 0x00, 0x05 }, new byte[] { 0x19, 0x56 }),
63 // Category 4: VW95, HW30ES
64 CAT4_DYNAMIC(4, "Dynamic", new byte[] { 0x00, 0x00 }, new byte[] { 0x19, 0x51 }),
65 CAT4_STANDARD(4, "Standard", new byte[] { 0x00, 0x01 }, new byte[] { 0x19, 0x52 }),
66 CAT4_CINEMA1(4, "Cinema1", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x53 }),
67 CAT4_CINEMA2(4, "Cinema2", new byte[] { 0x00, 0x03 }, new byte[] { 0x19, 0x54 }),
68 CAT4_CINEMA3(4, "Cinema3", new byte[] { 0x00, 0x04 }, new byte[] { 0x19, 0x55 }),
69 CAT4_GAME(4, "Game", new byte[] { 0x00, 0x05 }, new byte[] { 0x19, 0x56 }),
70 CAT4_PHOTO(4, "Photo", new byte[] { 0x00, 0x06 }, new byte[] { 0x19, 0x57 }),
71 CAT4_USER1(4, "User1", new byte[] { 0x00, 0x07 }, new byte[] { 0x19, 0x58 }),
72 CAT4_USER2(4, "User2", new byte[] { 0x00, 0x08 }, new byte[] { 0x19, 0x59 }),
74 // Category 5: VW1000ES, VW1100ES
75 CAT5_CINEMA_FILM1(5, "Film1", new byte[] { 0x00, 0x00 }, new byte[] { 0x19, 0x53 }),
76 CAT5_CINEMA_FILM2(5, "Film2", new byte[] { 0x00, 0x01 }, new byte[] { 0x19, 0x58 }),
77 CAT5_CINEMA_DIGITAL(5, "Digital", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x54 }),
78 CAT5_REFERENCE(5, "Reference", new byte[] { 0x00, 0x03 }, new byte[] { 0x19, 0x55 }),
79 CAT5_TV(5, "TV", new byte[] { 0x00, 0x04 }, new byte[] { 0x19, 0x52 }),
80 CAT5_PHOTO(5, "Photo", new byte[] { 0x00, 0x05 }, new byte[] { 0x19, 0x57 }),
81 CAT5_GAME(5, "Game", new byte[] { 0x00, 0x06 }, new byte[] { 0x19, 0x56 }),
82 CAT5_BRT_CINE(5, "BRTCINE", new byte[] { 0x00, 0x07 }, new byte[] { 0x19, 0x59 }),
83 CAT5_BRT_TV(5, "BRTTV", new byte[] { 0x00, 0x08 }, new byte[] { 0x19, 0x51 });
87 private byte[] dataCode;
88 private byte[] irCode;
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 dataCode the data code identifying the calibration preset
96 * @param irCode the IR code for the calibration preset
98 private SonyProjectorCalibrationPreset(int category, String name, byte[] dataCode, byte[] irCode) {
99 this.category = category;
101 this.dataCode = dataCode;
102 this.irCode = irCode;
106 * Get the category of projector models for the current calibration preset
108 * @return the category of projector models
110 public int getCategory() {
115 * Get the data code identifying the current calibration preset
117 * @return the data code
119 public byte[] getDataCode() {
124 * Get the IR code for the current calibration preset
126 * @return the IR code
128 public byte[] getIrCode() {
133 * Get the name of the current calibration preset
137 public String getName() {
142 * Get the list of {@link StateOption} associated to the available calibration presets for a particular category of
145 * @param category a category of projector models
147 * @return the list of {@link StateOption} associated to the available calibration presets for a provided category
148 * of projector models
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(), value.getName()));
161 * Get the list of {@link CommandOption} associated to the available calibration presets for a particular category
162 * of projector models
164 * @param category a category of projector models
166 * @return the list of {@link CommandOption} associated to the available calibration presets for a provided category
167 * of projector models
169 public static List<CommandOption> getCommandOptions(int category) {
170 List<CommandOption> options = new ArrayList<>();
171 for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
172 if (value.getCategory() == category) {
173 options.add(new CommandOption("PRESET_" + value.getName().toUpperCase(),
174 "@text/channel-type.sonyprojector.calibrationpreset.state.option." + value.getName()));
181 * Get the calibration preset associated to a name for a particular category of projector models
183 * @param category a category of projector models
184 * @param name the name used to identify the calibration preset
186 * @return the calibration preset associated to the searched name for the provided category of projector models
188 * @throws SonyProjectorException - If no calibration preset is associated to the searched name for the provided
191 public static SonyProjectorCalibrationPreset getFromName(int category, String name) throws SonyProjectorException {
192 for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
193 if (value.getCategory() == category && value.getName().equalsIgnoreCase(name)) {
197 throw new SonyProjectorException("Invalid name for a calibration preset: " + name);
201 * Get the calibration preset associated to a data code for a particular category of projector models
203 * @param category a category of projector models
204 * @param dataCode the data code used to identify the calibration preset
206 * @return the calibration preset associated to the searched data code for the provided category of projector models
208 * @throws SonyProjectorException - If no calibration preset is associated to the searched data code for the
211 public static SonyProjectorCalibrationPreset getFromDataCode(int category, byte[] dataCode)
212 throws SonyProjectorException {
213 for (SonyProjectorCalibrationPreset value : SonyProjectorCalibrationPreset.values()) {
214 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
218 throw new SonyProjectorException(
219 "Invalid data code for a calibration preset: " + HexUtils.bytesToHex(dataCode));