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.StateOption;
22 import org.openhab.core.util.HexUtils;
25 * Represents the different aspect modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorAspect {
32 // Category 1: VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515, VW520,
33 // VW528, VW550, VW570, VW600, VW665, VW675, VW695, VW760, VW885
34 CAT1_NORMAL(1, "Normal", new byte[] { 0x00, 0x01 }),
35 CAT1_V_STRETCH(1, "VStretch", new byte[] { 0x00, 0x0B }),
36 CAT1_185(1, "185", new byte[] { 0x00, 0x0C }),
37 CAT1_235(1, "235", new byte[] { 0x00, 0x0D }),
38 CAT1_STRETCH(1, "Stretch", new byte[] { 0x00, 0x0E }),
39 CAT1_SQUEEZE(1, "Squeeze", new byte[] { 0x00, 0x0F }),
41 // Category 2: VW40, VW50, HW10, HW15, HW20, HW30
42 CAT2_FULL(2, "Full", new byte[] { 0x00, 0x00 }),
43 CAT2_NORMAL(2, "Normal", new byte[] { 0x00, 0x01 }),
44 CAT2_WIDE(2, "WideZoom", new byte[] { 0x00, 0x02 }),
45 CAT2_ZOOM(2, "Zoom", new byte[] { 0x00, 0x03 }),
46 CAT2_FULL1(2, "Full1", new byte[] { 0x00, 0x07 }),
47 CAT2_FULL2(2, "Full2", new byte[] { 0x00, 0x08 }),
49 // Category 3: VW60, VW70, VW80, VW85, VW90, VW95, VW200
50 CAT3_FULL(3, "Full", new byte[] { 0x00, 0x00 }),
51 CAT3_NORMAL(3, "Normal", new byte[] { 0x00, 0x01 }),
52 CAT3_WIDE(3, "WideZoom", new byte[] { 0x00, 0x02 }),
53 CAT3_ZOOM(3, "Zoom", new byte[] { 0x00, 0x03 }),
54 CAT3_FULL1(3, "Full1", new byte[] { 0x00, 0x07 }),
55 CAT3_FULL2(3, "Full2", new byte[] { 0x00, 0x08 }),
56 CAT3_ANAMORPHIC(3, "Anamorphic", new byte[] { 0x00, 0x0B }),
59 CAT4_FULL(4, "Full", new byte[] { 0x00, 0x00 }),
60 CAT4_NORMAL(4, "Normal", new byte[] { 0x00, 0x01 }),
61 CAT4_WIDE(4, "WideZoom", new byte[] { 0x00, 0x02 }),
62 CAT4_ZOOM(4, "Zoom", new byte[] { 0x00, 0x03 }),
63 CAT3_SUBTITLE(4, "Subtitle", new byte[] { 0x00, 0x04 }),
65 // Category 5: HW40ES, HW50ES, HW55ES, HW58ES
66 CAT5_FULL(5, "Full", new byte[] { 0x00, 0x00 }),
67 CAT5_NORMAL(5, "Normal", new byte[] { 0x00, 0x01 }),
68 CAT5_WIDE(5, "WideZoom", new byte[] { 0x00, 0x02 }),
69 CAT5_ZOOM(5, "Zoom", new byte[] { 0x00, 0x03 }),
70 CAT5_V_STRETCH(5, "VStretch", new byte[] { 0x00, 0x0B }),
71 CAT5_STRETCH(5, "Stretch", new byte[] { 0x00, 0x0E }),
72 CAT5_SQUEEZE(5, "Squeeze", new byte[] { 0x00, 0x0F }),
74 // Category 6: HW45ES, HW60, HW65, HW68
75 CAT6_NORMAL(6, "Normal", new byte[] { 0x00, 0x01 }),
76 CAT6_V_STRETCH(6, "VStretch", new byte[] { 0x00, 0x0B }),
77 CAT6_STRETCH(6, "Stretch", new byte[] { 0x00, 0x0E }),
78 CAT6_SQUEEZE(6, "Squeeze", new byte[] { 0x00, 0x0F });
82 private byte[] dataCode;
87 * @param category a category of projector models for which the aspect mode is available
88 * @param name the name of the aspect mode
89 * @param dataCode the data code identifying the aspect mode
91 private SonyProjectorAspect(int category, String name, byte[] dataCode) {
92 this.category = category;
94 this.dataCode = dataCode;
98 * Get the category of projector models for the current aspect mode
100 * @return the category of projector models
102 public int getCategory() {
107 * Get the data code identifying the current aspect mode
109 * @return the data code
111 public byte[] getDataCode() {
116 * Get the name of the current aspect mode
120 public String getName() {
125 * Get the list of {@link StateOption} associated to the available aspect modes for a particular category of
128 * @param category a category of projector models
130 * @return the list of {@link StateOption} associated to the available aspect modes for a provided category of
133 public static List<StateOption> getStateOptions(int category) {
134 List<StateOption> options = new ArrayList<>();
135 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
136 if (value.getCategory() == category) {
137 options.add(new StateOption(value.getName(), value.getName()));
144 * Get the aspect mode associated to a name for a particular category of projector models
146 * @param category a category of projector models
147 * @param name the name used to identify the aspect mode
149 * @return the aspect mode associated to the searched name for the provided category of projector models
151 * @throws SonyProjectorException - If no aspect mode is associated to the searched name for the provided category
153 public static SonyProjectorAspect getFromName(int category, String name) throws SonyProjectorException {
154 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
155 if (value.getCategory() == category && value.getName().equals(name)) {
159 throw new SonyProjectorException("Invalid name for an aspect mode: " + name);
163 * Get the aspect mode associated to a data code for a particular category of projector models
165 * @param category a category of projector models
166 * @param dataCode the data code used to identify the aspect mode
168 * @return the aspect mode associated to the searched data code for the provided category of projector models
170 * @throws SonyProjectorException - If no aspect mode is associated to the searched data code for the provided
173 public static SonyProjectorAspect getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
174 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
175 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
179 throw new SonyProjectorException("Invalid data code for an aspect mode: " + HexUtils.bytesToHex(dataCode));