1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hdmicec.cts; 18 19 import android.hdmicec.cts.HdmiCecConstants.CecDeviceType; 20 21 import java.util.HashMap; 22 import java.util.Map; 23 24 public enum LogicalAddress { 25 TV(0x0), 26 RECORDER_1(0x1), 27 RECORDER_2(0x2), 28 TUNER_1(0x3), 29 PLAYBACK_1(0x4), 30 AUDIO_SYSTEM(0x5), 31 TUNER_2(0x6), 32 TUNER_3(0x7), 33 PLAYBACK_2(0x8), 34 RECORDER_3(0x9), 35 TUNER_4(0xa), 36 PLAYBACK_3(0xb), 37 RESERVED_1(0xc), 38 RESERVED_2(0xd), 39 SPECIFIC_USE(0xe), 40 BROADCAST(0xf), 41 UNKNOWN(0xf); 42 43 private final int address; 44 private static Map deviceMap = new HashMap<>(); 45 46 @Override toString()47 public String toString() { 48 return Integer.toHexString(this.address); 49 } 50 51 static { 52 for (LogicalAddress device : LogicalAddress.values()) { deviceMap.put(device.address, device)53 deviceMap.put(device.address, device); 54 } 55 } 56 getDeviceTypeString()57 public String getDeviceTypeString() { 58 return Integer.toString(getDeviceType()); 59 } 60 getLogicalAddressAsInt()61 public int getLogicalAddressAsInt() { 62 return this.address; 63 } 64 getDeviceType()65 public @CecDeviceType int getDeviceType() { 66 switch (this) { 67 case PLAYBACK_1: 68 case PLAYBACK_2: 69 case PLAYBACK_3: 70 return HdmiCecConstants.CEC_DEVICE_TYPE_PLAYBACK_DEVICE; 71 case TV: 72 return HdmiCecConstants.CEC_DEVICE_TYPE_TV; 73 case AUDIO_SYSTEM: 74 return HdmiCecConstants.CEC_DEVICE_TYPE_AUDIO_SYSTEM; 75 case RECORDER_1: 76 case RECORDER_2: 77 case RECORDER_3: 78 return HdmiCecConstants.CEC_DEVICE_TYPE_RECORDER; 79 case TUNER_1: 80 case TUNER_2: 81 case TUNER_3: 82 case TUNER_4: 83 return HdmiCecConstants.CEC_DEVICE_TYPE_TUNER; 84 default: 85 return HdmiCecConstants.CEC_DEVICE_TYPE_RESERVED; 86 } 87 } 88 getLogicalAddress(int address)89 public static LogicalAddress getLogicalAddress(int address) { 90 return (LogicalAddress) deviceMap.get(address); 91 } 92 LogicalAddress(int address)93 private LogicalAddress(int address) { 94 this.address = address; 95 } 96 } 97