cec: added poweroff devices parameter to the config (instead of a boolean parameter...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 15 Feb 2012 15:00:56 +0000 (16:00 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 15 Feb 2012 15:00:56 +0000 (16:00 +0100)
include/cectypes.h
src/cec-config/cec-config.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp

index 41d124e9a6d8ccee0778879220a3bcec64714b6f..fe8678f6df1d112ffbc04850a92f40234615e4d6 100644 (file)
@@ -74,7 +74,7 @@ namespace CEC {
 #define CEC_FW_VERSION_UNKNOWN       0xFFFF
 
 #define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE  1
-#define CEC_DEFAULT_SETTING_POWER_ON_STARTUP      1
+#define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE       1
 #define CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN    1
 #define CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER 1
 #define CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY  1
@@ -955,14 +955,14 @@ typedef struct libcec_configuration
   uint16_t              iPhysicalAddress;     /*!< the physical address of the CEC adapter */
   cec_logical_address   baseDevice;           /*!< the logical address of the device to which the adapter is connected. only used when iPhysicalAddress = 0 */
   uint8_t               iHDMIPort;            /*!< the HDMI port to which the adapter is connected. only used when iPhysicalAddress = 0 */
-  cec_vendor_id         tvVendor;             /*!< the vendor ID of the TV. leave this untouched to autodetect */
-  cec_logical_addresses wakeDevices;          /*!< wake these CEC devices when starting libCEC */
+  cec_vendor_id         tvVendor;             /*!< override the vendor ID of the TV. leave this untouched to autodetect */
+  cec_logical_addresses wakeDevices;          /*!< wake these CEC devices when initialising libCEC or when calling PowerOnDevices() without any parameter */
+  cec_logical_addresses powerOffDevices;      /*!< power off these devices when calling StandbyDevices() without any parameter */
 
   // player specific settings
   uint8_t               bGetSettingsFromROM;  /*!< true to get the settings from the ROM (if set, and a v2 ROM is present), false to use these settings. */
   uint8_t               bUseTVMenuLanguage;   /*!< use the menu language of the TV in the player application */
-  uint8_t               bPowerOnStartup;      /*!< power on CEC devices when start the player application */
-  uint8_t               bPowerOffShutdown;    /*!< power off CEC devices when stopping the player application */
+  uint8_t               bActivateSource;      /*!< make libCEC the active source on the bus when starting the player application */
   uint8_t               bPowerOffScreensaver; /*!< put devices in standby mode when activating the screensaver */
   uint8_t               bPowerOffOnStandby;   /*!< put this PC in standby mode when the TV is switched off */
 
@@ -980,11 +980,17 @@ typedef struct libcec_configuration
     tvVendor         = CEC_VENDOR_UNKNOWN;
     clientVersion    = CEC_CLIENT_VERSION_PRE_1_5;
     wakeDevices.Clear();
+    powerOffDevices.Clear();
 
     bGetSettingsFromROM  = 0;
     bUseTVMenuLanguage   = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE;
-    bPowerOnStartup      = CEC_DEFAULT_SETTING_POWER_ON_STARTUP;
-    bPowerOffShutdown    = CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN;
+    bActivateSource      = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE;
+    #if CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1
+    powerOffDevices.Set(CECDEVICE_BROADCAST);
+    #endif
+               #if CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1
+               wakeDevices.Set(CECDEVICE_TV);
+               #endif
     bPowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER;
     bPowerOffOnStandby   = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY;
 
index 02e812663993b86f48ebcd5ad91b5bc5414f0ee3..b5ecd8e7235b643c7669fa10793c51e455595974 100644 (file)
@@ -381,11 +381,11 @@ int main (int UNUSED(argc), char *UNUSED(argv[]))
   }
 
   {
-    PrintToStdOut("Do you want to power on CEC devices when starting the application (y/n)?");
+    PrintToStdOut("Do you want to make the CEC adapter the active source when starting the application (y/n)?");
     string input;
     getline(cin, input);
     cin.clear();
-    g_config.bPowerOnStartup = (input == "y" || input == "Y") ? 1 : 0;
+    g_config.bActivateSource = (input == "y" || input == "Y") ? 1 : 0;
   }
 
   {
@@ -393,7 +393,8 @@ int main (int UNUSED(argc), char *UNUSED(argv[]))
     string input;
     getline(cin, input);
     cin.clear();
-    g_config.bPowerOffShutdown = (input == "y" || input == "Y") ? 1 : 0;
+    if (input == "y" || input == "Y")
+      g_config.powerOffDevices.Set(CECDEVICE_BROADCAST);
   }
 
   {
@@ -417,8 +418,8 @@ int main (int UNUSED(argc), char *UNUSED(argv[]))
   PrintToStdOut("Connected to HDMI device:                                %X", (uint8_t)g_config.baseDevice);
   PrintToStdOut("Physical address:                                        %4X", g_config.iPhysicalAddress);
   PrintToStdOut("Use the TV's language setting:                           %s", g_config.bUseTVMenuLanguage ? "yes" : "no");
-  PrintToStdOut("Power on the TV when starting XBMC:                      %s", g_config.bPowerOnStartup ? "yes" : "no");
-  PrintToStdOut("Power off devices when stopping XBMC:                    %s", g_config.bPowerOffShutdown ? "yes" : "no");
+  PrintToStdOut("Make the adapter the active source when starting XBMC:   %s", g_config.bActivateSource ? "yes" : "no");
+  PrintToStdOut("Power off devices when stopping XBMC:                    %s", g_config.powerOffDevices.IsSet(CECDEVICE_BROADCAST) ? "yes" : "no");
   PrintToStdOut("Put devices in standby mode when activating screensaver: %s", g_config.bPowerOffScreensaver ? "yes" : "no");
   PrintToStdOut("Put this PC in standby mode when the TV is switched off: %s\n\n", g_config.bPowerOffOnStandby ? "yes" : "no");
 
@@ -451,8 +452,8 @@ int main (int UNUSED(argc), char *UNUSED(argv[]))
           "\t<setting id=\"connected_device\" value=\"" << (int)g_config.baseDevice << "\" />\n" <<
           "\t<setting id=\"physical_address\" value=\"" << hex << g_config.iPhysicalAddress << "\" />\n" <<
           "\t<setting id=\"use_tv_menu_language\" value=\"" << (int)g_config.bUseTVMenuLanguage << "\" />\n" <<
-          "\t<setting id=\"cec_power_on_startup\" value=\"" << (int)g_config.bPowerOnStartup << "\" />\n" <<
-          "\t<setting id=\"cec_power_off_shutdown\" value=\"" << (int)g_config.bPowerOffShutdown << "\" />\n" <<
+          "\t<setting id=\"cec_power_on_startup\" value=\"" << (int)g_config.bActivateSource << "\" />\n" <<
+          "\t<setting id=\"cec_power_off_shutdown\" value=\"" << (int)(g_config.powerOffDevices.IsSet(CECDEVICE_BROADCAST) ? 1 : 0) << "\" />\n" <<
           "\t<setting id=\"cec_standby_screensaver\" value=\"" << (int)g_config.bPowerOffScreensaver << "\" />\n" <<
           "\t<setting id=\"standby_pc_on_tv_standby\" value=\"" << (int)g_config.bPowerOffOnStandby << "\" />\n" <<
           "\t<setting id=\"enabled\" value=\"1\" />\n" <<
index ef2bbd10c4a0a7724b64d30223ee72d846a7a877..3bc4e7372767cbbdc3f632bc1b9c4a313ea0a46d 100644 (file)
@@ -228,7 +228,7 @@ bool CCECProcessor::Initialise(void)
   else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
     CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
 
-  WakeDevices();
+  PowerOnDevices();
 
   SetInitialised(bReturn);
   CLibCEC::ConfigurationChanged(m_configuration);
@@ -236,15 +236,6 @@ bool CCECProcessor::Initialise(void)
   return bReturn;
 }
 
-void CCECProcessor::WakeDevices(void)
-{
-  for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
-  {
-    if (m_configuration.wakeDevices[iPtr])
-      m_busDevices[iPtr]->PowerOn();
-  }
-}
-
 bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
 {
   bool bReturn(false);
@@ -953,6 +944,38 @@ bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bW
   return m_busDevices[iDestination]->TransmitKeyRelease(bWait);
 }
 
+bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
+{
+  if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
+  {
+    bool bReturn(true);
+    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    {
+      if (m_configuration.powerOffDevices[iPtr])
+        bReturn &= m_busDevices[iPtr]->Standby();
+    }
+    return bReturn;
+  }
+
+  return m_busDevices[address]->Standby();
+}
+
+bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
+{
+  if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
+  {
+    bool bReturn(true);
+    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    {
+      if (m_configuration.powerOffDevices[iPtr])
+        bReturn &= m_busDevices[iPtr]->PowerOn();
+    }
+    return bReturn;
+  }
+
+  return m_busDevices[address]->PowerOn();
+}
+
 const char *CCECProcessor::ToString(const cec_device_type type)
 {
   switch (type)
@@ -1426,13 +1449,12 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
   {
     m_configuration.wakeDevices = configuration->wakeDevices;
     if (!bNeedsReinit && IsRunning())
-      WakeDevices();
+      PowerOnDevices();
   }
 
   // just copy these
   m_configuration.bGetSettingsFromROM  = configuration->bGetSettingsFromROM;
-  m_configuration.bPowerOnStartup      = configuration->bPowerOnStartup;
-  m_configuration.bPowerOffShutdown    = configuration->bPowerOffShutdown;
+  m_configuration.powerOffDevices      = configuration->powerOffDevices;
   m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver;
   m_configuration.bPowerOffOnStandby   = configuration->bPowerOffOnStandby;
 
@@ -1464,8 +1486,7 @@ bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
   configuration->tvVendor             = m_configuration.tvVendor;
   configuration->wakeDevices          = m_configuration.wakeDevices;
   configuration->bGetSettingsFromROM  = m_configuration.bGetSettingsFromROM;
-  configuration->bPowerOnStartup      = m_configuration.bPowerOnStartup;
-  configuration->bPowerOffShutdown    = m_configuration.bPowerOffShutdown;
+  configuration->powerOffDevices      = m_configuration.powerOffDevices;
   configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver;
   configuration->bPowerOffOnStandby   = m_configuration.bPowerOffOnStandby;
 
index 7ebe93fb8336c8ff16cf924b16c99e54e3581d7c..ea8c03a4abe337a3187474e3f5c2d26ab181cb16 100644 (file)
@@ -85,6 +85,8 @@ namespace CEC
       virtual bool                  IsInitialised(void);
       virtual bool                  SetStreamPath(uint16_t iPhysicalAddress);
       virtual cec_client_version    GetClientVersion(void) const { return m_configuration.clientVersion; };
+      virtual bool                  StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
+      virtual bool                  PowerOnDevices(cec_logical_address address = CECDEVICE_BROADCAST);
 
       virtual bool SetActiveView(void);
       virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
@@ -147,7 +149,6 @@ namespace CEC
       void SetInitialised(bool bSetTo = true);
       void CreateBusDevices(void);
 
-      void WakeDevices(void);
       void ReplaceHandlers(void);
       void ScanCECBus(void);
       bool PhysicalAddressInUse(uint16_t iPhysicalAddress);
index f7159d502ce6a6fb6206579f4cb2b484446e7c73..67e8b6018415396a0f667eadad684e3bb42ee9c8 100644 (file)
@@ -166,12 +166,12 @@ bool CLibCEC::EnablePhysicalAddressDetection(void)
 
 bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
 {
-  return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->PowerOn() : false;
+  return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->PowerOnDevices(address) : false;
 }
 
 bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
 {
-  return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->Standby() : false;
+  return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->StandbyDevices(address) : false;
 }
 
 bool CLibCEC::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)