1 /* 2 * Copyright (C) 2014 ASUSTek COMPUTER INC. 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 #include <stdint.h> 18 #include <stdlib.h> 19 #include <unistd.h> 20 #include <sys/ioctl.h> 21 #include <sys/types.h> 22 #include <log/log.h> 23 #include <hardware/hdmi_cec.h> 24 25 extern struct hw_module_t HAL_MODULE_INFO_SYM; 26 static int (*hdmicec_open)(const struct hw_module_t *, const char *, struct hw_device_t **); 27 28 static struct hw_module_t *device; 29 static struct hw_module_t **device2 = &device; 30 31 int main(int argc, char* argv[]) 32 { 33 struct hdmi_cec_device *cec_device; 34 int err, type = -1; 35 36 if (argc > 1) 37 type = atoi(argv[1]); 38 39 ALOGI("open hdmicec"); 40 hdmicec_open = HAL_MODULE_INFO_SYM.methods->open; 41 err = (*hdmicec_open)(&HAL_MODULE_INFO_SYM, NULL, (struct hw_device_t **)device2); 42 if (!err) { 43 ALOGI("open success"); 44 } else { 45 ALOGE("open fail"); 46 } 47 48 cec_device = (struct hdmi_cec_device *)(*device2); 49 #if 0 50 if (type != -1) { 51 int fd; 52 53 ALOGI("0. test type change: %d\n", type); 54 fd = open("/dev/cec0", O_RDWR); 55 if (fd < 0) { 56 ALOGE("fail to open CEC device\n"); 57 } else { 58 err = ioctl(fd, CEC_IOC_SET_DEV_TYPE, type); 59 if (!err) { 60 ALOGI("type change success\n"); 61 } else { 62 ALOGE("type change fail\n"); 63 } 64 close(fd); 65 } 66 } 67 #endif 68 69 ALOGI("1. test add logical address\n"); 70 err = cec_device->add_logical_address(cec_device, CEC_ADDR_PLAYBACK_1); 71 if (!err) { 72 ALOGI("add logical address success\n"); 73 } else { 74 ALOGE("add logical address fail\n"); 75 } 76 77 ALOGI("2. test send cec message\n"); 78 cec_message_t send_msg; 79 80 ALOGI("2.a header\n"); 81 send_msg.initiator = CEC_ADDR_PLAYBACK_1; 82 send_msg.destination = CEC_ADDR_PLAYBACK_1; 83 send_msg.length = 0; 84 85 err = cec_device->send_message(cec_device, &send_msg); 86 ALOGI("send_message result= %d", err); 87 88 ALOGI("2.b header + opcode\n"); 89 send_msg.initiator = CEC_ADDR_PLAYBACK_1; 90 send_msg.destination = CEC_ADDR_TV; 91 send_msg.length = 1; 92 send_msg.body[0] = CEC_MESSAGE_IMAGE_VIEW_ON; 93 94 err = cec_device->send_message(cec_device, &send_msg); 95 ALOGI("send_message result= %d", err); 96 97 ALOGI("2.c header + opcode + operands\n"); 98 send_msg.initiator = CEC_ADDR_PLAYBACK_1; 99 send_msg.destination = CEC_ADDR_TV; 100 send_msg.length = 15; //max opcode + operands should be 15 101 send_msg.body[0] = CEC_MESSAGE_VENDOR_COMMAND; 102 for (size_t i = 1; i < send_msg.length; i++) 103 send_msg.body[i] = i; 104 105 err = cec_device->send_message(cec_device, &send_msg); 106 ALOGI("send_message result= %d", err); 107 108 ALOGI("3 check hdmi connect status\n"); 109 err = cec_device->is_connected(cec_device, 1); 110 ALOGI("is connected= %d", err); 111 112 ALOGI("4 get hdmi physical address\n"); 113 uint16_t addr; 114 err = cec_device->get_physical_address(cec_device, &addr); 115 ALOGI("addr= %d, err= %d", addr, err); 116 117 sleep(3); 118 ALOGI("close hdmicec"); 119 cec_device->common.close((struct hw_device_t *)cec_device); 120 121 return 0; 122 } 123