File indexing completed on 2024-05-12 05:27:54
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Bart Ribbers <bribbers@disroot.org> 0003 * SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include <QDebug> 0011 #include <QObject> 0012 0013 #include <libcec/cec.h> 0014 0015 #define LOOPTIME 50 * 1000 0016 0017 using namespace CEC; 0018 0019 class CECController : public QObject 0020 { 0021 Q_OBJECT 0022 Q_CLASSINFO("D-Bus Interface", "org.kde.plasma.remotecontrollers.CEC") 0023 0024 public: 0025 explicit CECController(); 0026 ~CECController() override; 0027 0028 void discoverDevices(); 0029 0030 public Q_SLOTS: 0031 Q_SCRIPTABLE int sendNextKey(); 0032 Q_SCRIPTABLE bool hdmiCecSupported(); 0033 Q_SCRIPTABLE bool sendKey(uchar, CEC::cec_logical_address address = CECDEVICE_TV); 0034 Q_SCRIPTABLE bool powerOnDevices(CEC::cec_logical_address address = CECDEVICE_TV); 0035 Q_SCRIPTABLE bool powerOffDevices(CEC::cec_logical_address address = CECDEVICE_BROADCAST); 0036 Q_SCRIPTABLE bool makeActiveSource(); 0037 Q_SCRIPTABLE bool setOSDName(const QString&); 0038 0039 Q_SIGNALS: 0040 Q_SCRIPTABLE void enterStandby(); 0041 Q_SCRIPTABLE bool sourceActivated(bool active); 0042 0043 private: 0044 ICECAdapter* m_cecAdapter = nullptr; 0045 ICECCallbacks m_cecCallbacks; 0046 static QHash<int, int> m_keyCodeTranslation; 0047 0048 static bool m_catchNextInput; 0049 static int m_caughtInput; 0050 static bool m_nativeNavMode; 0051 0052 static void handleCecKeypress(void* param, const cec_keypress* key); 0053 static void handleCommandReceived(void* param, const cec_command* command); 0054 static void handleSourceActivated(void* param, const cec_logical_address address, uint8_t activated); 0055 0056 static int m_hitcommand; 0057 0058 static void handleCompleteEvent(const int keycode, const int keyduration, const int opcode); 0059 }; 0060 0061 Q_DECLARE_METATYPE(CEC::cec_logical_address);