cec: make sure that a device is really powered on
[deb_libcec.git] / src / lib / devices / CECBusDevice.cpp
index 0b7adf677e61bebed790af62f4e0650a69f6051a..7fe92a451236ec893e89ef47fd213e5ae164fb56 100644 (file)
@@ -40,7 +40,7 @@
 
 using namespace CEC;
 
-#define ToString(p) CCECCommandHandler::ToString(p)
+#define ToString(p) m_processor->ToString(p)
 
 CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
   m_type(CEC_DEVICE_TYPE_RESERVED),
@@ -99,7 +99,16 @@ bool CCECBusDevice::PowerOn(void)
   cec_command::Format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_IMAGE_VIEW_ON);
   if (m_processor->Transmit(command))
   {
-    RequestPowerStatus();
+    {
+      CLockObject lock(&m_mutex);
+      m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
+    }
+    cec_power_status status = GetPowerStatus();
+    if (status == CEC_POWER_STATUS_STANDBY || status == CEC_POWER_STATUS_UNKNOWN)
+    {
+      SendKeypress(CEC_USER_CONTROL_CODE_POWER, true);
+      return SendKeyRelease(false);
+    }
     return true;
   }