From: Lars Op den Kamp Date: Sun, 27 Nov 2011 23:03:35 +0000 (+0100) Subject: cec: added SendKeypress()/cec_send_keypress() and SendKeyRelease()/cec_send_key_release() X-Git-Tag: upstream/2.2.0~1^2~44^2~90 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a33794d8b865d4b1d7b82fbae70bdb7658129614;p=deb_libcec.git cec: added SendKeypress()/cec_send_keypress() and SendKeyRelease()/cec_send_key_release() --- diff --git a/include/cec.h b/include/cec.h index 1486b28..70c17ce 100644 --- a/include/cec.h +++ b/include/cec.h @@ -290,6 +290,23 @@ namespace CEC * @return The new audio status. */ virtual uint8_t MuteAudio(bool bWait = true) = 0; + + /*! + * @brief Send a keypress to a device on the CEC bus. + * @param iDestination The address to send the message to. + * @param key The key to send. + * @param bWait True to wait for a response, false otherwise. + * @return True when the keypress was acked, false otherwise. + */ + virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false) = 0; + + /*! + * @brief Send a key release to a device on the CEC bus. + * @param iDestination The address to send the message to. + * @param bWait True to wait for a response, false otherwise. + * @return True when the keypress was acked, false otherwise. + */ + virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index d4765e0..07050bc 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -187,11 +187,24 @@ extern DECLSPEC int cec_is_active_device_type(cec_device_type type); extern DECLSPEC int cec_set_hdmi_port(uint8_t iPort); -extern DECLSPEC int cec_volume_up(int bWait = 1); +extern DECLSPEC int cec_volume_up(int bWait); -extern DECLSPEC int cec_volume_down(int bWait = 1); +extern DECLSPEC int cec_volume_down(int bWait); + +extern DECLSPEC int cec_mute_audio(int bWait); + +#ifdef __cplusplus +extern DECLSPEC int cec_send_keypress(CEC::cec_logical_address iDestination, CEC::cec_user_control_code key, int bWait); +#else +extern DECLSPEC int cec_send_keypress(cec_logical_address iDestination, cec_user_control_code key, int bWait); +#endif + +#ifdef __cplusplus +extern DECLSPEC int cec_send_key_release(CEC::cec_logical_address iDestination, int bWait); +#else +extern DECLSPEC int cec_send_key_release(cec_logical_address iDestination, int bWait); +#endif -extern DECLSPEC int cec_mute_audio(int bWait = 1); #ifdef __cplusplus }; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index d8fdb99..021e431 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -813,3 +813,13 @@ bool CCECProcessor::SetAckMask(uint16_t iMask) return bReturn; } + +bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */) +{ + return m_busDevices[iDestination]->SendKeypress(key, bWait); +} + +bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */) +{ + return m_busDevices[iDestination]->SendKeyRelease(bWait); +} diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index ea8f6a4..c1c2874 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -88,6 +88,8 @@ namespace CEC virtual uint8_t VolumeUp(bool bWait = true); virtual uint8_t VolumeDown(bool bWait = true); virtual uint8_t MuteAudio(bool bWait = true); + virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false); + virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false); virtual bool Transmit(const cec_command &data); virtual bool Transmit(CCECAdapterMessage *output); @@ -129,5 +131,6 @@ namespace CEC CLibCEC* m_controller; bool m_bMonitor; CecBuffer m_commandBuffer; + cec_keypress m_previousKey; }; }; diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 26fd7b0..50239bc 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -302,6 +302,20 @@ uint8_t CLibCEC::MuteAudio(bool bWait /* = true */) return 0; } +bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */) +{ + if (m_cec) + return m_cec->SendKeypress(iDestination, key, bWait); + return false; +} + +bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */) +{ + if (m_cec) + return m_cec->SendKeyRelease(iDestination, bWait); + return false; +} + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index ad3b1cd..050fcc1 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -91,6 +91,8 @@ namespace CEC virtual uint8_t VolumeUp(bool bWait = true); virtual uint8_t VolumeDown(bool bWait = true); virtual uint8_t MuteAudio(bool bWait = true); + virtual bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = false); + virtual bool SendKeyRelease(cec_logical_address iDestination, bool bWait = false); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 0193124..f1e80fa 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -271,25 +271,39 @@ int cec_set_hdmi_port(uint8_t iPort) return -1; } -int cec_volume_up(int bWait /* = 1 */) +int cec_volume_up(int bWait) { if (cec_parser) return cec_parser->VolumeUp(bWait == 1); return -1; } -int cec_volume_down(int bWait /* = 1 */) +int cec_volume_down(int bWait) { if (cec_parser) return cec_parser->VolumeDown(bWait == 1); return -1; } -int cec_mute_audio(int bWait /* = 1 */) +int cec_mute_audio(int bWait) { if (cec_parser) return cec_parser->MuteAudio(bWait == 1); return -1; } +int cec_send_keypress(cec_logical_address iDestination, cec_user_control_code key, int bWait) +{ + if (cec_parser) + return cec_parser->SendKeypress(iDestination, key, bWait == 1) ? 1 : 0; + return -1; +} + +int cec_send_key_release(cec_logical_address iDestination, int bWait) +{ + if (cec_parser) + return cec_parser->SendKeyRelease(iDestination, bWait == 1) ? 1 : 0; + return -1; +} + //@} diff --git a/src/lib/devices/CECAudioSystem.cpp b/src/lib/devices/CECAudioSystem.cpp index 87735f4..9dd3123 100644 --- a/src/lib/devices/CECAudioSystem.cpp +++ b/src/lib/devices/CECAudioSystem.cpp @@ -111,39 +111,26 @@ bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest) uint8_t CCECAudioSystem::VolumeUp(bool bWait /* = true */) { - return SendKey(CEC_USER_CONTROL_CODE_VOLUME_UP, bWait); + if (SendKeypress(CEC_USER_CONTROL_CODE_VOLUME_UP)) + SendKeyRelease(bWait); + + CLockObject lock(&m_mutex); + return m_audioStatus; } uint8_t CCECAudioSystem::VolumeDown(bool bWait /* = true */) { - return SendKey(CEC_USER_CONTROL_CODE_VOLUME_DOWN, bWait); -} + if (SendKeypress(CEC_USER_CONTROL_CODE_VOLUME_DOWN)) + SendKeyRelease(bWait); -uint8_t CCECAudioSystem::MuteAudio(bool bWait /* = true */) -{ - return SendKey(CEC_USER_CONTROL_CODE_MUTE, bWait); + CLockObject lock(&m_mutex); + return m_audioStatus; } -uint8_t CCECAudioSystem::SendKey(cec_user_control_code key, bool bWait /* = true */) +uint8_t CCECAudioSystem::MuteAudio(bool bWait /* = true */) { - { - CLockObject lock(&m_transmitMutex); - cec_command command; - cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED); - command.parameters.PushBack(key); - m_processor->Transmit(command); - - cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE); - if (bWait) - { - if (m_processor->Transmit(command)) - m_condition.Wait(&m_transmitMutex, 1000); - } - else - { - m_processor->Transmit(command); - } - } + if (SendKeypress(CEC_USER_CONTROL_CODE_MUTE)) + SendKeyRelease(bWait); CLockObject lock(&m_mutex); return m_audioStatus; diff --git a/src/lib/devices/CECAudioSystem.h b/src/lib/devices/CECAudioSystem.h index 6c04ad9..7a7a16e 100644 --- a/src/lib/devices/CECAudioSystem.h +++ b/src/lib/devices/CECAudioSystem.h @@ -50,7 +50,6 @@ namespace CEC virtual uint8_t VolumeUp(bool bWait = true); virtual uint8_t VolumeDown(bool bWait = true); virtual uint8_t MuteAudio(bool bWait = true); - virtual uint8_t SendKey(cec_user_control_code key, bool bWait = true); virtual bool TransmitActiveSource(void) { return false; } diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index d5a0be6..5c38f63 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -748,4 +748,43 @@ bool CCECBusDevice::TransmitVendorID(cec_logical_address dest) return m_processor->Transmit(command); } } + +bool CCECBusDevice::SendKeypress(cec_user_control_code key, bool bWait /* = false */) +{ + { + CLockObject lock(&m_transmitMutex); + cec_command command; + cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED); + command.parameters.PushBack(key); + + if (bWait) + { + if (m_processor->Transmit(command)) + return m_condition.Wait(&m_transmitMutex, 1000); + return false; + } + + return m_processor->Transmit(command); + } +} + +bool CCECBusDevice::SendKeyRelease(bool bWait /* = false */) +{ + { + CLockObject lock(&m_transmitMutex); + cec_command command; + cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE); + + if (bWait) + { + if (m_processor->Transmit(command)) + return m_condition.Wait(&m_transmitMutex, 1000); + return false; + } + else + { + return m_processor->Transmit(command); + } + } +} //@} diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 57d353b..c86a1f2 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -102,6 +102,8 @@ namespace CEC virtual bool TransmitPowerState(cec_logical_address dest); virtual bool TransmitPoll(cec_logical_address dest); virtual bool TransmitVendorID(cec_logical_address dest); + virtual bool SendKeypress(cec_user_control_code key, bool bWait = true); + virtual bool SendKeyRelease(bool bWait = true); protected: cec_device_type m_type;