From: Lars Op den Kamp Date: Fri, 11 Nov 2011 12:51:09 +0000 (+0100) Subject: cec: added SetMenuState() X-Git-Tag: upstream/2.2.0~1^2~54 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=28fa6c976a4c91b515be4cb119f92e2000bbd90e;p=deb_libcec.git cec: added SetMenuState() --- diff --git a/include/cec.h b/include/cec.h index 6a8996d..7a306dd 100644 --- a/include/cec.h +++ b/include/cec.h @@ -166,16 +166,17 @@ namespace CEC /*! * @brief Change the deck control mode, if this adapter is registered as playback device. * @param mode The new control mode. + * @param bSendUpdate True to send the status over the CEC line. * @return True if set, false otherwise. */ - virtual bool SetDeckControlMode(cec_deck_control_mode mode) = 0; + virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true) = 0; /*! * @brief Change the deck info, if this adapter is a playback device. * @param info The new deck info. * @return True if set, false otherwise. */ - virtual bool SetDeckInfo(cec_deck_info info) = 0; + virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true) = 0; /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. @@ -183,6 +184,14 @@ namespace CEC */ virtual bool SetInactiveView(void) = 0; + /*! + * @brief Change the menu state. + * @param state The new true. + * @param bSendUpdate True to send the status over the CEC line. + * @return True if set, false otherwise. + */ + virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true) = 0; + /*! * @brief Display a message on the device with the given logical address. * @param iLogicalAddres The device to display the message on. diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index cf3ea3f..f2eafaa 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -320,7 +320,7 @@ bool CCECProcessor::SetActiveView(void) return SetActiveSource(); } -bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode) +bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) { bool bReturn(false); @@ -328,13 +328,15 @@ bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode) if (device) { ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode); + if (bSendUpdate) + ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); bReturn = true; } return bReturn; } -bool CCECProcessor::SetDeckInfo(cec_deck_info info) +bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) { bool bReturn(false); @@ -342,6 +344,8 @@ bool CCECProcessor::SetDeckInfo(cec_deck_info info) if (device) { ((CCECPlaybackDevice *) device)->SetDeckStatus(info); + if (bSendUpdate) + ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); bReturn = true; } @@ -407,6 +411,20 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) return true; } +bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) +{ + for (uint8_t iPtr = 0; iPtr < 16; iPtr++) + { + if (m_logicalAddresses[iPtr]) + m_busDevices[iPtr]->SetMenuState(state); + } + + if (bSendUpdate) + m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV); + + return true; +} + bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) { if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary]) diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index a0192f2..8f8e892 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -71,10 +71,11 @@ namespace CEC virtual bool SetActiveView(void); virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED); - virtual bool SetDeckControlMode(cec_deck_control_mode mode); - virtual bool SetDeckInfo(cec_deck_info info); + virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true); + virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true); virtual bool SetInactiveView(void); virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); + virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); virtual bool SetStreamPath(uint16_t iStreamPath); virtual bool SwitchMonitoring(bool bEnable); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index a226d41..c067562 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -186,14 +186,14 @@ bool CLibCEC::SetActiveView(void) return m_cec ? m_cec->SetActiveView() : false; } -bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode) +bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) { - return m_cec ? m_cec->SetDeckControlMode(mode) : false; + return m_cec ? m_cec->SetDeckControlMode(mode, bSendUpdate) : false; } -bool CLibCEC::SetDeckInfo(cec_deck_info info) +bool CLibCEC::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) { - return m_cec ? m_cec->SetDeckInfo(info) : false; + return m_cec ? m_cec->SetDeckInfo(info, bSendUpdate) : false; } bool CLibCEC::SetInactiveView(void) @@ -201,6 +201,11 @@ bool CLibCEC::SetInactiveView(void) return m_cec ? m_cec->SetInactiveView() : false; } +bool CLibCEC::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) +{ + return m_cec ? m_cec->SetMenuState(state, bSendUpdate) : false; +} + bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) { return m_cec && iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST ? diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 3982420..7a69c96 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -73,9 +73,10 @@ namespace CEC virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST); virtual bool SetActiveView(void); virtual bool SetActiveSource(cec_device_type type = CEC_DEVICE_TYPE_RESERVED); - virtual bool SetDeckControlMode(cec_deck_control_mode mode); - virtual bool SetDeckInfo(cec_deck_info info); + virtual bool SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate = true); + virtual bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true); virtual bool SetInactiveView(void); + virtual bool SetMenuState(cec_menu_state state, bool bSendUpdate = true); virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage); virtual bool SwitchMonitoring(bool bEnable); virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 3eeb295..26b964b 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -50,7 +50,7 @@ CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogi m_powerStatus(CEC_POWER_STATUS_UNKNOWN), m_processor(processor), m_vendor(CEC_VENDOR_UNKNOWN), - m_bMenuActive(true), + m_menuState(CEC_MENU_STATE_DEACTIVATED), m_bActiveSource(false), m_iLastCommandSent(0), m_iLastActive(0), @@ -272,6 +272,17 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) } } +void CCECBusDevice::SetMenuState(const cec_menu_state state) +{ + if (m_menuState != state) + { + CStdString strLog; + strLog.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); + m_processor->AddLog(CEC_LOG_DEBUG, strLog); + m_menuState = state; + } +} + void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) { if (iNewAddress > 0) @@ -415,16 +426,12 @@ bool CCECBusDevice::TransmitInactiveView(void) bool CCECBusDevice::TransmitMenuState(cec_logical_address dest) { CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); - if (m_bMenuActive) - strLog.append("menu active"); - else - strLog.append("menu inactive"); + strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); AddLog(CEC_LOG_NOTICE, strLog); cec_command command; cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_MENU_STATUS); - command.parameters.push_back(m_bMenuActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); + command.parameters.push_back((uint8_t)m_menuState); return m_processor->Transmit(command); } diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index cad6591..245f829 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -75,6 +75,7 @@ namespace CEC virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = 0); virtual void SetCecVersion(const cec_version newVersion); virtual void SetMenuLanguage(const cec_menu_language &menuLanguage); + virtual void SetMenuState(const cec_menu_state state); virtual void SetVendorId(uint64_t iVendorId); virtual void SetPowerStatus(const cec_power_status powerStatus); @@ -100,7 +101,7 @@ namespace CEC CCECProcessor *m_processor; CCECCommandHandler *m_handler; cec_vendor_id m_vendor; - bool m_bMenuActive; + cec_menu_state m_menuState; bool m_bActiveSource; uint64_t m_iLastCommandSent; uint64_t m_iLastActive; diff --git a/src/lib/devices/CECPlaybackDevice.cpp b/src/lib/devices/CECPlaybackDevice.cpp index cee7c49..02b9d43 100644 --- a/src/lib/devices/CECPlaybackDevice.cpp +++ b/src/lib/devices/CECPlaybackDevice.cpp @@ -75,7 +75,7 @@ bool CCECPlaybackDevice::TransmitDeckStatus(cec_logical_address dest) AddLog(CEC_LOG_NOTICE, strLog); cec_command command; - cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_GIVE_DECK_STATUS); + cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_DECK_STATUS); command.push_back((uint8_t)m_deckStatus); return m_processor->Transmit(command); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 1c0f8d9..a6b5d10 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -487,6 +487,19 @@ void CCECCommandHandler::SetVendorId(const cec_command &command) device->SetVendorId(iVendorId); } +const char *CCECCommandHandler::ToString(const cec_menu_state state) +{ + switch (state) + { + case CEC_MENU_STATE_ACTIVATED: + return "activated"; + case CEC_MENU_STATE_DEACTIVATED: + return "deactivated"; + default: + return "unknown"; + } +} + const char *CCECCommandHandler::ToString(const cec_version version) { switch (version) diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index aed84fd..9bf9898 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -47,6 +47,7 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }; + static const char *ToString(const cec_menu_state state); static const char *ToString(const cec_deck_control_mode mode); static const char *ToString(const cec_version version); static const char *ToString(const cec_power_status status);