InputCEC.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef INPUTCEC_H
  2. #define INPUTCEC_H
  3. #include <QMutex>
  4. #include <QTimer>
  5. #include "input/InputComponent.h"
  6. #include <libcec/cec.h>
  7. using namespace CEC;
  8. #define CEC_LONGPRESS_DURATION 1000 // duration after keypress is considerered as long
  9. #define CEC_INPUT_NAME "CEC"
  10. class InputCECWorker;
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////
  12. class InputCEC : public InputBase
  13. {
  14. public:
  15. explicit InputCEC(QObject* parent);
  16. ~InputCEC();
  17. const char* inputName() override { return CEC_INPUT_NAME; }
  18. bool initInput() override;
  19. private:
  20. QThread* m_cecThread;
  21. InputCECWorker* m_cecWorker;
  22. };
  23. /////////////////////////////////////////////////////////////////////////////////////////
  24. class InputCECWorker : public QObject
  25. {
  26. Q_OBJECT
  27. public:
  28. explicit InputCECWorker(QObject* parent = nullptr) : QObject(parent), m_adapter(nullptr), m_adapterPort("")
  29. {
  30. }
  31. Q_SLOT bool init();
  32. Q_SIGNAL void receivedInput(const QString& source, const QString& keycode, InputBase::InputkeyState keyState);
  33. Q_SLOT void closeCec();
  34. public slots:
  35. void checkAdapter();
  36. private:
  37. bool openAdapter();
  38. void closeAdapter();
  39. QString getCommandString(cec_user_control_code code);
  40. void sendReceivedInput(const QString& source, const QString& keycode, InputBase::InputkeyState keyState);
  41. QString getCommandParamsList(const cec_command *command);
  42. // libcec callbacks
  43. static void CecLogMessage(void* cbParam, const cec_log_message *message);
  44. static void CecCommand(void* cbParam, const cec_command *command);
  45. static void CecAlert(void* cbParam, const libcec_alert type, const libcec_parameter param);
  46. libcec_configuration m_configuration;
  47. ICECCallbacks m_callbacks;
  48. ICECAdapter* m_adapter;
  49. QString m_adapterPort;
  50. QTimer* m_timer;
  51. bool m_verboseLogging;
  52. };
  53. #endif // INPUTCEC_H