From: Lars Op den Kamp Date: Thu, 8 Mar 2012 19:09:09 +0000 (+0100) Subject: cec: set the device type in the firmware too for v2 firmwares. bugzid: 543 X-Git-Tag: upstream/2.2.0~1^2~31^2~91 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9878069e35286a320bb01ef58a1cc2864856e54e;p=deb_libcec.git cec: set the device type in the firmware too for v2 firmwares. bugzid: 543 --- diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 46e428f..d676225 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -618,3 +618,29 @@ bool CLibCEC::IsLibCECActiveSource(void) m_cec->m_busDevices[m_cec->GetActiveSource()]->GetStatus(false) == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC : false; } + +cec_device_type CLibCEC::GetType(cec_logical_address address) +{ + switch (address) + { + case CECDEVICE_AUDIOSYSTEM: + return CEC_DEVICE_TYPE_AUDIO_SYSTEM; + case CECDEVICE_PLAYBACKDEVICE1: + case CECDEVICE_PLAYBACKDEVICE2: + case CECDEVICE_PLAYBACKDEVICE3: + return CEC_DEVICE_TYPE_PLAYBACK_DEVICE; + case CECDEVICE_RECORDINGDEVICE1: + case CECDEVICE_RECORDINGDEVICE2: + case CECDEVICE_RECORDINGDEVICE3: + return CEC_DEVICE_TYPE_RECORDING_DEVICE; + case CECDEVICE_TUNER1: + case CECDEVICE_TUNER2: + case CECDEVICE_TUNER3: + case CECDEVICE_TUNER4: + return CEC_DEVICE_TYPE_TUNER; + case CECDEVICE_TV: + return CEC_DEVICE_TYPE_TV; + default: + return CEC_DEVICE_TYPE_RESERVED; + } +} diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 9241a2c..fb98030 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -121,6 +121,8 @@ namespace CEC const char *ToString(const cec_vendor_id vendor); const char *ToString(const cec_client_version version); const char *ToString(const cec_server_version version); + + static cec_device_type GetType(cec_logical_address address); //@} static void AddLog(const cec_log_level level, const char *strFormat, ...); diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 4f477b9..030d643 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -576,6 +576,7 @@ bool CUSBCECAdapterCommunication::PersistConfiguration(libcec_configuration *con bool bReturn(true); bReturn &= SetAutoEnabled(true); + bReturn &= SetDeviceType(CLibCEC::GetType(configuration->logicalAddresses.primary)); bReturn &= SetDefaultLogicalAddress(configuration->logicalAddresses.primary); bReturn &= SetLogicalAddressMask(configuration->logicalAddresses.AckMask()); bReturn &= SetPhysicalAddress(configuration->iPhysicalAddress); @@ -636,6 +637,31 @@ bool CUSBCECAdapterCommunication::SetAutoEnabled(bool enabled) return true; } +bool CUSBCECAdapterCommunication::SetDeviceType(cec_device_type type) +{ + CLockObject lock(m_mutex); + CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the device type to %1X", (uint8_t)type); + + CCECAdapterMessage *output = new CCECAdapterMessage; + + output->PushBack(MSGSTART); + output->PushEscaped(MSGCODE_SET_DEVICE_TYPE); + output->PushEscaped((uint8_t)type); + output->PushBack(MSGEND); + output->isTransmission = false; + + SendMessageToAdapter(output); + bool bWriteOk = output->state == ADAPTER_MESSAGE_STATE_SENT_ACKED; + delete output; + if (!bWriteOk) + { + CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the device type"); + return false; + } + + return true; +} + bool CUSBCECAdapterCommunication::SetDefaultLogicalAddress(cec_logical_address address) { CLockObject lock(m_mutex); diff --git a/src/lib/adapter/USBCECAdapterCommunication.h b/src/lib/adapter/USBCECAdapterCommunication.h index 98f72fc..8d1e2cb 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.h +++ b/src/lib/adapter/USBCECAdapterCommunication.h @@ -90,6 +90,7 @@ namespace CEC void *Process(void); private: bool SetAutoEnabled(bool enabled); + bool SetDeviceType(cec_device_type type); bool SetDefaultLogicalAddress(cec_logical_address address); bool SetLogicalAddressMask(uint16_t iMask); bool SetPhysicalAddress(uint16_t iPhysicalAddress);