2020-07-20 20:06:41 +02:00
|
|
|
#include <cec/CECHandler.h>
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <libcec/cecloader.h>
|
2023-11-27 09:06:43 +01:00
|
|
|
#include <events/EventHandler.h>
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonDocument>
|
2023-12-03 21:23:31 +01:00
|
|
|
#include <QJsonDocument>
|
2020-07-20 20:06:41 +02:00
|
|
|
#include <QJsonObject>
|
mDNS Support (#1452)
* Allow build, if no grabbers are enabled
* Align available functions to right Qt version
* Update to next development version
* Align available functions to right Qt version
* fix workflows (apt/nightly)
* Disable QNetworkConfigurationManager deprecation warnings
* Initial go on Smart Pointers
* Add Deallocation
* Correct QT_WARNING_DISABLE_DEPRECATED (available since 5.9)
* Cluster Build Variables
* Hyperion Light
* Address build warnings
* Hyperion Light - UI
* Update Protobuf to latest master
* Removed compiler warnings
* Added restart ability to systray
* Correct Protobuf
* Ignore 'no-return' warning on protobuf build
* hyperion-remote: Fix auto discovery of hyperion server
* Fix Qt version override
* Update changelog
* Remove Grabber Components, if no Grabber exists
* Standalone Grabber - Fix fps default
* Remote Control - Have Source Selction accrosswhole screen
* Enable Blackborder detection only, if relevant input sources available
* Enable Blackborder detection only, if relevant input sources available
* Remote UI - rearrange containers
* Checkout
* Fix compilation on windows
* Re-added qmdnsengine template cmake
* chrono added for linux
* Removed existing AVAHI/Bonjour, allow to enable/disable mDNS
* hyperiond macos typo fix
* Fix macOS Bundle build
* Fix macOS bundle info details
* Correct CMake files
* Removed existing AVAHI/Bonjour (2)
* Share hyperion's services via mDNS
* Add mDNS Browser and mDNS for LED-Devices
* Support mDNS discovery for standalone grabbers
* Remove ZLib Dependency & Cleanup
* mDNS - hanle 2.local2 an ".local." domains equally
* Hue - Link discovery to bridge class, workaround port 443 for mDNS discovery
* Fix save button state when switching between devices
* Removed sessions (of other hyperions)
* mDNS Publisher - Simplify service naming
* mDNS refactoring & Forwarder discovery
* mDNS Updates to use device service name
* Consistency of standalone grabbers with mDNS Service Registry
* Merge branch 'hyperion-project:master' into mDNS
* Start JSON and WebServers only after Instance 0 is available
* Remove bespoke qDebug Output again
* MDNS updates and refactor Forwarder
* Minor updates
* Upgrade to CMake 3.1
* typo
* macOS fix
* Correct merge
* - Remove dynamic linker flag from standalone dispmanX Grabber
- Added ability to use system qmdns libs
* Cec handler library will load at runtime
* typo fix
* protobuf changes
* mDNS changes for Windows/macOS
* test window build qmdnsengine
* absolute path to protobuf cmake dir
* Rework Hue Wizard supporting mDNS
* LED-Devices - Retry support + Refactoring (excl. Hue)
* LED-Devices - Refactoring/Retry support Hue + additional alignments
* Address LGTM findings
* Fix CI-Build, revert test changes
* Build Windows in Release mode to avoid python problem
* Correct that WebServerObject is available earlier
* Ensure that instance name in logs for one instance are presented
* Update content LEDs
* Rework mDNS Address lookup
* Fix LED UI
* Fix for non mDNS Services (ignore default port)
* Disbale device when now input is available
* Revert back some updates, ensure last color is updated when switched on
* Handle reopening case and changed IP, port for API-calls
* Add UPD-DDP Device
* WLED support for DDP
* Fix printout
* LEDDevice - Allow more retries, udapte defaults
* LED-Net Devices - Select Custom device, if configured
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
Co-authored-by: Paulchen Panther <Paulchen-Panter@protonmail.com>
2022-05-01 19:42:47 +02:00
|
|
|
#include <QFile>
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
/* Enable to turn on detailed CEC logs */
|
2023-11-27 09:06:43 +01:00
|
|
|
#define NOVERBOSE_CEC
|
|
|
|
|
|
|
|
CECHandler::CECHandler(const QJsonDocument& config, QObject * parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, _config(config)
|
|
|
|
, _isInitialised(false)
|
2023-12-03 21:23:31 +01:00
|
|
|
, _isOpen(false)
|
2023-11-27 09:06:43 +01:00
|
|
|
, _isEnabled(false)
|
|
|
|
, _buttonReleaseDelayMs(CEC_BUTTON_TIMEOUT)
|
|
|
|
, _buttonRepeatRateMs(0)
|
|
|
|
, _doubleTapTimeoutMs(CEC_DOUBLE_TAP_TIMEOUT_MS)
|
|
|
|
, _cecEventActionMap()
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
qRegisterMetaType<Event>("Event");
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
_logger = Logger::getInstance("EVENTS-CEC");
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
_cecCallbacks = getCallbacks();
|
|
|
|
_cecConfig = getConfig();
|
|
|
|
_cecConfig.callbacks = &_cecCallbacks;
|
|
|
|
_cecConfig.callbackParam = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CECHandler::~CECHandler()
|
|
|
|
{
|
2024-02-25 17:35:39 +01:00
|
|
|
Info(_logger, "CEC handler stopped");
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
void CECHandler::handleSettingsUpdate(settings::type type, const QJsonDocument& config)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if(type == settings::CECEVENTS)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (_isInitialised)
|
|
|
|
{
|
|
|
|
const QJsonObject& obj = config.object();
|
|
|
|
|
|
|
|
_isEnabled = obj["enable"].toBool(false);
|
|
|
|
Debug(_logger, "CEC Event handling is %s", _isEnabled? "enabled" : "disabled");
|
|
|
|
|
|
|
|
if (_isEnabled)
|
|
|
|
{
|
|
|
|
_buttonReleaseDelayMs = obj["buttonReleaseDelayMs"].toInt(CEC_BUTTON_TIMEOUT);
|
|
|
|
_buttonRepeatRateMs = obj["buttonRepeatRateMs"].toInt(0);
|
|
|
|
_doubleTapTimeoutMs = obj["doubleTapTimeoutMs"].toInt(CEC_DOUBLE_TAP_TIMEOUT_MS);
|
|
|
|
|
|
|
|
Debug(_logger, "Remote button press release time : %dms",_buttonReleaseDelayMs);
|
|
|
|
Debug(_logger, "Remote button press repeat rate : %dms",_buttonRepeatRateMs);
|
|
|
|
Debug(_logger, "Remote button press delay before repeating : %dms",_doubleTapTimeoutMs);
|
|
|
|
|
|
|
|
_cecConfig.iButtonReleaseDelayMs = static_cast<uint32_t>(_buttonReleaseDelayMs);
|
|
|
|
_cecConfig.iButtonRepeatRateMs = static_cast<uint32_t>(_buttonRepeatRateMs);
|
|
|
|
_cecConfig.iDoubleTapTimeoutMs = static_cast<uint32_t>(_doubleTapTimeoutMs);
|
|
|
|
|
|
|
|
_cecEventActionMap.clear();
|
|
|
|
const QJsonArray actionItems = obj["actions"].toArray();
|
|
|
|
if (!actionItems.isEmpty())
|
|
|
|
{
|
|
|
|
for (const QJsonValue &item : actionItems)
|
|
|
|
{
|
|
|
|
QString cecEvent = item.toObject().value("event").toString();
|
|
|
|
QString action = item.toObject().value("action").toString();
|
|
|
|
_cecEventActionMap.insert(cecEvent, stringToEvent(action));
|
|
|
|
Debug(_logger, "CEC-Event : \"%s\" linked to action \"%s\"", QSTRING_CSTR(cecEvent), QSTRING_CSTR(action));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_cecEventActionMap.isEmpty())
|
|
|
|
{
|
|
|
|
enable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Warning(_logger, "No CEC events to listen to are configured currently.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
disable();
|
|
|
|
}
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
2023-11-27 09:06:43 +01:00
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
bool CECHandler::start()
|
|
|
|
{
|
|
|
|
_isInitialised = false;
|
|
|
|
if (_cecAdapter == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
_cecAdapter = LibCecInitialise(&_cecConfig);
|
|
|
|
if(_cecAdapter == nullptr)
|
|
|
|
{
|
|
|
|
Error(_logger, "Failed loading libCEC library. CEC is not supported.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isInitialised = true;
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
handleSettingsUpdate(settings::CECEVENTS,_config);
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
2023-11-27 09:06:43 +01:00
|
|
|
return _isInitialised;
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
void CECHandler::stop()
|
|
|
|
{
|
|
|
|
if (_cecAdapter != nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
Info(_logger, "Stopping CEC handler");
|
|
|
|
_cecAdapter->Close();
|
|
|
|
UnloadLibCec(_cecAdapter);
|
|
|
|
}
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
bool CECHandler::enable()
|
|
|
|
{
|
|
|
|
if (_isInitialised)
|
|
|
|
{
|
2023-12-03 21:23:31 +01:00
|
|
|
if (!_isOpen)
|
2023-11-27 09:06:43 +01:00
|
|
|
{
|
2023-12-03 21:23:31 +01:00
|
|
|
const auto adapters = getAdapters();
|
|
|
|
if (adapters.isEmpty())
|
|
|
|
{
|
|
|
|
Error(_logger, "Failed to find any CEC adapter. CEC event handling will be disabled.");
|
|
|
|
_cecAdapter->Close();
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-27 09:06:43 +01:00
|
|
|
|
2023-12-03 21:23:31 +01:00
|
|
|
Info(_logger, "Auto detecting CEC adapter");
|
|
|
|
bool opened {false};
|
|
|
|
for (const auto & adapter : adapters)
|
2023-11-27 09:06:43 +01:00
|
|
|
{
|
2023-12-03 21:23:31 +01:00
|
|
|
printAdapter(adapter);
|
|
|
|
if (!opened)
|
|
|
|
{
|
|
|
|
if (openAdapter(adapter))
|
|
|
|
{
|
|
|
|
|
|
|
|
Info(_logger, "CEC adapter '%s', type: %s initialized." , adapter.strComName, _cecAdapter->ToString(adapter.adapterType));
|
|
|
|
opened = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-11-27 09:06:43 +01:00
|
|
|
}
|
|
|
|
|
2023-12-03 21:23:31 +01:00
|
|
|
if (!opened)
|
|
|
|
{
|
|
|
|
Error(_logger, "Could not initialize any CEC adapter.");
|
|
|
|
_cecAdapter->Close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isOpen=true;
|
2024-02-25 17:35:39 +01:00
|
|
|
QObject::connect(this, &CECHandler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent);
|
2023-11-27 09:06:43 +01:00
|
|
|
#ifdef VERBOSE_CEC
|
2023-12-03 21:23:31 +01:00
|
|
|
std::cout << "Found Devices: " << scan().toStdString() << std::endl;
|
2023-11-27 09:06:43 +01:00
|
|
|
#endif
|
2023-12-03 21:23:31 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
2023-12-03 21:23:31 +01:00
|
|
|
if (_isOpen && !_cecAdapter->SetConfiguration(&_cecConfig))
|
2023-11-27 09:06:43 +01:00
|
|
|
{
|
|
|
|
Error(_logger, "Failed setting remote button press timing parameters");
|
|
|
|
}
|
2023-12-03 21:23:31 +01:00
|
|
|
|
|
|
|
Info(_logger, "CEC handler enabled");
|
|
|
|
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
|
2023-12-03 21:23:31 +01:00
|
|
|
return _isOpen;
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
void CECHandler::disable()
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (_isInitialised)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2024-02-25 17:35:39 +01:00
|
|
|
QObject::disconnect(this, &CECHandler::signalEvent, EventHandler::getInstance().data(), &EventHandler::handleEvent);
|
2020-07-20 20:06:41 +02:00
|
|
|
_cecAdapter->Close();
|
2023-12-03 21:23:31 +01:00
|
|
|
_isOpen=false;
|
|
|
|
Info(_logger, "CEC handler disabled");
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CECConfig CECHandler::getConfig() const
|
|
|
|
{
|
|
|
|
CECConfig configuration;
|
|
|
|
|
|
|
|
const std::string name("HyperionCEC");
|
|
|
|
name.copy(configuration.strDeviceName, std::min(name.size(), sizeof(configuration.strDeviceName)));
|
|
|
|
configuration.deviceTypes.Add(CEC::CEC_DEVICE_TYPE_RECORDING_DEVICE);
|
|
|
|
configuration.clientVersion = CEC::LIBCEC_VERSION_CURRENT;
|
|
|
|
|
|
|
|
return configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
CECCallbacks CECHandler::getCallbacks() const
|
|
|
|
{
|
|
|
|
CECCallbacks callbacks;
|
|
|
|
|
|
|
|
callbacks.sourceActivated = onCecSourceActivated;
|
|
|
|
callbacks.commandReceived = onCecCommandReceived;
|
|
|
|
callbacks.alert = onCecAlert;
|
|
|
|
callbacks.logMessage = onCecLogMessage;
|
|
|
|
callbacks.keyPress = onCecKeyPress;
|
|
|
|
callbacks.configurationChanged = onCecConfigurationChanged;
|
|
|
|
callbacks.menuStateChanged = onCecMenuStateChanged;
|
|
|
|
|
|
|
|
return callbacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<CECAdapterDescriptor> CECHandler::getAdapters() const
|
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (_cecAdapter == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return {};
|
|
|
|
|
|
|
|
QVector<CECAdapterDescriptor> descriptors(16);
|
2023-11-27 09:06:43 +01:00
|
|
|
int8_t size = _cecAdapter->DetectAdapters(descriptors.data(), static_cast<uint8_t>(descriptors.size()), nullptr, true /*quickscan*/);
|
2020-07-20 20:06:41 +02:00
|
|
|
descriptors.resize(size);
|
|
|
|
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CECHandler::openAdapter(const CECAdapterDescriptor & descriptor)
|
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (_cecAdapter == nullptr)
|
2023-12-03 21:23:31 +01:00
|
|
|
{
|
2020-07-20 20:06:41 +02:00
|
|
|
return false;
|
2023-12-03 21:23:31 +01:00
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
if(!_cecAdapter->Open(descriptor.strComName))
|
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
Error(_logger, "CEC adapter '%s', type: %s failed to open.", descriptor.strComName, _cecAdapter->ToString(descriptor.adapterType));
|
2020-07-20 20:06:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CECHandler::printAdapter(const CECAdapterDescriptor & descriptor) const
|
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(_logger, "CEC Adapter:");
|
|
|
|
Debug(_logger, "\tName : %s", descriptor.strComName);
|
|
|
|
Debug(_logger, "\tPath : %s", descriptor.strComPath);
|
|
|
|
if (descriptor.iVendorId != 0)
|
|
|
|
{
|
|
|
|
Debug(_logger, "\tVendor id: %04x", descriptor.iVendorId);
|
|
|
|
}
|
|
|
|
if (descriptor.iProductId != 0)
|
|
|
|
{
|
|
|
|
Debug(_logger, "\tProduct id: %04x", descriptor.iProductId);
|
|
|
|
}
|
|
|
|
if (descriptor.iFirmwareVersion != 0)
|
|
|
|
{
|
|
|
|
Debug(_logger, "\tFirmware id: %d", descriptor.iFirmwareVersion);
|
|
|
|
}
|
|
|
|
if (descriptor.adapterType != CEC::ADAPTERTYPE_UNKNOWN)
|
|
|
|
{
|
|
|
|
Debug(_logger, "\tType : %s", _cecAdapter->ToString(descriptor.adapterType));
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CECHandler::scan() const
|
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (_cecAdapter == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return {};
|
|
|
|
|
|
|
|
Info(_logger, "Starting CEC scan");
|
|
|
|
|
|
|
|
QJsonArray devices;
|
|
|
|
CECLogicalAddresses addresses = _cecAdapter->GetActiveDevices();
|
2023-11-27 09:06:43 +01:00
|
|
|
for (uint8_t address = CEC::CECDEVICE_TV; address <= CEC::CECDEVICE_BROADCAST; ++address)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
if (addresses[address] != 0)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
CECLogicalAddress logicalAddress = static_cast<CECLogicalAddress>(address);
|
2020-07-20 20:06:41 +02:00
|
|
|
|
|
|
|
QJsonObject device;
|
2023-11-27 09:06:43 +01:00
|
|
|
CECVendorId vendor = static_cast<CECVendorId>(_cecAdapter->GetDeviceVendorId(logicalAddress));
|
2020-07-20 20:06:41 +02:00
|
|
|
CECPowerStatus power = _cecAdapter->GetDevicePowerStatus(logicalAddress);
|
|
|
|
|
|
|
|
device["name" ] = _cecAdapter->GetDeviceOSDName(logicalAddress).c_str();
|
|
|
|
device["vendor" ] = _cecAdapter->ToString(vendor);
|
|
|
|
device["address" ] = _cecAdapter->ToString(logicalAddress);
|
|
|
|
device["power" ] = _cecAdapter->ToString(power);
|
|
|
|
|
|
|
|
devices << device;
|
|
|
|
|
2022-12-27 08:36:10 +01:00
|
|
|
Info(_logger, "%s", QSTRING_CSTR(QString("\tCECDevice: %1 / %2 / %3 / %4")
|
2023-11-27 09:06:43 +01:00
|
|
|
.arg(device["name"].toString(),
|
|
|
|
device["vendor"].toString(),
|
|
|
|
device["address"].toString(),
|
|
|
|
device["power"].toString())
|
|
|
|
)
|
|
|
|
);
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QJsonDocument(devices).toJson(QJsonDocument::Compact);
|
|
|
|
}
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
void CECHandler::triggerAction(const QString& cecEvent)
|
|
|
|
{
|
|
|
|
Event action = _cecEventActionMap.value(cecEvent, Event::Unknown);
|
|
|
|
if ( action != Event::Unknown )
|
|
|
|
{
|
2023-12-03 21:23:31 +01:00
|
|
|
Debug(_logger, "CEC-Event : \"%s\" triggers action \"%s\"", QSTRING_CSTR(cecEvent), eventToString(action) );
|
2023-11-27 09:06:43 +01:00
|
|
|
emit signalEvent(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-20 20:06:41 +02:00
|
|
|
void CECHandler::onCecLogMessage(void * context, const CECLogMessage * message)
|
|
|
|
{
|
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
2023-11-27 09:06:43 +01:00
|
|
|
if (handler == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch (message->level)
|
|
|
|
{
|
|
|
|
case CEC::CEC_LOG_ERROR:
|
2023-11-27 09:06:43 +01:00
|
|
|
Error(handler->_logger, "%s", message->message);
|
2020-07-20 20:06:41 +02:00
|
|
|
break;
|
|
|
|
case CEC::CEC_LOG_WARNING:
|
2023-11-27 09:06:43 +01:00
|
|
|
Warning(handler->_logger, "%s", message->message);
|
2020-07-20 20:06:41 +02:00
|
|
|
break;
|
|
|
|
case CEC::CEC_LOG_TRAFFIC:
|
|
|
|
case CEC::CEC_LOG_NOTICE:
|
2023-11-27 09:06:43 +01:00
|
|
|
Info(handler->_logger, "%s", message->message);
|
2020-07-20 20:06:41 +02:00
|
|
|
break;
|
|
|
|
case CEC::CEC_LOG_DEBUG:
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(handler->_logger, "%s", message->message);
|
2020-07-20 20:06:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CECHandler::onCecKeyPress(void * context, const CECKeyPress * key)
|
|
|
|
{
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
2023-11-27 09:06:43 +01:00
|
|
|
if (handler == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
CECAdapter * adapter = handler->_cecAdapter;
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
Debug(handler->_logger, "CECHandler::onCecKeyPress: %s", adapter->ToString(key->keycode));
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
2023-11-27 09:06:43 +01:00
|
|
|
switch (key->keycode) {
|
|
|
|
case CEC::CEC_USER_CONTROL_CODE_F1_BLUE:
|
|
|
|
case CEC::CEC_USER_CONTROL_CODE_F2_RED:
|
|
|
|
case CEC::CEC_USER_CONTROL_CODE_F3_GREEN:
|
|
|
|
case CEC::CEC_USER_CONTROL_CODE_F4_YELLOW:
|
|
|
|
handler->triggerAction(adapter->ToString(key->keycode));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
void CECHandler::onCecAlert(void * context, const CECAlert alert, const CECParameter /* data */)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
2023-11-27 09:06:43 +01:00
|
|
|
if (handler == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return;
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
Error(handler->_logger, QSTRING_CSTR(QString("CECHandler::onCecAlert: %1")
|
|
|
|
.arg(alert)));
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CECHandler::onCecConfigurationChanged(void * context, const CECConfig * configuration)
|
|
|
|
{
|
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
2023-11-27 09:06:43 +01:00
|
|
|
if (handler == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return;
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(handler->_logger, "CECHandler::onCecConfigurationChanged: %s", configuration->strDeviceName);
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int CECHandler::onCecMenuStateChanged(void * context, const CECMenuState state)
|
|
|
|
{
|
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
|
|
|
if (!handler)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
CECAdapter * adapter = handler->_cecAdapter;
|
|
|
|
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(handler->_logger, "CECHandler::onCecMenuStateChanged: %s", adapter->ToString(state));
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CECHandler::onCecCommandReceived(void * context, const CECCommand * command)
|
|
|
|
{
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
|
|
|
if (!handler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CECAdapter * adapter = handler->_cecAdapter;
|
|
|
|
|
|
|
|
#ifdef VERBOSE_CEC
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(handler->_logger, "CECHandler::onCecCommandReceived: %s %s > %s)",
|
|
|
|
adapter->ToString(command->opcode),
|
|
|
|
adapter->ToString(command->initiator),
|
|
|
|
adapter->ToString(command->destination)
|
|
|
|
);
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
|
|
|
/* We do NOT check sender */
|
2023-11-27 09:06:43 +01:00
|
|
|
//if (address == CEC::CECDEVICE_TV)
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
switch (command->opcode) {
|
|
|
|
case CEC::CEC_OPCODE_STANDBY:
|
|
|
|
case CEC::CEC_OPCODE_SET_STREAM_PATH:
|
2020-07-20 20:06:41 +02:00
|
|
|
{
|
2023-11-27 09:06:43 +01:00
|
|
|
handler->triggerAction(adapter->ToString(command->opcode));
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
2023-11-27 09:06:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2020-07-20 20:06:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CECHandler::onCecSourceActivated(void * context, const CECLogicalAddress address, const uint8_t activated)
|
|
|
|
{
|
|
|
|
/* We use CECHandler::onCecCommandReceived for
|
|
|
|
* source activated/deactivated notifications. */
|
|
|
|
|
|
|
|
#ifdef VERBOSE_CEC
|
|
|
|
CECHandler * handler = qobject_cast<CECHandler*>(static_cast<QObject*>(context));
|
2023-11-27 09:06:43 +01:00
|
|
|
if (handler == nullptr)
|
2020-07-20 20:06:41 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
CECAdapter * adapter = handler->_cecAdapter;
|
2023-11-27 09:06:43 +01:00
|
|
|
Debug(handler->_logger, QSTRING_CSTR(QString("CEC source %1 : %2")
|
|
|
|
.arg(activated ? "activated" : "deactivated",
|
|
|
|
adapter->ToString(address))
|
|
|
|
));
|
2020-07-20 20:06:41 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|