| 1 |
/* |
| 2 |
* Copyright (C) 2005-2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "PeripheralBusCEC.h" |
| 10 |
|
| 11 |
#include <libcec/cec.h> |
| 12 |
|
| 13 |
using namespace PERIPHERALS; |
| 14 |
using namespace CEC; |
| 15 |
|
| 16 |
CPeripheralBusCEC::CPeripheralBusCEC(CPeripherals& manager) |
| 17 |
: CPeripheralBus("PeripBusCEC", manager, PERIPHERAL_BUS_CEC) |
| 18 |
{ |
| 19 |
m_cecAdapter = CECInitialise(&m_configuration); |
| 20 |
} |
| 21 |
|
| 22 |
CPeripheralBusCEC::~CPeripheralBusCEC(void) |
| 23 |
{ |
| 24 |
if (m_cecAdapter) |
| 25 |
CECDestroy(m_cecAdapter); |
| 26 |
} |
| 27 |
|
| 28 |
bool CPeripheralBusCEC::PerformDeviceScan(PeripheralScanResults& results) |
| 29 |
{ |
| 30 |
cec_adapter_descriptor deviceList[10]; |
| 31 |
int8_t iFound = m_cecAdapter->DetectAdapters(deviceList, 10, NULL, true); |
| 32 |
|
| 33 |
for (uint8_t iDevicePtr = 0; iDevicePtr < iFound; iDevicePtr++) |
| 34 |
{ |
| 35 |
PeripheralScanResult result(m_type); |
| 36 |
result.m_iVendorId = deviceList[iDevicePtr].iVendorId; |
| 37 |
result.m_iProductId = deviceList[iDevicePtr].iProductId; |
| 38 |
result.m_strLocation = deviceList[iDevicePtr].strComName; |
| 39 |
result.m_type = PERIPHERAL_CEC; |
| 40 |
|
| 41 |
// override the bus type, so users don't have to reconfigure their adapters |
| 42 |
switch (deviceList[iDevicePtr].adapterType) |
| 43 |
{ |
| 44 |
case ADAPTERTYPE_P8_EXTERNAL: |
| 45 |
case ADAPTERTYPE_P8_DAUGHTERBOARD: |
| 46 |
result.m_mappedBusType = PERIPHERAL_BUS_USB; |
| 47 |
break; |
| 48 |
default: |
| 49 |
break; |
| 50 |
} |
| 51 |
|
| 52 |
result.m_iSequence = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId); |
| 53 |
if (!results.ContainsResult(result)) |
| 54 |
results.m_results.push_back(result); |
| 55 |
} |
| 56 |
return true; |
| 57 |
} |