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 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, VW1000ES, VW1100ES
35 CAT1_NORMAL(1, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
36 CAT1_V_STRETCH(1, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
37 CAT1_185(1, "185", new byte[] { 0x00, 0x0C }, new byte[] { 0x1B, 0x45 }),
38 CAT1_235(1, "235", new byte[] { 0x00, 0x0D }, new byte[] { 0x1B, 0x46 }),
39 CAT1_STRETCH(1, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
40 CAT1_SQUEEZE(1, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 }),
42 // Category 2: VW40, VW50, HW10, HW15, HW20, HW30
43 CAT2_FULL(2, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
44 CAT2_NORMAL(2, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
45 CAT2_WIDE(2, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
46 CAT2_ZOOM(2, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
47 CAT2_FULL1(2, "Full1", new byte[] { 0x00, 0x07 }, new byte[] { 0x1B, 0x3F }),
48 CAT2_FULL2(2, "Full2", new byte[] { 0x00, 0x08 }, new byte[] { 0x1B, 0x40 }),
50 // Category 3: VW60, VW70, VW80, VW85, VW90, VW95, VW200
51 CAT3_FULL(3, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
52 CAT3_NORMAL(3, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
53 CAT3_WIDE(3, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
54 CAT3_ZOOM(3, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
55 CAT3_FULL1(3, "Full1", new byte[] { 0x00, 0x07 }, new byte[] { 0x1B, 0x3F }),
56 CAT3_FULL2(3, "Full2", new byte[] { 0x00, 0x08 }, new byte[] { 0x1B, 0x40 }),
57 CAT3_ANAMORPHIC(3, "Anamorphic", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
60 CAT4_FULL(4, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
61 CAT4_NORMAL(4, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
62 CAT4_WIDE(4, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
63 CAT4_ZOOM(4, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
64 CAT3_SUBTITLE(4, "Subtitle", new byte[] { 0x00, 0x04 }, new byte[] { 0x1B, 0x49 }), // IR code not confirmed
66 // Category 5: HW40ES, HW50ES, HW55ES, HW58ES
67 CAT5_FULL(5, "Full", new byte[] { 0x00, 0x00 }, new byte[] { 0x1B, 0x42 }),
68 CAT5_NORMAL(5, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
69 CAT5_WIDE(5, "WideZoom", new byte[] { 0x00, 0x02 }, new byte[] { 0x1B, 0x3E }),
70 CAT5_ZOOM(5, "Zoom", new byte[] { 0x00, 0x03 }, new byte[] { 0x1B, 0x43 }),
71 CAT5_V_STRETCH(5, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
72 CAT5_STRETCH(5, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
73 CAT5_SQUEEZE(5, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 }),
75 // Category 6: HW45ES, HW60, HW65, HW68
76 CAT6_NORMAL(6, "Normal", new byte[] { 0x00, 0x01 }, new byte[] { 0x1B, 0x41 }),
77 CAT6_V_STRETCH(6, "VStretch", new byte[] { 0x00, 0x0B }, new byte[] { 0x1B, 0x44 }),
78 CAT6_STRETCH(6, "Stretch", new byte[] { 0x00, 0x0E }, new byte[] { 0x1B, 0x47 }),
79 CAT6_SQUEEZE(6, "Squeeze", new byte[] { 0x00, 0x0F }, new byte[] { 0x1B, 0x48 });
83 private byte[] dataCode;
84 private byte[] irCode;
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 dataCode the data code identifying the aspect mode
92 * @param irCode the IR code for the aspect mode
94 private SonyProjectorAspect(int category, String name, byte[] dataCode, byte[] irCode) {
95 this.category = category;
97 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 IR code for the current aspect mode
122 * @return the IR code
124 public byte[] getIrCode() {
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(), value.getName()));
157 * Get the list of {@link CommandOption} associated to the available aspect modes for a particular category of
160 * @param category a category of projector models
162 * @return the list of {@link CommandOption} associated to the available aspect modes for a provided category of
165 public static List<CommandOption> getCommandOptions(int category) {
166 List<CommandOption> options = new ArrayList<>();
167 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
168 if (value.getCategory() == category) {
169 options.add(new CommandOption("ASPECT_" + value.getName().toUpperCase(),
170 "@text/channel-type.sonyprojector.aspect.state.option." + value.getName()));
177 * Get the aspect mode associated to a name for a particular category of projector models
179 * @param category a category of projector models
180 * @param name the name used to identify the aspect mode
182 * @return the aspect mode associated to the searched name for the provided category of projector models
184 * @throws SonyProjectorException - If no aspect mode is associated to the searched name for the provided category
186 public static SonyProjectorAspect getFromName(int category, String name) throws SonyProjectorException {
187 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
188 if (value.getCategory() == category && value.getName().equalsIgnoreCase(name)) {
192 throw new SonyProjectorException("Invalid name for an aspect mode: " + name);
196 * Get the aspect mode associated to a data code for a particular category of projector models
198 * @param category a category of projector models
199 * @param dataCode the data code used to identify the aspect mode
201 * @return the aspect mode associated to the searched data code for the provided category of projector models
203 * @throws SonyProjectorException - If no aspect mode is associated to the searched data code for the provided
206 public static SonyProjectorAspect getFromDataCode(int category, byte[] dataCode) throws SonyProjectorException {
207 for (SonyProjectorAspect value : SonyProjectorAspect.values()) {
208 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
212 throw new SonyProjectorException("Invalid data code for an aspect mode: " + HexUtils.bytesToHex(dataCode));