cec: set the device type in the firmware too for v2 firmwares. bugzid: 543
[deb_libcec.git] / src / lib / adapter / USBCECAdapterCommunication.cpp
index 4f477b90d6cfa9df43e29958d6f98bea92d43c4f..030d643516c5c52e8e0772ba4cd8b162c52469d3 100644 (file)
@@ -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);