From: Lars Op den Kamp Date: Fri, 11 Nov 2011 00:45:57 +0000 (+0100) Subject: cec: added SetDeckControlMode() and SetDeckInfo(). handle deck related opcodes. proba... X-Git-Tag: upstream/2.2.0~1^2~57 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a9232a79cfb71be51caea8aae6c8ea63ae3884ad;p=deb_libcec.git cec: added SetDeckControlMode() and SetDeckInfo(). handle deck related opcodes. probably needs some further tweaking --- diff --git a/include/cec.h b/include/cec.h index 8212f17..6a8996d 100644 --- a/include/cec.h +++ b/include/cec.h @@ -163,6 +163,20 @@ namespace CEC */ virtual bool SetActiveView(void) = 0; + /*! + * @brief Change the deck control mode, if this adapter is registered as playback device. + * @param mode The new control mode. + * @return True if set, false otherwise. + */ + virtual bool SetDeckControlMode(cec_deck_control_mode mode) = 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; + /*! * @brief Broadcast a message that notifies connected CEC capable devices that this device is no longer the active source. * @return True when the command was sent succesfully, false otherwise. diff --git a/include/cectypes.h b/include/cectypes.h index 65225b8..4e5413e 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -117,10 +117,10 @@ typedef enum cec_channel_identifier typedef enum cec_deck_control_mode { - CEC_DESK_CONTROL_MODE_SKIP_FORWARD_WIND = 1, - CEC_DESK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2, - CEC_DESK_CONTROL_MODE_STOP = 3, - CEC_DESK_CONTROL_MODE_EJECT = 4 + CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND = 1, + CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND = 2, + CEC_DECK_CONTROL_MODE_STOP = 3, + CEC_DECK_CONTROL_MODE_EJECT = 4 } cec_deck_control_mode; typedef enum cec_deck_info diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index dce52ac..d094be1 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -319,6 +319,34 @@ bool CCECProcessor::SetActiveView(void) return SetActiveSource(); } +bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode) +{ + bool bReturn(false); + + CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); + if (device) + { + ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode); + bReturn = true; + } + + return bReturn; +} + +bool CCECProcessor::SetDeckInfo(cec_deck_info info) +{ + bool bReturn(false); + + CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); + if (device) + { + ((CCECPlaybackDevice *) device)->SetDeckStatus(info); + bReturn = true; + } + + return bReturn; +} + bool CCECProcessor::SetStreamPath(uint16_t iStreamPath) { bool bReturn(false); @@ -408,7 +436,6 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress) return false; } - CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const { CCECBusDevice *device = NULL; @@ -425,6 +452,22 @@ CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddre return device; } +CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const +{ + CCECBusDevice *device = NULL; + + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + { + if (m_busDevices[iPtr]->m_type == type) + { + device = m_busDevices[iPtr]; + break; + } + } + + return device; +} + cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) { return m_busDevices[iAddress]->GetCecVersion(); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index b166b5f..a0192f2 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -58,6 +58,7 @@ namespace CEC virtual bool IsMonitoring(void) const { return m_bMonitor; } virtual CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const; + virtual CCECBusDevice * GetDeviceByType(cec_device_type type) const; virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); virtual const std::string & GetDeviceName(void) { return m_strDeviceName; } @@ -70,6 +71,8 @@ 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 SetInactiveView(void); virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 0959beb..a226d41 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -186,6 +186,16 @@ bool CLibCEC::SetActiveView(void) return m_cec ? m_cec->SetActiveView() : false; } +bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode) +{ + return m_cec ? m_cec->SetDeckControlMode(mode) : false; +} + +bool CLibCEC::SetDeckInfo(cec_deck_info info) +{ + return m_cec ? m_cec->SetDeckInfo(info) : false; +} + bool CLibCEC::SetInactiveView(void) { return m_cec ? m_cec->SetInactiveView() : false; diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index b3477e1..3982420 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -73,6 +73,8 @@ 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 SetInactiveView(void); virtual bool SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage); virtual bool SwitchMonitoring(bool bEnable); diff --git a/src/lib/devices/CECPlaybackDevice.cpp b/src/lib/devices/CECPlaybackDevice.cpp index ef6f00b..cee7c49 100644 --- a/src/lib/devices/CECPlaybackDevice.cpp +++ b/src/lib/devices/CECPlaybackDevice.cpp @@ -38,7 +38,8 @@ using namespace CEC; CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) : CCECBusDevice(processor, address, iPhysicalAddress), - m_deckStatus(CEC_DECK_INFO_NO_MEDIA) + m_deckStatus(CEC_DECK_INFO_STOP), + m_deckControlMode(CEC_DECK_CONTROL_MODE_STOP) { m_type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE; } @@ -55,13 +56,27 @@ void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus) } } +void CCECPlaybackDevice::SetDeckControlMode(cec_deck_control_mode mode) +{ + if (m_deckControlMode != mode) + { + CStdString strLog; + strLog.Format(">> %s (%X): deck control mode changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_deckControlMode), CCECCommandHandler::ToString(mode)); + AddLog(CEC_LOG_DEBUG, strLog.c_str()); + + m_deckControlMode = mode; + } +} + bool CCECPlaybackDevice::TransmitDeckStatus(cec_logical_address dest) { - // need to support opcodes play and deck control before doing anything with this CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): deck status feature abort", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest); + strLog.Format("<< %s (%X) -> %s (%X): deck status '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, CCECCommandHandler::ToString(m_deckStatus)); AddLog(CEC_LOG_NOTICE, strLog); - m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DECK_STATUS); - return false; + cec_command command; + cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_GIVE_DECK_STATUS); + command.push_back((uint8_t)m_deckStatus); + + return m_processor->Transmit(command); } diff --git a/src/lib/devices/CECPlaybackDevice.h b/src/lib/devices/CECPlaybackDevice.h index 24ce072..db504f7 100644 --- a/src/lib/devices/CECPlaybackDevice.h +++ b/src/lib/devices/CECPlaybackDevice.h @@ -42,12 +42,15 @@ namespace CEC virtual ~CCECPlaybackDevice(void) {}; virtual cec_deck_info GetDeckStatus(void) const { return m_deckStatus; }; + virtual cec_deck_control_mode GetDeckControlMode(void) const { return m_deckControlMode; }; virtual void SetDeckStatus(cec_deck_info deckStatus); + virtual void SetDeckControlMode(cec_deck_control_mode mode); virtual bool TransmitDeckStatus(cec_logical_address dest); protected: - cec_deck_info m_deckStatus; + cec_deck_info m_deckStatus; + cec_deck_control_mode m_deckControlMode; }; } diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index b52b8aa..7785ef6 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -85,6 +85,9 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) case CEC_OPCODE_GIVE_DECK_STATUS: HandleGiveDeckStatus(command); break; + case CEC_OPCODE_DECK_CONTROL: + HandleDeckControl(command); + break; case CEC_OPCODE_MENU_REQUEST: HandleMenuRequest(command); break; @@ -182,6 +185,18 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command) return true; } +bool CCECCommandHandler::HandleDeckControl(const cec_command &command) +{ + CCECBusDevice *device = GetDevice(command.destination); + if (device && device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE && command.parameters.size > 0) + { + ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); + return true; + } + + return false; +} + bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) { if (command.parameters.size == 1) @@ -540,6 +555,23 @@ const char *CCECCommandHandler::ToString(const cec_logical_address address) } } +const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode) +{ + switch (mode) + { + case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND: + return "skip forward wind"; + case CEC_DECK_CONTROL_MODE_EJECT: + return "eject"; + case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND: + return "reverse rewind"; + case CEC_DECK_CONTROL_MODE_STOP: + return "stop"; + default: + return "unknown"; + } +} + const char *CCECCommandHandler::ToString(const cec_deck_info status) { switch (status) diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 7185ede..16095f6 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_deck_control_mode mode); static const char *ToString(const cec_version version); static const char *ToString(const cec_power_status status); static const char *ToString(const cec_deck_info status); @@ -55,6 +56,7 @@ namespace CEC protected: virtual bool HandleActiveSource(const cec_command &command); + virtual bool HandleDeckControl(const cec_command &command); virtual bool HandleDeviceCecVersion(const cec_command &command); virtual bool HandleDeviceVendorCommandWithId(const cec_command &command); virtual bool HandleDeviceVendorId(const cec_command &command);