X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FLibCEC.cpp;h=ab252906686d020538e98649a29561e67f7316ae;hb=f077e8ede7d2c288ff1d9a358eb0c7cceac5fddc;hp=afbf2260f5c16dbeaee4e55a764bf2eb49875e16;hpb=9dee1670cb5167360026a910a33de46e811a8588;p=deb_libcec.git diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index afbf226..ab25290 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -35,6 +35,7 @@ #include "AdapterCommunication.h" #include "AdapterDetection.h" #include "CECProcessor.h" +#include "devices/CECBusDevice.h" #include "util/StdString.h" #include "platform/timeutils.h" @@ -78,7 +79,17 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */) return false; } - if (!m_comm->Open(strPort, 38400, iTimeoutMs)) + int64_t iNow = GetTimeMs(); + int64_t iTarget = iNow + iTimeoutMs; + + bool bOpened(false); + while (!bOpened && iNow < iTarget) + { + bOpened = m_comm->Open(strPort, 38400, iTimeoutMs); + iNow = GetTimeMs(); + } + + if (!bOpened) { AddLog(CEC_LOG_ERROR, "could not open a connection"); return false; @@ -158,14 +169,19 @@ bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress) return m_cec ? m_cec->SetLogicalAddress(iLogicalAddress) : false; } +bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress) +{ + return m_cec ? m_cec->SetPhysicalAddress(iPhysicalAddress) : false; +} + bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) { - return m_cec ? m_cec->PowerOnDevices(address) : false; + return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->PowerOn() : false; } bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) { - return m_cec ? m_cec->StandbyDevices(address) : false; + return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)address]->Standby() : false; } bool CLibCEC::SetActiveView(void) @@ -178,6 +194,16 @@ bool CLibCEC::SetInactiveView(void) return m_cec ? m_cec->SetInactiveView() : false; } +bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) +{ + return m_cec && iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST ? m_cec->m_busDevices[(uint8_t)iLogicalAddress]->SetOSDString(duration, strMessage) : false; +} + +bool CLibCEC::SwitchMonitoring(bool bEnable) +{ + return m_cec ? m_cec->SwitchMonitoring(bEnable) : false; +} + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) @@ -204,7 +230,7 @@ void CLibCEC::AddKey(void) } } -void CLibCEC::AddCommand(cec_command &command) +void CLibCEC::AddCommand(const cec_command &command) { if (m_commandBuffer.Push(command)) { @@ -231,6 +257,13 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode) { m_iCurrentButton = iButtonCode; m_buttontime = GetTimeMs(); + + /* push keypress to the keybuffer with 0 duration. + push another press to the keybuffer with the duration set when the button is released */ + cec_keypress key; + key.duration = 0; + key.keycode = m_iCurrentButton; + m_keyBuffer.Push(key); } void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)