Created
October 22, 2012 07:00
-
-
Save warped-rudi/3930045 to your computer and use it in GitHub Desktop.
CEC device detection in XBMC Eden (Cubox)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/xbmc/peripherals/PeripheralTypes.h b/xbmc/peripherals/PeripheralTypes.h | |
index 53831fc..94baaf9 100644 | |
--- a/xbmc/peripherals/PeripheralTypes.h | |
+++ b/xbmc/peripherals/PeripheralTypes.h | |
@@ -35,7 +35,8 @@ namespace PERIPHERALS | |
{ | |
PERIPHERAL_BUS_UNKNOWN = 0, | |
PERIPHERAL_BUS_USB, | |
- PERIPHERAL_BUS_PCI | |
+ PERIPHERAL_BUS_PCI, | |
+ PERIPHERAL_BUS_INTERNAL | |
}; | |
enum PeripheralFeature | |
@@ -135,6 +136,8 @@ namespace PERIPHERALS | |
return "usb"; | |
case PERIPHERAL_BUS_PCI: | |
return "pci"; | |
+ case PERIPHERAL_BUS_INTERNAL: | |
+ return "builtin"; | |
default: | |
return "unknown"; | |
} | |
@@ -149,6 +152,8 @@ namespace PERIPHERALS | |
return PERIPHERAL_BUS_USB; | |
else if (strTypeLowerCase.Equals("pci")) | |
return PERIPHERAL_BUS_PCI; | |
+ else if (strTypeLowerCase.Equals("builtin")) | |
+ return PERIPHERAL_BUS_INTERNAL; | |
return PERIPHERAL_BUS_UNKNOWN; | |
}; | |
diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp | |
index 971b843..6ce884b 100644 | |
--- a/xbmc/peripherals/Peripherals.cpp | |
+++ b/xbmc/peripherals/Peripherals.cpp | |
@@ -29,6 +29,7 @@ | |
#include "devices/PeripheralTuner.h" | |
#include "devices/PeripheralCecAdapter.h" | |
#include "bus/PeripheralBusUSB.h" | |
+#include "bus/PeripheralBusBuiltin.h" | |
#include "dialogs/GUIDialogPeripheralManager.h" | |
#include "threads/SingleLock.h" | |
@@ -76,6 +77,8 @@ void CPeripherals::Initialise(void) | |
/* load mappings from peripherals.xml */ | |
LoadMappings(); | |
+ m_busses.push_back(new CPeripheralBusBuiltin(this)); | |
+ | |
#if defined(HAVE_PERIPHERAL_BUS_USB) | |
m_busses.push_back(new CPeripheralBusUSB(this)); | |
#endif | |
diff --git a/xbmc/peripherals/bus/Makefile.in b/xbmc/peripherals/bus/Makefile.in | |
index 2595a9c..230a665 100644 | |
--- a/xbmc/peripherals/bus/Makefile.in | |
+++ b/xbmc/peripherals/bus/Makefile.in | |
@@ -1,4 +1,5 @@ | |
-SRCS=PeripheralBus.cpp | |
+SRCS=PeripheralBus.cpp \ | |
+ PeripheralBusBuiltin.cpp | |
ifeq (@USE_LIBUDEV@,1) | |
SRCS+=linux/PeripheralBusUSBLibUdev.cpp | |
diff --git a/xbmc/peripherals/bus/PeripheralBusBuiltin.cpp b/xbmc/peripherals/bus/PeripheralBusBuiltin.cpp | |
new file mode 100644 | |
index 0000000..87104f8 | |
--- /dev/null | |
+++ b/xbmc/peripherals/bus/PeripheralBusBuiltin.cpp | |
@@ -0,0 +1,56 @@ | |
+/* | |
+ * Copyright (C) 2005-2011 Team XBMC | |
+ * http://xbmc.org | |
+ * | |
+ * This Program is free software; you can redistribute it and/or modify | |
+ * it under the terms of the GNU General Public License as published by | |
+ * the Free Software Foundation; either version 2, or (at your option) | |
+ * any later version. | |
+ * | |
+ * This Program is distributed in the hope that it will be useful, | |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
+ * GNU General Public License for more details. | |
+ * | |
+ * You should have received a copy of the GNU General Public License | |
+ * along with XBMC; see the file COPYING. If not, write to | |
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
+ * http://www.gnu.org/copyleft/gpl.html | |
+ * | |
+ */ | |
+ | |
+#include "PeripheralBusBuiltin.h" | |
+#include "peripherals/Peripherals.h" | |
+#include "peripherals/devices/PeripheralCecAdapter.h" | |
+#include "utils/log.h" | |
+#include "utils/StringUtils.h" | |
+ | |
+using namespace PERIPHERALS; | |
+ | |
+CPeripheralBusBuiltin::CPeripheralBusBuiltin(CPeripherals *manager) : | |
+ CPeripheralBus(manager, PERIPHERAL_BUS_INTERNAL) | |
+{ | |
+ m_bNeedsPolling = false; | |
+ m_bDetectionDone = false; | |
+} | |
+ | |
+bool CPeripheralBusBuiltin::PerformDeviceScan(PeripheralScanResults &results) | |
+{ | |
+ if (!m_bDetectionDone) | |
+ { | |
+#if defined(HAVE_LIBCEC) | |
+ CPeripheralCecAdapter::AutoDetectDevices(m_detected); | |
+#endif | |
+ | |
+ m_bDetectionDone = true; | |
+ } | |
+ | |
+ for (size_t i = 0; i < m_detected.size(); i++) | |
+ { | |
+ if (!results.ContainsResult(m_detected[i])) | |
+ results.m_results.push_back(m_detected[i]); | |
+ } | |
+ | |
+ return true; | |
+} | |
+ | |
diff --git a/xbmc/peripherals/bus/PeripheralBusBuiltin.h b/xbmc/peripherals/bus/PeripheralBusBuiltin.h | |
new file mode 100644 | |
index 0000000..1ce6956 | |
--- /dev/null | |
+++ b/xbmc/peripherals/bus/PeripheralBusBuiltin.h | |
@@ -0,0 +1,43 @@ | |
+#pragma once | |
+/* | |
+ * Copyright (C) 2005-2011 Team XBMC | |
+ * http://xbmc.org | |
+ * | |
+ * This Program is free software; you can redistribute it and/or modify | |
+ * it under the terms of the GNU General Public License as published by | |
+ * the Free Software Foundation; either version 2, or (at your option) | |
+ * any later version. | |
+ * | |
+ * This Program is distributed in the hope that it will be useful, | |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
+ * GNU General Public License for more details. | |
+ * | |
+ * You should have received a copy of the GNU General Public License | |
+ * along with XBMC; see the file COPYING. If not, write to | |
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
+ * http://www.gnu.org/copyleft/gpl.html | |
+ * | |
+ */ | |
+ | |
+#include "peripherals/bus/PeripheralBus.h" | |
+#include "peripherals/devices/Peripheral.h" | |
+ | |
+namespace PERIPHERALS | |
+{ | |
+ class CPeripherals; | |
+ | |
+ class CPeripheralBusBuiltin : public CPeripheralBus | |
+ { | |
+ std::vector<PeripheralScanResult> m_detected; | |
+ bool m_bDetectionDone; | |
+ | |
+ public: | |
+ CPeripheralBusBuiltin(CPeripherals *manager); | |
+ | |
+ /*! | |
+ * @see PeripheralBus::PerformDeviceScan() | |
+ */ | |
+ bool PerformDeviceScan(PeripheralScanResults &results); | |
+ }; | |
+} | |
diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp | |
index 7357300..690df18 100644 | |
--- a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp | |
+++ b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp | |
@@ -1217,11 +1217,13 @@ int CPeripheralCecAdapter::CecLogMessage(void *cbParam, const cec_log_message me | |
bool CPeripheralCecAdapter::TranslateComPort(CStdString &strLocation) | |
{ | |
- if ((strLocation.Left(18).Equals("peripherals://usb/") || | |
- strLocation.Left(18).Equals("peripherals://rpi/")) && | |
- strLocation.Right(4).Equals(".dev")) | |
+ CStdString strPrefix("peripherals://"); | |
+ strPrefix.append(PeripheralTypeTranslator::BusTypeToString(m_busType)); | |
+ strPrefix.append("/"); | |
+ | |
+ if (strLocation.Left(strPrefix.length()) == strPrefix && strLocation.Right(4).Equals(".dev")) | |
{ | |
- strLocation = strLocation.Right(strLocation.length() - 18); | |
+ strLocation = strLocation.Right(strLocation.length() - strPrefix.length()); | |
strLocation = strLocation.Left(strLocation.length() - 4); | |
return true; | |
} | |
@@ -1721,4 +1723,66 @@ void CPeripheralCecAdapter::ProcessStandbyDevices(void) | |
m_cecAdapter->StandbyDevices(CECDEVICE_BROADCAST); | |
} | |
+bool CPeripheralCecAdapter::AutoDetectDevices(std::vector<PeripheralScanResult> &devices) | |
+{ | |
+ DllLibCEC dll; | |
+ bool bOk = false; | |
+ ICECAdapter *detector; | |
+ cec_adapter deviceList[16]; | |
+ libcec_configuration config; | |
+ PeripheralScanResult device; | |
+ | |
+ if (dll.Load() && dll.IsLoaded()) | |
+ { | |
+ detector = dll.CECInitialise(&config); | |
+ | |
+ if (detector) | |
+ { | |
+ if (config.serverVersion >= CEC_LIB_SUPPORTED_VERSION) | |
+ { | |
+ int devCount = detector->FindAdapters(deviceList, 16); | |
+ | |
+ for (int i = 0; i < devCount; i++) | |
+ { | |
+ if (detector->GetDeviceInformation(deviceList[i].comm, &config)) | |
+ { | |
+ switch (config.adapterType) | |
+ { | |
+ case ADAPTERTYPE_RPI: | |
+ // todo: IDs should be queried ! | |
+ device.m_iVendorId = 0x2708; | |
+ device.m_iProductId = 0x1001; | |
+ break; | |
+ | |
+ case ADAPTERTYPE_TDA995x: | |
+ // todo: IDs should be queried ! | |
+ device.m_iVendorId = 0x0471; | |
+ device.m_iProductId = 0x1001; | |
+ break; | |
+ | |
+ default: | |
+ device.m_iVendorId = 0; | |
+ device.m_iProductId = 0; | |
+ break; | |
+ } | |
+ | |
+ if (device.m_iVendorId || device.m_iProductId) | |
+ { | |
+ device.m_type = PERIPHERAL_CEC; | |
+ device.m_strLocation = deviceList[i].comm; | |
+ devices.push_back(device); | |
+ } | |
+ } | |
+ } | |
+ | |
+ bOk = true; | |
+ } | |
+ | |
+ dll.CECDestroy(detector); | |
+ } | |
+ } | |
+ | |
+ return bOk; | |
+} | |
+ | |
#endif | |
diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.h b/xbmc/peripherals/devices/PeripheralCecAdapter.h | |
index 05c21bd..9928773 100644 | |
--- a/xbmc/peripherals/devices/PeripheralCecAdapter.h | |
+++ b/xbmc/peripherals/devices/PeripheralCecAdapter.h | |
@@ -45,6 +45,7 @@ namespace PERIPHERALS | |
#else | |
#include "PeripheralHID.h" | |
+#include "peripherals/bus/PeripheralBus.h" | |
#include "interfaces/AnnouncementManager.h" | |
#include "threads/Thread.h" | |
#include "threads/CriticalSection.h" | |
@@ -109,6 +110,8 @@ namespace PERIPHERALS | |
CStdString GetComPort(void); | |
void PushCecKeypress(const CEC::cec_keypress &key); | |
+ | |
+ static bool AutoDetectDevices(std::vector<PeripheralScanResult> &devices); | |
void ActivateSource(void); | |
void StandbyDevices(void); | |
@@ -138,8 +141,7 @@ namespace PERIPHERALS | |
void Process(void); | |
void ProcessVolumeChange(void); | |
void SetMenuLanguage(const char *strLanguage); | |
- static bool FindConfigLocation(CStdString &strString); | |
- static bool TranslateComPort(CStdString &strPort); | |
+ bool TranslateComPort(CStdString &strPort); | |
void ResetMembers(void); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/system/peripherals.xml b/system/peripherals.xml | |
index 46bf1d1..82c8685 100644 | |
--- a/system/peripherals.xml | |
+++ b/system/peripherals.xml | |
@@ -32,4 +32,24 @@ | |
<setting key="standby_devices_advanced" type="string" value="" configurable="0" /> | |
<setting key="double_tap_timeout_ms" type="int" min="0" value="2000" configurable="0" /> | |
</peripheral> | |
+ | |
+ <peripheral vendor_product="0471:1001" bus="builtin" name="Internal CEC Adapter" mapTo="cec"> | |
+ <setting key="enabled" type="bool" value="1" label="305" order="1" /> | |
+ <setting key="activate_source" type="bool" value="1" label="36020" order="2" /> | |
+ <setting key="wake_devices" type="string" value="0" label="36007" order="3" /> | |
+ <setting key="standby_devices" type="string" value="0" label="36008" order="4" /> | |
+ <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="5" /> | |
+ <setting key="standby_pc_on_tv_standby" type="enum" value="36028" label="36029" order="6" lvalues="36028|13005|13011" /> | |
+ <setting key="standby_tv_on_pc_standby" type="bool" value="0" label="36026" order="7" /> | |
+ <setting key="send_inactive_source" type="bool" value="1" label="36025" order="8" /> | |
+ <setting key="use_tv_menu_language" type="bool" value="0" label="36018" order="9" /> | |
+ <setting key="physical_address" type="string" label="36021" value="0" order="10" /> | |
+ <setting key="connected_device" type="int" label="36019" value="0" min="0" max="15" step="1" order="12" /> | |
+ | |
+ <setting key="cec_hdmi_port" type="int" value="1" min="1" max="15" label="36015" order="11" configurable="0"/> | |
+ <setting key="port" type="string" value="" label="36022" order="13" configurable="0" /> | |
+ <setting key="tv_vendor" type="int" value="0" configurable="0" /> | |
+ <setting key="device_name" type="string" value="XBMC" configurable="0" /> | |
+ <setting key="device_type" type="int" value="1" configurable="0" /> | |
+ </peripheral> | |
</peripherals> | |
d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment