Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

[RFC] InputCEC activateSource on receivedInput #1076

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/input/InputCEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ bool InputCEC::initInput()
return retVal;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
void InputCEC::activateSource()
{
QMetaObject::invokeMethod(m_cecWorker, "activateSource", Qt::QueuedConnection);
}

/////////////////////////////////////////////////////////////////////////////////////////
InputCEC::~InputCEC()
{
Expand Down Expand Up @@ -118,6 +124,9 @@ bool InputCECWorker::init()
// check for attached adapters
checkAdapter();

// if necessary, wake device(s)
activateSource();

// Start a timer to keep track of attached/removed adapters
m_timer = new QTimer(nullptr);
m_timer->setInterval(10 * 1000);
Expand Down Expand Up @@ -184,14 +193,28 @@ void InputCECWorker::closeAdapter()
void InputCECWorker::checkAdapter()
{
if (m_adapterPort.isEmpty())
{
{
if (m_adapter)
m_adapter->Close();

openAdapter();
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
void InputCECWorker::activateSource()
{
if (!SettingsComponent::Get().value(SETTINGS_SECTION_CEC, "activatesource").toBool())
{
return;
}

// Check if a tv has powered on
QLOG_INFO() << "CEC activateSource changing input";
m_adapter->SetActiveSource();

}

///////////////////////////////////////////////////////////////////////////////////////////////////
void InputCECWorker::sendReceivedInput(const QString &source, const QString &keycode, InputBase::InputkeyState keyState)
{
Expand Down
5 changes: 5 additions & 0 deletions src/input/InputCEC.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ class InputCECWorker;
///////////////////////////////////////////////////////////////////////////////////////////////////
class InputCEC : public InputBase
{
Q_OBJECT

public:
explicit InputCEC(QObject* parent);
~InputCEC();

const char* inputName() override { return CEC_INPUT_NAME; }
bool initInput() override;

public slots:
void activateSource();

private:
QThread* m_cecThread;
Expand All @@ -42,6 +46,7 @@ Q_OBJECT
Q_SLOT bool init();
Q_SIGNAL void receivedInput(const QString& source, const QString& keycode, InputBase::InputkeyState keyState);
Q_SLOT void closeCec();
Q_SLOT void activateSource();

public slots:
void checkAdapter();
Expand Down
7 changes: 6 additions & 1 deletion src/input/InputComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ bool InputComponent::componentInitialize()
#endif
#ifdef HAVE_CEC
if (SettingsComponent::Get().value(SETTINGS_SECTION_CEC, "enable").toBool())
addInput(new InputCEC(this));
{
InputCEC* cec = new InputCEC(this);
addInput(cec);
connect(&InputKeyboard::Get(), &InputKeyboard::receivedInput,
cec, &InputCEC::activateSource);
}
#endif

return true;
Expand Down