2 * Copyright (c) 2010-2021 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.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;
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", "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 }),
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 }),
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 }),
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 }),
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 });
87 private @Nullable String label;
88 private byte[] dataCode;
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
98 private SonyProjectorCalibrationPreset(int category, String name, @Nullable String label, byte[] dataCode) {
99 this.category = category;
102 this.dataCode = dataCode;
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 label of the current calibration preset
128 public @Nullable String getLabel() {
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(),
155 value.getLabel() != null ? value.getLabel() : value.getName()));
162 * Get the calibration preset associated to a name for a particular category of projector models
164 * @param category a category of projector models
165 * @param name the name used to identify the calibration preset
167 * @return the calibration preset associated to the searched name for the provided category of projector models
169 * @throws SonyProjectorException - If no calibration preset is associated to the searched name for the provided
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)) {
178 throw new SonyProjectorException("Invalid name for a calibration preset: " + name);
182 * Get the calibration preset associated to a data code for a particular category of projector models
184 * @param category a category of projector models
185 * @param dataCode the data code used to identify the calibration preset
187 * @return the calibration preset associated to the searched data code for the provided category of projector models
189 * @throws SonyProjectorException - If no calibration preset is associated to the searched data code for the
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())) {
199 throw new SonyProjectorException(
200 "Invalid data code for a calibration preset: " + HexUtils.bytesToHex(dataCode));