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 motion enhancer modes available for the projector
27 * @author Laurent Garnier - Initial contribution
30 public enum SonyProjectorMotionEnhancer {
32 // Category 1: VW260, VW285, VW300, VW315, VW320, VW328, VW350, VW360, VW365, VW385, VW500, VW515, VW520, VW528,
33 // VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW45ES, HW60, HW65, HW68
34 CAT1_SMOOTH_HIGH(1, "SmoothHigh", new byte[] { 0x00, 0x01 }),
35 CAT1_SMOOTH_LOW(1, "SmoothLow", new byte[] { 0x00, 0x02 }),
36 CAT1_IMPULSE(1, "Impulse", new byte[] { 0x00, 0x03 }),
37 CAT1_COMBINATION(1, "Combination", new byte[] { 0x00, 0x04 }),
38 CAT1_TRUE_CINEMA(1, "TrueCinema", new byte[] { 0x00, 0x05 }),
39 CAT1_OFF(1, "Off", new byte[] { 0x00, 0x00 }),
41 // Category 2: VW80, VW85, VW90, VW95, VW200, VW1000ES, VW1100ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
42 CAT2_HIGH(2, "High", new byte[] { 0x00, 0x02 }),
43 CAT2_LOW(2, "Low", new byte[] { 0x00, 0x01 }),
44 CAT2_OFF(2, "Off", new byte[] { 0x00, 0x00 }),
46 // Category 3: VW270, VW295
47 CAT3_SMOOTH_HIGH(3, "SmoothHigh", new byte[] { 0x00, 0x01 }),
48 CAT3_SMOOTH_LOW(3, "SmoothLow", new byte[] { 0x00, 0x02 }),
49 CAT3_TRUE_CINEMA(3, "TrueCinema", new byte[] { 0x00, 0x05 }),
50 CAT3_OFF(3, "Off", new byte[] { 0x00, 0x00 });
54 private byte[] dataCode;
59 * @param category a category of projector models for which the motion enhancer mode is available
60 * @param name the name of the motion enhancer mode
61 * @param dataCode the data code identifying the motion enhancer mode
63 private SonyProjectorMotionEnhancer(int category, String name, byte[] dataCode) {
64 this.category = category;
66 this.dataCode = dataCode;
70 * Get the category of projector models for the current motion enhancer mode
72 * @return the category of projector models
74 public int getCategory() {
79 * Get the data code identifying the current motion enhancer mode
81 * @return the data code
83 public byte[] getDataCode() {
88 * Get the name of the current motion enhancer mode
92 public String getName() {
97 * Get the list of {@link StateOption} associated to the available motion enhancer modes for a particular category
100 * @param category a category of projector models
102 * @return the list of {@link StateOption} associated to the available motion enhancer modes for a provided category
103 * of projector models
105 public static List<StateOption> getStateOptions(int category) {
106 List<StateOption> options = new ArrayList<>();
107 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
108 if (value.getCategory() == category) {
109 options.add(new StateOption(value.getName(), value.getName()));
116 * Get the motion enhancer mode associated to a name for a particular category of projector models
118 * @param category a category of projector models
119 * @param name the name used to identify the motion enhancer mode
121 * @return the motion enhancer mode associated to the searched name for the provided category of projector models
123 * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched name for the provided
126 public static SonyProjectorMotionEnhancer getFromName(int category, String name) throws SonyProjectorException {
127 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
128 if (value.getCategory() == category && value.getName().equals(name)) {
132 throw new SonyProjectorException("Invalid name for a motion enhancer mode: " + name);
136 * Get the motion enhancer mode associated to a data code for a particular category of projector models
138 * @param category a category of projector models
139 * @param dataCode the data code used to identify the motion enhancer mode
141 * @return the motion enhancer mode associated to the searched data code for the provided category of projector
144 * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched data code for the
147 public static SonyProjectorMotionEnhancer getFromDataCode(int category, byte[] dataCode)
148 throws SonyProjectorException {
149 for (SonyProjectorMotionEnhancer value : SonyProjectorMotionEnhancer.values()) {
150 if (value.getCategory() == category && Arrays.equals(dataCode, value.getDataCode())) {
154 throw new SonyProjectorException(
155 "Invalid data code for a motion enhancer mode: " + HexUtils.bytesToHex(dataCode));