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 aspect modes available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorAspect {
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, VW885
35 CAT1_NORMAL(1, "Normal", null, new byte[] { 0x00, 0x01 }),
36 CAT1_V_STRETCH(1, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
37 CAT1_185(1, "185", "1.85:1 Zoom", new byte[] { 0x00, 0x0C }),
38 CAT1_235(1, "235", "2.35:1 Zoom", new byte[] { 0x00, 0x0D }),
39 CAT1_STRETCH(1, "Stretch", null, new byte[] { 0x00, 0x0E }),
40 CAT1_SQUEEZE(1, "Squeeze", null, new byte[] { 0x00, 0x0F }),
42 // Category 2: VW40, VW50, HW10, HW15, HW20, HW30
43 CAT2_FULL(2, "Full", null, new byte[] { 0x00, 0x00 }),
44 CAT2_NORMAL(2, "Normal", null, new byte[] { 0x00, 0x01 }),
45 CAT2_WIDE(2, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
46 CAT2_ZOOM(2, "Zoom", null, new byte[] { 0x00, 0x03 }),
47 CAT2_FULL1(2, "Full1", "Full 1", new byte[] { 0x00, 0x07 }),
48 CAT2_FULL2(2, "Full2", "Full 2", new byte[] { 0x00, 0x08 }),
50 // Category 3: VW60, VW70, VW80, VW85, VW90, VW95, VW200
51 CAT3_FULL(3, "Full", null, new byte[] { 0x00, 0x00 }),
52 CAT3_NORMAL(3, "Normal", null, new byte[] { 0x00, 0x01 }),
53 CAT3_WIDE(3, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
54 CAT3_ZOOM(3, "Zoom", null, new byte[] { 0x00, 0x03 }),
55 CAT3_FULL1(3, "Full1", "Full 1", new byte[] { 0x00, 0x07 }),
56 CAT3_FULL2(3, "Full2", "Full 2", new byte[] { 0x00, 0x08 }),
57 CAT3_ANAMORPHIC(3, "Anamorphic", null, new byte[] { 0x00, 0x0B }),
60 CAT4_FULL(4, "Full", null, new byte[] { 0x00, 0x00 }),
61 CAT4_NORMAL(4, "Normal", null, new byte[] { 0x00, 0x01 }),
62 CAT4_WIDE(4, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
63 CAT4_ZOOM(4, "Zoom", null, new byte[] { 0x00, 0x03 }),
64 CAT3_SUBTITLE(4, "Subtitle", null, new byte[] { 0x00, 0x04 }),
66 // Category 5: HW40ES, HW50ES, HW55ES, HW58ES
67 CAT5_FULL(5, "Full", null, new byte[] { 0x00, 0x00 }),
68 CAT5_NORMAL(5, "Normal", null, new byte[] { 0x00, 0x01 }),
69 CAT5_WIDE(5, "WideZoom", "Wide Zoom", new byte[] { 0x00, 0x02 }),
70 CAT5_ZOOM(5, "Zoom", null, new byte[] { 0x00, 0x03 }),
71 CAT5_V_STRETCH(5, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
72 CAT5_STRETCH(5, "Stretch", null, new byte[] { 0x00, 0x0E }),
73 CAT5_SQUEEZE(5, "Squeeze", null, new byte[] { 0x00, 0x0F }),
75 // Category 6: HW45ES, HW60, HW65, HW68
76 CAT6_NORMAL(6, "Normal", null, new byte[] { 0x00, 0x01 }),
77 CAT6_V_STRETCH(6, "VStretch", "V Stretch", new byte[] { 0x00, 0x0B }),
78 CAT6_STRETCH(6, "Stretch", null, new byte[] { 0x00, 0x0E }),
79 CAT6_SQUEEZE(6, "Squeeze", null, new byte[] { 0x00, 0x0F });
83 private @Nullable String label;
84 private byte[] dataCode;
89 * @param category a category of projector models for which the aspect mode is available
90 * @param name the name of the aspect mode
91 * @param label the label of the aspect mode; can be null when the label is identical to the name
92 * @param dataCode the data code identifying the aspect mode
94 private SonyProjectorAspect(int category, String name, @Nullable String label, byte[] dataCode) {
95 this.category = category;
98 this.dataCode = dataCode;
102 * Get the category of projector models for the current aspect mode
104 * @return the category of projector models
106 public int getCategory() {
111 * Get the data code identifying the current aspect mode
113 * @return the data code
115 public byte[] getDataCode() {
120 * Get the label of the current aspect mode
124 public @Nullable String getLabel() {
129 * Get the name of the current aspect mode
133 public String getName() {
138 * Get the list of {@link StateOption} associated to the available aspect modes for a particular category of
141 * @param category a category of projector models
143 * @return the list of {@link StateOption} associated to the available aspect modes for a provided category of
146 public static List<StateOption> getStateOptions(int category) {
147 List<StateOption> options = new ArrayList<>();
148 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
149 if (value.getCategory() == category) {
150 options.add(new StateOption(value.getName(),
151 value.getLabel() != null ? value.getLabel() : value.getName()));
158 * Get the aspect mode associated to a name for a particular category of projector models
160 * @param category a category of projector models
161 * @param name the name used to identify the aspect mode
163 * @return the aspect mode associated to the searched name for the provided category of projector models
165 * @throws SonyProjectorException - If no aspect mode is associated to the searched name for the provided category
167 public static SonyProjectorAspect getFromName(int category, String name) throws SonyProjectorException {
168 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
169 if (value.getCategory() == category && value.getName().equals(name)) {
173 throw new SonyProjectorException("Invalid name for an aspect mode: " + name);
177 * Get the aspect mode associated to a data code for a particular category of projector models
179 * @param category a category of projector models
180 * @param dataCode the data code used to identify the aspect mode
182 * @return the aspect mode associated to the searched data code for the provided category of projector models
184 * @throws SonyProjectorException - If no aspect mode is associated to the searched data code for the provided
187 public static SonyProjectorAspect getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
188 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
189 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
193 throw new SonyProjectorException("Invalid data code for an aspect mode: " + HexUtils.bytesToHex(dataCode));