]> git.basschouten.com Git - openhab-addons.git/blob
76743a41cd1c44bbf1179dec230714f88e02a0de
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.List;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.sonyprojector.internal.SonyProjectorException;
21 import org.openhab.core.types.CommandOption;
22
23 /**
24  * Represents the different kinds of commands
25  *
26  * @author Markus Wehrle - Initial contribution
27  * @author Laurent Garnier - Transform into an enum and rename it
28  * @author Laurent Garnier - Add more IR commands
29  */
30 @NonNullByDefault
31 public enum SonyProjectorItem {
32
33     // Not available for VW40, VW50, VW60, VW70, VW80, VW85, VW90, VW95, VW100, VW200, VW1000ES, VW1100ES,
34     // HW10, HW15, HW20, HW30ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
35     POWER("Power On/Off", new byte[] { 0x01, 0x30 }, new byte[] { 0x17, 0x15 }),
36     POWER_ON("Power On", null, new byte[] { 0x17, 0x2E }),
37     POWER_OFF("Power Off", null, new byte[] { 0x17, 0x2F }),
38
39     INPUT("Input", new byte[] { 0x00, 0x01 }, new byte[] { 0x17, 0x57 }, "input"),
40     CALIBRATION_PRESET("Calibration Preset", new byte[] { 0x00, 0x02 }, new byte[] { 0x19, 0x5B }, "calibrationpreset"),
41     CONTRAST("Contrast", new byte[] { 0x00, 0x10 }),
42     CONTRAST_UP("Contrast +", null, new byte[] { 0x17, 0x18 }),
43     CONTRAST_DOWN("Contrast -", null, new byte[] { 0x17, 0x19 }),
44     BRIGHTNESS("Brigtness", new byte[] { 0x00, 0x11 }),
45     BRIGHTNESS_UP("Brightness +", null, new byte[] { 0x17, 0x1E }),
46     BRIGHTNESS_DOWN("Brightness -", null, new byte[] { 0x17, 0x1F }),
47     COLOR("Color", new byte[] { 0x00, 0x12 }),
48     COLOR_UP("Color +", null, new byte[] { 0x17, 0x1A }),
49     COLOR_DOWN("Color -", null, new byte[] { 0x17, 0x1B }),
50     HUE("Hue", new byte[] { 0x00, 0x13 }),
51     HUE_UP("Hue +", null, new byte[] { 0x17, 0x20 }),
52     HUE_DOWN("Hue -", null, new byte[] { 0x17, 0x21 }),
53     SHARPNESS("Sharpness", new byte[] { 0x00, 0x14 }),
54     SHARPNESS_UP("Sharpness +", null, new byte[] { 0x17, 0x22 }),
55     SHARPNESS_DOWN("Sharpness -", null, new byte[] { 0x17, 0x23 }),
56     CONTRAST_ENHANCER("Contrast Enhancer", new byte[] { 0x00, 0x1C }, new byte[] { 0x17, 0x07 }, "contrastenhancer"),
57     COLOR_TEMP("Color Temperature", new byte[] { 0x00, 0x17 }, new byte[] { 0x19, 0x5C }, "colortemperature"),
58     GAMMA_CORRECTION("Gamma Correction", new byte[] { 0x00, 0x22 }, new byte[] { 0x19, 0x5E }, "gammacorrection"),
59     COLOR_SPACE("Color Space", new byte[] { 0x00, 0x3B }, new byte[] { 0x19, 0x4B }, "colorspace"),
60
61     PICTURE_MUTING("Picture Muting", new byte[] { 0x00, 0x30 }, new byte[] { 0x17, 0x24 }, "picturemuting"),
62     NR("NR", new byte[] { 0x00, 0x25 }),
63
64     // Not available for VW100, VW200
65     LAMP_CONTROL("Lamp Control", new byte[] { 0x00, 0x1A }),
66
67     // Not available for VW315, VW320, VW328, VW365, VW515, VW520, VW528, VW665, HW60, HW65, HW68
68     REAL_COLOR("Real Color Processing", new byte[] { 0x00, 0x1E }, new byte[] { 0x19, 0x08 }),
69
70     // Not available for VW40, VW50, VW60, VW70, VW85, VW95, VW100, HW15, HW20, HW30ES
71     REALITY_CREATION("Reality Creation", new byte[] { 0x00, 0x67 }, new byte[] { 0x19, 0x4C }),
72
73     // Not available for VW40, VW50, VW60
74     FILM_MODE("Film Mode", new byte[] { 0x00, 0x1F }),
75
76     // Not available for VW40, VW50, VW60, VW70, VW100, VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350,
77     // VW365, VW385, VW500, VW515, VW520, VW528, VW570, VW600, VW665, VW675, VW695, VW760, VW870, VW885, VW995, HW10,
78     // HW15, HW20, HW30ES, HW45ES, HW60, HW65, HW68
79     FILM_PROJECTION("Film Projection", new byte[] { 0x00, 0x58 }, new byte[] { 0x17, 0x08 }, "filmprojection"),
80
81     // Not available for VW40, VW50, VW60, VW70, VW100, HW10, HW15, HW20, HW30ES
82     MOTION_ENHANCER("Motion Enhancer", new byte[] { 0x00, 0x59 }, new byte[] { 0x17, 0x05 }, "motionenhancer"),
83
84     // Not available for VW40, VW50, VW60, VW100
85     XVCOLOR("xvColor", new byte[] { 0x00, 0x5A }),
86
87     // Not available for VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, HW35ES, HW40ES, HW45ES,
88     // HW58ES
89     IRIS_MODE("Iris Mode", new byte[] { 0x00, 0x1D }, new byte[] { 0x19, 0x5F }, "irismode"),
90
91     // Not available for VW100, VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500,
92     // VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW760, VW870, VW885, VW995, VW1000ES, VW1100ES, HW35ES,
93     // HW40ES, HW45ES, HW50ES, HW55ES, HW58ES, HW60, HW65, HW68
94     IRIS_SENSITIVITY("Iris Sensitivity", new byte[] { 0x00, 0x56 }),
95
96     // Not available for VW100, VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW760, VW870,
97     // VW885, VW995, HW35ES, HW40ES, HW45ES, HW58ES
98     IRIS_MANUAL("Iris Manual", new byte[] { 0x00, 0x57 }),
99
100     // Not available for VW40, VW50, VW60, VW100, VW200, VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350,
101     // VW365, VW385, VW500, VW515, VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW760, VW870, VW885, VW995,
102     // VW1000ES, VW1100ES, HW35ES, HW40ES, HW45ES, HW50ES, HW55ES, HW58ES, HW60, HW65, HW68
103     BLOCK_NR("Block NR", new byte[] { 0x00, 0x26 }),
104     MOSQUITO_NR("Mosquito NR", new byte[] { 0x00, 0x27 }),
105
106     // Not available for VW40, VW50, VW60, VW70, VW80, VW85, VW90, VW95, VW100, VW200, HW10, HW15, HW20, HW30ES
107     MPEG_NR("MPEG NR", new byte[] { 0x00, 0x6C }),
108
109     // Not available for VW40, VW50, VW60, VW70, VW85, VW95, VW100, VW315, VW320, VW328, VW365, VW1000ES, VW1100ES
110     // HW15, HW20, HW30ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES, HW60, HW65, HW68
111     HDR("HDR", new byte[] { 0x00, 0x7C }),
112
113     ASPECT("Aspect", new byte[] { 0x00, 0x20 }, new byte[] { 0x19, 0x6E }, "aspect"),
114
115     // Not available for VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, VW385, VW500, VW515,
116     // VW520, VW528, VW550, VW570, VW600, VW665, VW675, VW760, VW870, VW885, VW995, HW45ES, HW60, HW65, HW68
117     OVERSCAN("Overscan", new byte[] { 0x00, 0x23 }),
118
119     // Not available for VW40, VW50, VW60, VW70, VW80, VW85, VW90, VW100, VW200, VW260, VW270, VW285, VW295, VW300,
120     // VW315, VW320, VW328, VW350, VW365, HW10, HW15, HW20, HW30ES, HW35ES, HW40ES, HW45ES, HW50ES, HW55ES, HW58ES,
121     // HW60, HW65, HW68
122     PICTURE_POSITION("Picture Position", new byte[] { 0x00, 0x66 }),
123
124     PICTURE_POS_185("Picture Position 1.85:1", null, new byte[] { 0x1B, 0x20 }),
125     PICTURE_POS_235("Picture Position 2.35:1", null, new byte[] { 0x1B, 0x21 }),
126     PICTURE_POS_CUSTOM1("Picture Position Custom 1", null, new byte[] { 0x1B, 0x22 }),
127     PICTURE_POS_CUSTOM2("Picture Position Custom 2", null, new byte[] { 0x1B, 0x23 }),
128     PICTURE_POS_CUSTOM3("Picture Position Custom 3", null, new byte[] { 0x1B, 0x24 }),
129
130     // Not available for VW40, VW50, VW60, VW70, VW85, VW95, VW100, VW1000ES, VW1100ES
131     // HW15, HW20, HW30ES, HW35ES, HW40ES, HW50ES, HW55ES, HW58ES
132     INPUT_LAG_REDUCTION("Input Lag Reduction", new byte[] { 0x00, (byte) 0x99 }),
133
134     STATUS_ERROR("Status Error", new byte[] { 0x01, 0x01 }),
135     STATUS_POWER("Status Power", new byte[] { 0x01, 0x02 }),
136     LAMP_USE_TIME("Lamp Use Time", new byte[] { 0x01, 0x13 }),
137
138     // Not available for VW40, VW50, VW60, VW70, VW100
139     STATUS_ERROR2("Status Error 2", new byte[] { 0x01, 0x25 }),
140
141     CATEGORY_CODE("Category Code", new byte[] { (byte) 0x80, 0x00 }),
142     MODEL_NAME("Model Name", new byte[] { (byte) 0x80, 0x01 }),
143     SERIAL_NUMBER("Serial Number", new byte[] { (byte) 0x80, 0x02 }),
144     INSTALLATION_LOCATION("Installation Location", new byte[] { (byte) 0x80, 0x03 }),
145
146     MENU("Menu", null, new byte[] { 0x17, 0x29 }),
147     UP("Cursor UP", null, new byte[] { 0x17, 0x35 }),
148     DOWN("Cursor DOWN", null, new byte[] { 0x17, 0x36 }),
149     LEFT("Cursor LEFT", null, new byte[] { 0x17, 0x34 }),
150     RIGHT("Cursor RIGHT", null, new byte[] { 0x17, 0x33 }),
151     ENTER("Enter", null, new byte[] { 0x17, 0x5A }),
152     RESET("Reset", null, new byte[] { 0x17, 0x7B }),
153     MEMORY("Memory", null, new byte[] { 0x17, 0x5E }),
154     STATUS_ON("Status On", null, new byte[] { 0x17, 0x25 }),
155     STATUS_OFF("Status Off", null, new byte[] { 0x17, 0x26 }),
156
157     ADJUST_PICTURE("Adjust Picture", null, new byte[] { 0x19, 0x09 }),
158
159     COLOR_CORRECTION("Color Correction", null, new byte[] { 0x1B, 0x1C }),
160
161     PITCH("Screen Pitch", null, new byte[] { 0x17, 0x47 }),
162     SHIFT("Screen Shift", null, new byte[] { 0x17, 0x48 }),
163
164     APA("APA", null, new byte[] { 0x19, 0x60 }),
165     DOT_PHASE("Dot Phase", null, new byte[] { 0x19, 0x61 }),
166
167     V_KEYSTONE("V Keystone", null, new byte[] { 0x19, 0x3A }),
168     V_KEYSTONE_UP("V Keystone +", null, new byte[] { 0x19, 0x00 }),
169     V_KEYSTONE_DOWN("V Keystone -", null, new byte[] { 0x19, 0x01 }),
170     LENS_CONTROL("Lens Control", null, new byte[] { 0x19, 0x78 }),
171     LENS_SHIFT("Lens Shift", null, new byte[] { 0x19, 0x63 }),
172     LENS_SHIFT_LEFT("Lens Shift LEFT", null, new byte[] { 0x19, 0x02 }),
173     LENS_SHIFT_RIGHT("Lens Shift RIGHT", null, new byte[] { 0x19, 0x03 }),
174
175     LENS_SHIFT_UP("Lens Shift UP", null, new byte[] { 0x17, 0x72 }),
176     LENS_SHIFT_DOWN("Lens Shift DOWN", null, new byte[] { 0x17, 0x73 }),
177
178     LENS_ZOOM("Lens Zoom", null, new byte[] { 0x19, 0x62 }),
179
180     LENS_ZOOM_LARGE("Lens Zoom Large", null, new byte[] { 0x17, 0x77 }),
181     LENS_ZOOM_SMALL("Lens Zoom Small", null, new byte[] { 0x17, 0x78 }),
182
183     LENS_FOCUS("Lens Focus", null, new byte[] { 0x19, 0x64 }),
184
185     LENS_FOCUS_FAR("Lens Focus Far", null, new byte[] { 0x17, 0x74 }),
186     LENS_FOCUS_NEAR("Lens Focus Near", null, new byte[] { 0x17, 0x75 }),
187
188     LENS_POSITION("Lens Position", null, new byte[] { 0x1B, 0x18 }),
189
190     MODE_3D("3D", null, new byte[] { 0x19, 0x3B }),
191
192     OPTIONS("Options", null, new byte[] { 0x1B, 0x6E }),
193     EXIT("Exit", null, new byte[] { 0x1B, 0x6F }),
194     SYNC_MENU("Sync Menu", null, new byte[] { 0x1B, 0x70 }),
195     PLAY("Play", null, new byte[] { 0x1B, 0x71 }),
196     STOP("Stop", null, new byte[] { 0x1B, 0x72 }),
197     PAUSE("Pause", null, new byte[] { 0x1B, 0x73 }),
198     FAST_REWIND("Fast Rewind", null, new byte[] { 0x1B, 0x74 }),
199     FAST_FORWARD("Fast Forward", null, new byte[] { 0x1B, 0x75 }),
200     PREVIOUS("Previous", null, new byte[] { 0x1B, 0x76 }),
201     NEXT("Next", null, new byte[] { 0x1B, 0x77 });
202
203     private String name;
204     private byte @Nullable [] code;
205     private byte @Nullable [] irCode;
206     private @Nullable String channelType;
207
208     /**
209      *
210      * @param name the item name
211      * @param code the data code associated to the item
212      */
213     private SonyProjectorItem(String name, byte @Nullable [] code) {
214         this(name, code, null, null);
215     }
216
217     /**
218      *
219      * @param name the item name
220      * @param code the data code associated to the item
221      * @param irCode the IR code associated to the item
222      */
223     private SonyProjectorItem(String name, byte @Nullable [] code, byte @Nullable [] irCode) {
224         this(name, code, irCode, null);
225     }
226
227     /**
228      *
229      * @param name the item name
230      * @param code the data code associated to the item
231      * @param irCode the IR code associated to the item
232      * @param channelType the channel type id to consider to retrieve the command option label
233      */
234     private SonyProjectorItem(String name, byte @Nullable [] code, byte @Nullable [] irCode,
235             @Nullable String channelType) {
236         this.name = name;
237         this.code = code;
238         this.irCode = irCode;
239         this.channelType = channelType;
240     }
241
242     /**
243      * Get the data code associated to the current item
244      *
245      * @return the data code or null if undefined
246      */
247     public byte @Nullable [] getCode() {
248         return code;
249     }
250
251     /**
252      * Get the IR code associated to the current item
253      *
254      * @return the IR code or null if undefined
255      */
256     public byte @Nullable [] getIrCode() {
257         return irCode;
258     }
259
260     /**
261      * Get the item name
262      *
263      * @return the name
264      */
265     public String getName() {
266         return name;
267     }
268
269     /**
270      * Get the channel type id to consider to retrieve the command option label
271      *
272      * @return the channel type id
273      */
274     public @Nullable String getChannelType() {
275         return channelType;
276     }
277
278     public static boolean isValidIrCode(byte @Nullable [] irCode) {
279         if (irCode != null && irCode.length == 2) {
280             return irCode[0] == 0x17 || irCode[0] == 0x19 || irCode[0] == 0x1B;
281         }
282         return false;
283     }
284
285     /**
286      * Get the command associated to a value
287      *
288      * @param val the value used to identify the command
289      *
290      * @return the command associated to the searched value
291      *
292      * @throws SonyProjectorException - If no command is associated to the searched value
293      */
294     public static SonyProjectorItem getFromValue(String val) throws SonyProjectorException {
295         for (SonyProjectorItem value : SonyProjectorItem.values()) {
296             if (value.name().equalsIgnoreCase(val)) {
297                 return value;
298             }
299         }
300         throw new SonyProjectorException("Invalid value for a command: " + val);
301     }
302
303     /**
304      * Get the list of {@link CommandOption} associated to the available IR commands
305      *
306      * @param inputOptions the command options associated to the video inputs
307      * @param presetOptions the command options associated to the calibration presets
308      * @param aspectOptions the command options associated to the aspect ratios
309      *
310      * @return the list of {@link CommandOption} associated to the available IR commands
311      */
312     public static List<CommandOption> getIRCommandOptions(List<CommandOption> inputOptions,
313             List<CommandOption> presetOptions, List<CommandOption> aspectOptions) {
314         List<CommandOption> options = new ArrayList<>();
315         for (SonyProjectorItem value : SonyProjectorItem.values()) {
316             if (isValidIrCode(value.getIrCode())) {
317                 options.add(new CommandOption(value.name(), value.getChannelType() == null ? value.getName()
318                         : "@text/channel-type.sonyprojector." + value.getChannelType() + ".label"));
319             }
320             if (value == INPUT) {
321                 options.addAll(inputOptions);
322             } else if (value == CALIBRATION_PRESET) {
323                 options.addAll(presetOptions);
324             } else if (value == ASPECT) {
325                 options.addAll(aspectOptions);
326             }
327         }
328         return options;
329     }
330 }