* @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;
};
};
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
};
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);
+}
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);
CLibCEC* m_controller;
bool m_bMonitor;
CecBuffer<cec_command> m_commandBuffer;
+ cec_keypress m_previousKey;
};
};
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)
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);
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;
+}
+
//@}
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;
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; }
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);
+ }
+ }
+}
//@}
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;