]> git.basschouten.com Git - openhab-addons.git/blob
05ca59bb3434887d30610c078143e558cde2a0d2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonyprojector.internal.communication;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
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;
23
24 /**
25  * Represents the different motion enhancer modes available for the projector
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public enum SonyProjectorMotionEnhancer {
31
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 }),
40
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 }),
45
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 });
51
52     private int category;
53     private String name;
54     private byte[] dataCode;
55
56     /**
57      * Constructor
58      *
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
62      */
63     private SonyProjectorMotionEnhancer(int category, String name, byte[] dataCode) {
64         this.category = category;
65         this.name = name;
66         this.dataCode = dataCode;
67     }
68
69     /**
70      * Get the category of projector models for the current motion enhancer mode
71      *
72      * @return the category of projector models
73      */
74     public int getCategory() {
75         return category;
76     }
77
78     /**
79      * Get the data code identifying the current motion enhancer mode
80      *
81      * @return the data code
82      */
83     public byte[] getDataCode() {
84         return dataCode;
85     }
86
87     /**
88      * Get the name of the current motion enhancer mode
89      *
90      * @return the name
91      */
92     public String getName() {
93         return name;
94     }
95
96     /**
97      * Get the list of {@link StateOption} associated to the available motion enhancer modes for a particular category
98      * of projector models
99      *
100      * @param category a category of projector models
101      *
102      * @return the list of {@link StateOption} associated to the available motion enhancer modes for a provided category
103      *         of projector models
104      */
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()));
110             }
111         }
112         return options;
113     }
114
115     /**
116      * Get the motion enhancer mode associated to a name for a particular category of projector models
117      *
118      * @param category a category of projector models
119      * @param name the name used to identify the motion enhancer mode
120      *
121      * @return the motion enhancer mode associated to the searched name for the provided category of projector models
122      *
123      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched name for the provided
124      *             category
125      */
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)) {
129                 return value;
130             }
131         }
132         throw new SonyProjectorException("Invalid name for a motion enhancer mode: " + name);
133     }
134
135     /**
136      * Get the motion enhancer mode associated to a data code for a particular category of projector models
137      *
138      * @param category a category of projector models
139      * @param dataCode the data code used to identify the motion enhancer mode
140      *
141      * @return the motion enhancer mode associated to the searched data code for the provided category of projector
142      *         models
143      *
144      * @throws SonyProjectorException - If no motion enhancer mode is associated to the searched data code for the
145      *             provided category
146      */
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())) {
151                 return value;
152             }
153         }
154         throw new SonyProjectorException(
155                 "Invalid data code for a motion enhancer mode: " + HexUtils.bytesToHex(dataCode));
156     }
157 }