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 motion enhancer modes available for the projector
28 * @author Laurent Garnier - Initial contribution
31 public enum SonyProjectorMotionEnhancer {
33 // Category 1: VW260, VW285, VW300, VW315, VW320, VW328, VW350, VW360, VW365, VW385, VW500, VW515, VW520, VW528,
34 // VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW45ES, HW60, HW65, HW68
35 CAT1_SMOOTH_HIGH(1, "SmoothHigh", "Smooth High", new byte[] { 0x00, 0x01 }),
36 CAT1_SMOOTH_LOW(1, "SmoothLow", "Smooth Low", new byte[] { 0x00, 0x02 }),
37 CAT1_IMPULSE(1, "Impulse", null, new byte[] { 0x00, 0x03 }),
38 CAT1_COMBINATION(1, "Combination", null, new byte[] { 0x00, 0x04 }),
39 CAT1_TRUE_CINEMA(1, "TrueCinema", "True Cinema", new byte[] { 0x00, 0x05 }),
40 CAT1_OFF(1, "Off", null, new byte[] { 0x00, 0x00 }),
42 // Category 2: VW80, VW85, VW90, VW95, VW200, VW1000ES, VW1100ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
43 CAT2_HIGH(2, "High", null, new byte[] { 0x00, 0x02 }),
44 CAT2_LOW(2, "Low", null, new byte[] { 0x00, 0x01 }),
45 CAT2_OFF(2, "Off", null, new byte[] { 0x00, 0x00 }),
47 // Category 3: VW270, VW295
48 CAT3_SMOOTH_HIGH(3, "SmoothHigh", "Smooth High", new byte[] { 0x00, 0x01 }),
49 CAT3_SMOOTH_LOW(3, "SmoothLow", "Smooth Low", new byte[] { 0x00, 0x02 }),
50 CAT3_TRUE_CINEMA(3, "TrueCinema", "True Cinema", new byte[] { 0x00, 0x05 }),
51 CAT3_OFF(3, "Off", null, new byte[] { 0x00, 0x00 });
55 private @Nullable String label;
56 private byte[] dataCode;
61 * @param category a category of projector models for which the motion enhancer mode is available
62 * @param name the name of the motion enhancer mode
63 * @param label the label of the motion enhancer mode; can be null when the label is identical to the name
64 * @param dataCode the data code identifying the motion enhancer mode
66 private SonyProjectorMotionEnhancer(int category, String name, @Nullable String label, byte[] dataCode) {
67 this.category = category;
70 this.dataCode = dataCode;
74 * Get the category of projector models for the current motion enhancer mode
76 * @return the category of projector models
78 public int getCategory() {
83 * Get the data code identifying the current motion enhancer mode
85 * @return the data code
87 public byte[] getDataCode() {
92 * Get the label of the current motion enhancer mode
96 public @Nullable String getLabel() {
101 * Get the name of the current motion enhancer mode
105 public String getName() {
110 * Get the list of {@link StateOption} associated to the available motion enhancer modes for a particular category
111 * of projector models
113 * @param category a category of projector models
115 * @return the list of {@link StateOption} associated to the available motion enhancer modes for a provided category
116 * of projector models
118 public static List<StateOption> getStateOptions(int category) {
119 List<StateOption> options = new ArrayList<>();
120 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
121 if (value.getCategory() == category) {
122 options.add(new StateOption(value.getName(),
123 value.getLabel() != null ? value.getLabel() : value.getName()));
130 * Get the motion enhancer mode associated to a name for a particular category of projector models
132 * @param category a category of projector models
133 * @param name the name used to identify the motion enhancer mode
135 * @return the motion enhancer mode associated to the searched name for the provided category of projector models
137 * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched name for the provided
140 public static SonyProjectorMotionEnhancer getFromName(int category, String name) throws SonyProjectorException {
141 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
142 if (value.getCategory() == category && value.getName().equals(name)) {
146 throw new SonyProjectorException("Invalid name for a motion enhancer mode: " + name);
150 * Get the motion enhancer mode associated to a data code for a particular category of projector models
152 * @param category a category of projector models
153 * @param dataCode the data code used to identify the motion enhancer mode
155 * @return the motion enhancer mode associated to the searched data code for the provided category of projector
158 * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched data code for the
161 public static SonyProjectorMotionEnhancer getFromDataCode(int category, byte[] dataCode)
162 throws SonyProjectorException {
163 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
164 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
168 throw new SonyProjectorException(
169 "Invalid data code for a motion enhancer mode: " + HexUtils.bytesToHex(dataCode));