2 * Copyright (c) 2010-2024 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.List;
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;
24 * Represents the different kinds of commands
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
31 public enum SonyProjectorItem {
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 }),
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"),
61 PICTURE_MUTING("Picture Muting", new byte[] { 0x00, 0x30 }, new byte[] { 0x17, 0x24 }, "picturemuting"),
62 NR("NR", new byte[] { 0x00, 0x25 }),
64 // Not available for VW100, VW200
65 LAMP_CONTROL("Lamp Control", new byte[] { 0x00, 0x1A }),
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 }),
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 }),
73 // Not available for VW40, VW50, VW60
74 FILM_MODE("Film Mode", new byte[] { 0x00, 0x1F }),
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"),
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"),
84 // Not available for VW40, VW50, VW60, VW100
85 XVCOLOR("xvColor", new byte[] { 0x00, 0x5A }),
87 // Not available for VW260, VW270, VW285, VW295, VW300, VW315, VW320, VW328, VW350, VW365, HW35ES, HW40ES, HW45ES,
89 IRIS_MODE("Iris Mode", new byte[] { 0x00, 0x1D }, new byte[] { 0x19, 0x5F }, "irismode"),
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 }),
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 }),
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 }),
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 }),
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 }),
113 ASPECT("Aspect", new byte[] { 0x00, 0x20 }, new byte[] { 0x19, 0x6E }, "aspect"),
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 }),
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,
122 PICTURE_POSITION("Picture Position", new byte[] { 0x00, 0x66 }),
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 }),
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 }),
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 }),
138 // Not available for VW40, VW50, VW60, VW70, VW100
139 STATUS_ERROR2("Status Error 2", new byte[] { 0x01, 0x25 }),
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 }),
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 }),
157 ADJUST_PICTURE("Adjust Picture", null, new byte[] { 0x19, 0x09 }),
159 COLOR_CORRECTION("Color Correction", null, new byte[] { 0x1B, 0x1C }),
161 PITCH("Screen Pitch", null, new byte[] { 0x17, 0x47 }),
162 SHIFT("Screen Shift", null, new byte[] { 0x17, 0x48 }),
164 APA("APA", null, new byte[] { 0x19, 0x60 }),
165 DOT_PHASE("Dot Phase", null, new byte[] { 0x19, 0x61 }),
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 }),
175 LENS_SHIFT_UP("Lens Shift UP", null, new byte[] { 0x17, 0x72 }),
176 LENS_SHIFT_DOWN("Lens Shift DOWN", null, new byte[] { 0x17, 0x73 }),
178 LENS_ZOOM("Lens Zoom", null, new byte[] { 0x19, 0x62 }),
180 LENS_ZOOM_LARGE("Lens Zoom Large", null, new byte[] { 0x17, 0x77 }),
181 LENS_ZOOM_SMALL("Lens Zoom Small", null, new byte[] { 0x17, 0x78 }),
183 LENS_FOCUS("Lens Focus", null, new byte[] { 0x19, 0x64 }),
185 LENS_FOCUS_FAR("Lens Focus Far", null, new byte[] { 0x17, 0x74 }),
186 LENS_FOCUS_NEAR("Lens Focus Near", null, new byte[] { 0x17, 0x75 }),
188 LENS_POSITION("Lens Position", null, new byte[] { 0x1B, 0x18 }),
190 MODE_3D("3D", null, new byte[] { 0x19, 0x3B }),
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 });
204 private byte @Nullable [] code;
205 private byte @Nullable [] irCode;
206 private @Nullable String channelType;
210 * @param name the item name
211 * @param code the data code associated to the item
213 private SonyProjectorItem(String name, byte @Nullable [] code) {
214 this(name, code, null, null);
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
223 private SonyProjectorItem(String name, byte @Nullable [] code, byte @Nullable [] irCode) {
224 this(name, code, irCode, null);
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
234 private SonyProjectorItem(String name, byte @Nullable [] code, byte @Nullable [] irCode,
235 @Nullable String channelType) {
238 this.irCode = irCode;
239 this.channelType = channelType;
243 * Get the data code associated to the current item
245 * @return the data code or null if undefined
247 public byte @Nullable [] getCode() {
252 * Get the IR code associated to the current item
254 * @return the IR code or null if undefined
256 public byte @Nullable [] getIrCode() {
265 public String getName() {
270 * Get the channel type id to consider to retrieve the command option label
272 * @return the channel type id
274 public @Nullable String getChannelType() {
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;
286 * Get the command associated to a value
288 * @param val the value used to identify the command
290 * @return the command associated to the searched value
292 * @throws SonyProjectorException - If no command is associated to the searched value
294 public static SonyProjectorItem getFromValue(String val) throws SonyProjectorException {
295 for (SonyProjectorItem value : SonyProjectorItem.values()) {
296 if (value.name().equalsIgnoreCase(val)) {
300 throw new SonyProjectorException("Invalid value for a command: " + val);
304 * Get the list of {@link CommandOption} associated to the available IR commands
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
310 * @return the list of {@link CommandOption} associated to the available IR commands
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"));
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);