From ca27e6cf80cc7750e82f7cef6cb671a63b94db74 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Wed, 15 Feb 2012 16:00:56 +0100 Subject: [PATCH] cec: added poweroff devices parameter to the config (instead of a boolean parameter). changed the power on parameter into activate source. --- include/cectypes.h | 20 +++++++++----- src/cec-config/cec-config.cpp | 15 ++++++----- src/lib/CECProcessor.cpp | 51 ++++++++++++++++++++++++----------- src/lib/CECProcessor.h | 3 ++- src/lib/LibCEC.cpp | 4 +-- 5 files changed, 61 insertions(+), 32 deletions(-) diff --git a/include/cectypes.h b/include/cectypes.h index 41d124e..fe8678f 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -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; diff --git a/src/cec-config/cec-config.cpp b/src/cec-config/cec-config.cpp index 02e8126..b5ecd8e 100644 --- a/src/cec-config/cec-config.cpp +++ b/src/cec-config/cec-config.cpp @@ -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\n" << "\t\n" << "\t\n" << - "\t\n" << - "\t\n" << + "\t\n" << + "\t\n" << "\t\n" << "\t\n" << "\t\n" << diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index ef2bbd1..3bc4e73 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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; diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 7ebe93f..ea8c03a 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -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); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index f7159d5..67e8b60 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -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 */) -- 2.34.1