2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
33 #include "CECDetect.h"
34 #include "libPlatform/os-dependent.h"
35 #include "util/StdString.h"
36 #if !defined(__WINDOWS__)
43 #define CEC_VID 0x2548
44 #define CEC_PID 0x1001
49 #if !defined(__WINDOWS__)
50 bool TranslateComPort(CStdString
&strString
)
52 CStdString
strTmp(strString
);
54 int iSlash
= strTmp
.Find('/');
57 strTmp
= strTmp
.Left(iSlash
);
59 strString
.Format("%s/%s:1.0/tty", strString
.c_str(), strTmp
.c_str());
66 bool FindComPort(CStdString
&strLocation
)
68 CStdString strPort
= strLocation
;
69 bool bReturn(!strPort
.IsEmpty());
70 CStdString
strConfigLocation(strLocation
);
71 if (TranslateComPort(strConfigLocation
))
74 struct dirent
*dirent
;
75 if((dir
= opendir(strConfigLocation
.c_str())) == NULL
)
78 while ((dirent
= readdir(dir
)) != NULL
)
80 if(strcmp((char*)dirent
->d_name
, "." ) != 0 && strcmp((char*)dirent
->d_name
, ".." ) != 0)
82 strPort
.Format("/dev/%s", dirent
->d_name
);
83 if (!strPort
.IsEmpty())
85 strLocation
= strPort
;
98 int CCECDetect::FindDevices(vector
<cec_device
> &deviceList
, const char *strDevicePath
/* = NULL */)
102 #if !defined(__WINDOWS__)
104 if (!(udev
= udev_new()))
107 struct udev_enumerate
*enumerate
;
108 struct udev_list_entry
*devices
, *dev_list_entry
;
109 struct udev_device
*dev
;
110 enumerate
= udev_enumerate_new(udev
);
111 udev_enumerate_scan_devices(enumerate
);
112 devices
= udev_enumerate_get_list_entry(enumerate
);
113 udev_list_entry_foreach(dev_list_entry
, devices
)
116 strPath
= udev_list_entry_get_name(dev_list_entry
);
118 dev
= udev_device_new_from_syspath(udev
, strPath
);
122 dev
= udev_device_get_parent(udev_device_get_parent(dev
));
125 if (!udev_device_get_sysattr_value(dev
,"idVendor") || !udev_device_get_sysattr_value(dev
, "idProduct"))
127 udev_device_unref(dev
);
131 int iVendor
, iProduct
;
132 sscanf(udev_device_get_sysattr_value(dev
, "idVendor"), "%x", &iVendor
);
133 sscanf(udev_device_get_sysattr_value(dev
, "idProduct"), "%x", &iProduct
);
134 if (iVendor
== CEC_VID
&& iProduct
== CEC_PID
)
136 CStdString
strPath(udev_device_get_syspath(dev
));
137 if (strDevicePath
&& strcmp(strPath
.c_str(), strDevicePath
))
140 CStdString
strComm(strPath
);
141 if (FindComPort(strComm
))
144 foundDev
.path
= strPath
;
145 foundDev
.comm
= strComm
;
146 deviceList
.push_back(foundDev
);
150 udev_device_unref(dev
);
153 udev_enumerate_unref(enumerate
);