diff options
author | Lars Op den Kamp <opdenkamp@gmail.com> | 2013-07-08 17:22:35 -0700 |
---|---|---|
committer | Lars Op den Kamp <opdenkamp@gmail.com> | 2013-07-08 17:22:35 -0700 |
commit | d8b4503f0be7eae2d8236953aad8e9820a36c86c (patch) | |
tree | 02151cffac25702d36447be61d8947613c264318 | |
parent | 96b1c9764da810371f2ce4d1e015016a3f59901c (diff) | |
parent | 19d37944ca2a2ac2f3e71a40a94e9ea289d8f2db (diff) |
Merge pull request #2598 from jmarcet/for-upstream
Add new Action ToggleCECDevice() to switch state of playing device via a CEC peripheral
-rw-r--r-- | xbmc/Application.cpp | 14 | ||||
-rw-r--r-- | xbmc/ApplicationMessenger.cpp | 50 | ||||
-rw-r--r-- | xbmc/ApplicationMessenger.h | 6 | ||||
-rw-r--r-- | xbmc/interfaces/Builtins.cpp | 15 | ||||
-rw-r--r-- | xbmc/peripherals/Peripherals.cpp | 20 | ||||
-rw-r--r-- | xbmc/peripherals/Peripherals.h | 8 | ||||
-rw-r--r-- | xbmc/peripherals/devices/Peripheral.h | 7 | ||||
-rw-r--r-- | xbmc/peripherals/devices/PeripheralCecAdapter.cpp | 26 | ||||
-rw-r--r-- | xbmc/peripherals/devices/PeripheralCecAdapter.h | 2 |
9 files changed, 148 insertions, 0 deletions
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index d560360305..3937ce8f6f 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -2180,6 +2180,20 @@ bool CApplication::OnKey(const CKey& key) m_idleTimer.StartZero(); bool processKey = AlwaysProcess(action); + if (StringUtils::StartsWith(action.GetName(),"CECToggleState") || StringUtils::StartsWith(action.GetName(),"CECStandby")) + { + bool ret = true; + + CLog::Log(LOGDEBUG, "%s: action %s [%d], toggling state of playing device", __FUNCTION__, action.GetName().c_str(), action.GetID()); + // do not wake up the screensaver right after switching off the playing device + if (StringUtils::StartsWith(action.GetName(),"CECToggleState")) + ret = CApplicationMessenger::Get().CECToggleState(); + else + ret = CApplicationMessenger::Get().CECStandby(); + if (!ret) /* display is switched off */ + return true; + } + ResetScreenSaver(); // allow some keys to be processed while the screensaver is active diff --git a/xbmc/ApplicationMessenger.cpp b/xbmc/ApplicationMessenger.cpp index bcc7f6ef76..4a44c43d42 100644 --- a/xbmc/ApplicationMessenger.cpp +++ b/xbmc/ApplicationMessenger.cpp @@ -45,6 +45,7 @@ #include "cores/AudioEngine/AEFactory.h" #include "music/tags/MusicInfoTag.h" +#include "peripherals/Peripherals.h" #include "powermanagement/PowerManager.h" #ifdef TARGET_WINDOWS @@ -73,6 +74,7 @@ using namespace PVR; using namespace std; using namespace MUSIC_INFO; +using namespace PERIPHERALS; CDelayedMessage::CDelayedMessage(ThreadMessage& msg, unsigned int delay) : CThread("DelayedMessage") { @@ -824,6 +826,21 @@ void CApplicationMessenger::ProcessMessage(ThreadMessage *pMsg) CGUIWindowLoginScreen::LoadProfile(pMsg->dwParam1); break; } + case TMSG_CECTOGGLESTATE: + { + *((bool*)pMsg->lpVoid) = g_peripherals.ToggleDeviceState(STATE_SWITCH_TOGGLE); + break; + } + case TMSG_CECACTIVATESOURCE: + { + *((bool*)pMsg->lpVoid) = g_peripherals.ToggleDeviceState(STATE_ACTIVATE_SOURCE); + break; + } + case TMSG_CECSTANDBY: + { + *((bool*)pMsg->lpVoid) = g_peripherals.ToggleDeviceState(STATE_STANDBY); + break; + } case TMSG_START_ANDROID_ACTIVITY: { #if defined(TARGET_ANDROID) @@ -1347,3 +1364,36 @@ void CApplicationMessenger::StartAndroidActivity(const vector<CStdString> ¶m tMsg.params = params; SendMessage(tMsg, false); } + +bool CApplicationMessenger::CECToggleState() +{ + bool result; + + ThreadMessage tMsg = {TMSG_CECTOGGLESTATE}; + tMsg.lpVoid = (void*)&result; + SendMessage(tMsg, false); + + return result; +} + +bool CApplicationMessenger::CECActivateSource() +{ + bool result; + + ThreadMessage tMsg = {TMSG_CECACTIVATESOURCE}; + tMsg.lpVoid = (void*)&result; + SendMessage(tMsg, false); + + return result; +} + +bool CApplicationMessenger::CECStandby() +{ + bool result; + + ThreadMessage tMsg = {TMSG_CECSTANDBY}; + tMsg.lpVoid = (void*)&result; + SendMessage(tMsg, false); + + return result; +} diff --git a/xbmc/ApplicationMessenger.h b/xbmc/ApplicationMessenger.h index d26fb678c1..d6b19e165f 100644 --- a/xbmc/ApplicationMessenger.h +++ b/xbmc/ApplicationMessenger.h @@ -90,6 +90,9 @@ namespace MUSIC_INFO #define TMSG_INHIBITIDLESHUTDOWN 313 #define TMSG_LOADPROFILE 314 #define TMSG_ACTIVATESCREENSAVER 315 +#define TMSG_CECTOGGLESTATE 316 +#define TMSG_CECACTIVATESOURCE 317 +#define TMSG_CECSTANDBY 318 #define TMSG_NETWORKMESSAGE 500 @@ -216,6 +219,9 @@ public: void SetCurrentItem(const CFileItem& item); void LoadProfile(unsigned int idx); + bool CECToggleState(); + bool CECActivateSource(); + bool CECStandby(); CStdString GetResponse(); int SetResponse(CStdString response); diff --git a/xbmc/interfaces/Builtins.cpp b/xbmc/interfaces/Builtins.cpp index e753b25859..5aa99b1295 100644 --- a/xbmc/interfaces/Builtins.cpp +++ b/xbmc/interfaces/Builtins.cpp @@ -204,6 +204,9 @@ const BUILT_IN commands[] = { { "UpdateAddonRepos", false, "Check add-on repositories for updates" }, { "UpdateLocalAddons", false, "Check for local add-on changes" }, { "ToggleDPMS", false, "Toggle DPMS mode manually"}, + { "CECToggleState", false, "Toggle state of playing device via a CEC peripheral"}, + { "CECActivateSource", false, "Wake up playing device via a CEC peripheral"}, + { "CECStandby", false, "Put playing device on standby via a CEC peripheral"}, { "Weather.Refresh", false, "Force weather data refresh"}, { "Weather.LocationNext", false, "Switch to next weather location"}, { "Weather.LocationPrevious", false, "Switch to previous weather location"}, @@ -1591,6 +1594,18 @@ int CBuiltins::Execute(const CStdString& execString) { g_application.ToggleDPMS(true); } + else if (execute.Equals("cectogglestate")) + { + CApplicationMessenger::Get().CECToggleState(); + } + else if (execute.Equals("cecactivatesource")) + { + CApplicationMessenger::Get().CECActivateSource(); + } + else if (execute.Equals("cecstandby")) + { + CApplicationMessenger::Get().CECStandby(); + } #if defined(HAS_LIRC) || defined(HAS_IRSERVERSUITE) else if (execute.Equals("lirc.stop")) { diff --git a/xbmc/peripherals/Peripherals.cpp b/xbmc/peripherals/Peripherals.cpp index b9f066cf6f..6691b2fa73 100644 --- a/xbmc/peripherals/Peripherals.cpp +++ b/xbmc/peripherals/Peripherals.cpp @@ -634,6 +634,26 @@ bool CPeripherals::ToggleMute(void) return false; } +bool CPeripherals::ToggleDeviceState(CecStateChange mode /*= STATE_SWITCH_TOGGLE */, unsigned int iPeripheral /*= 0 */) +{ + bool ret(false); + vector<CPeripheral *> peripherals; + + if (SupportsCEC() && GetPeripheralsWithFeature(peripherals, FEATURE_CEC)) + { + for (unsigned int iPeripheralPtr = iPeripheral; iPeripheralPtr < peripherals.size(); iPeripheralPtr++) + { + CPeripheralCecAdapter *cecDevice = (CPeripheralCecAdapter *) peripherals.at(iPeripheralPtr); + if (cecDevice) + ret = cecDevice->ToggleDeviceState(mode); + if (iPeripheral) + break; + } + } + + return ret; +} + bool CPeripherals::GetNextKeypress(float frameTime, CKey &key) { vector<CPeripheral *> peripherals; diff --git a/xbmc/peripherals/Peripherals.h b/xbmc/peripherals/Peripherals.h index 1e93b3dc54..ed48ccfad9 100644 --- a/xbmc/peripherals/Peripherals.h +++ b/xbmc/peripherals/Peripherals.h @@ -169,6 +169,14 @@ namespace PERIPHERALS virtual bool ToggleMute(void); /*! + * @brief Try to toggle the playing device state via a peripheral. + * @param mode Whether to activate, put on standby or toggle the source. + * @param iPeripheral Optional CPeripheralCecAdapter pointer to a specific device, instead of iterating through all of them. + * @return True when the playing device has been switched on, false otherwise. + */ + virtual bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE, const unsigned int iPeripheral = 0); + + /*! * @brief Try to mute the audio via a peripheral. * @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise. */ diff --git a/xbmc/peripherals/devices/Peripheral.h b/xbmc/peripherals/devices/Peripheral.h index 51f6c566c3..ab45e9714f 100644 --- a/xbmc/peripherals/devices/Peripheral.h +++ b/xbmc/peripherals/devices/Peripheral.h @@ -31,6 +31,13 @@ namespace PERIPHERALS { class CGUIDialogPeripheralSettings; + typedef enum + { + STATE_SWITCH_TOGGLE, + STATE_ACTIVATE_SOURCE, + STATE_STANDBY + } CecStateChange; + class CPeripheral { friend class CGUIDialogPeripheralSettings; diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp index 386d3e4165..7f071ca400 100644 --- a/xbmc/peripherals/devices/PeripheralCecAdapter.cpp +++ b/xbmc/peripherals/devices/PeripheralCecAdapter.cpp @@ -1676,7 +1676,33 @@ void CPeripheralCecAdapter::ProcessStandbyDevices(void) } if (bStandby) + { m_cecAdapter->StandbyDevices(CECDEVICE_BROADCAST); + if (m_configuration.bSendInactiveSource == 1) + { + CLog::Log(LOGDEBUG, "%s - sending inactive source commands", __FUNCTION__); + m_cecAdapter->SetInactiveView(); + } + } +} + +bool CPeripheralCecAdapter::ToggleDeviceState(CecStateChange mode /*= STATE_SWITCH_TOGGLE */, bool forceType /*= false */) +{ + if (!IsRunning()) + return false; + if (m_cecAdapter->IsLibCECActiveSource() && (mode == STATE_SWITCH_TOGGLE || mode == STATE_STANDBY)) + { + CLog::Log(LOGDEBUG, "%s - putting CEC device on standby...", __FUNCTION__); + m_screensaverLastActivated = CDateTime::GetCurrentDateTime(); + StandbyDevices(); + return false; + } + else if (mode == STATE_SWITCH_TOGGLE || mode == STATE_ACTIVATE_SOURCE) + { + CLog::Log(LOGDEBUG, "%s - waking up CEC device...", __FUNCTION__); + ActivateSource(); + return true; + } } #endif diff --git a/xbmc/peripherals/devices/PeripheralCecAdapter.h b/xbmc/peripherals/devices/PeripheralCecAdapter.h index 4b671396a1..0a4100e323 100644 --- a/xbmc/peripherals/devices/PeripheralCecAdapter.h +++ b/xbmc/peripherals/devices/PeripheralCecAdapter.h @@ -35,6 +35,7 @@ namespace PERIPHERALS void VolumeDown(void) {} bool IsMuted(void) { return false; } void ToggleMute(void) {} + bool ToggleDeviceState(CecStateChange mode = STATE_SWITCH_TOGGLE, bool forceType = false) { return false; } int GetButton(void) { return 0; } unsigned int GetHoldTime(void) { return 0; } @@ -110,6 +111,7 @@ namespace PERIPHERALS // public CEC methods void ActivateSource(void); void StandbyDevices(void); + bool ToggleDeviceState(CecStateChange mode = STATE_SWITCH_TOGGLE, bool forceType = false); private: bool InitialiseFeature(const PeripheralFeature feature); |