X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FLibCEC.cpp;h=c0931c3e963d3fb724c5da88ba7d74e9b2cd1502;hb=ebefc26c10d68ba9ced2a30c896dccc81c6c2eeb;hp=331b11d3b7cbfedd485a56c3d1787446dd3b0ca6;hpb=0d800fe507054f9fc752ba70e5a9c14d95dcb87f;p=deb_libcec.git diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 331b11d..c0931c3 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -102,16 +102,24 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CON void CLibCEC::Close(void) { + if (!m_cec) + return; + // unregister all clients - UnregisterClients(); + m_cec->UnregisterClients(); // close the connection - if (m_cec) - m_cec->Close(); + m_cec->Close(); } int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) { + if (!CUSBCECAdapterDetection::CanAutodetect()) + { + AddLog(CEC_LOG_WARNING, "libCEC has not been compiled with adapter detection code for this target, so the path to the COM port has to be provided to libCEC"); + return 0; + } + return CUSBCECAdapterDetection::FindAdapters(deviceList, iBufSize, strDevicePath); } @@ -467,6 +475,13 @@ void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...) (*it)->AddLog(message); } +void CLibCEC::AddCommand(const cec_command &command) +{ + // send the command to all clients + for (vector::iterator it = m_clients.begin(); it != m_clients.end(); it++) + (*it)->AddCommand(command); +} + void CLibCEC::Alert(const libcec_alert type, const libcec_parameter ¶m) { // send the alert to all clients @@ -541,14 +556,14 @@ void * CECInitialise(libcec_configuration *configuration) return static_cast< void* > (lib); } -void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t iPhysicalAddress /* = 0 */) +void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types) { - libcec_configuration configuration; + libcec_configuration configuration; configuration.Clear(); // client version < 1.5.0 snprintf(configuration.strDeviceName, 13, "%s", strDeviceName); configuration.deviceTypes = types; - configuration.iPhysicalAddress = iPhysicalAddress; + configuration.iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS; if (configuration.deviceTypes.IsEmpty()) configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); @@ -556,6 +571,18 @@ void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint1 return CECInitialise(&configuration); } +void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /* = CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +{ + libcec_configuration configuration; configuration.Clear(); + + // client version < 1.5.0 + snprintf(configuration.strDeviceName, 13, "%s", strDeviceName); + configuration.iPhysicalAddress = iPhysicalAddress; + configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); + + return CECInitialise(&configuration); +} + bool CECStartBootloader(void) { bool bReturn(false); @@ -591,7 +618,6 @@ bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *co // no longer being used void CLibCEC::AddKey(const cec_keypress &UNUSED(key)) {} -void CLibCEC::AddCommand(const cec_command &UNUSED(command)) {} void CLibCEC::ConfigurationChanged(const libcec_configuration &UNUSED(config)) {} void CLibCEC::SetCurrentButton(cec_user_control_code UNUSED(iButtonCode)) {} CLibCEC *CLibCEC::GetInstance(void) { return NULL; }