InputCEC.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. const char* inputName() override { return CEC_INPUT_NAME; }
  17. bool initInput() override;
  18. private:
  19. QThread* m_cecThread;
  20. InputCECWorker* m_cecWorker;
  21. };
  22. /////////////////////////////////////////////////////////////////////////////////////////
  23. class InputCECWorker : public QObject
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit InputCECWorker(QObject* parent = nullptr) : QObject(parent), m_adapter(nullptr), m_adapterPort("")
  28. {
  29. }
  30. ~InputCECWorker() override;
  31. Q_SLOT bool init();
  32. Q_SIGNAL void receivedInput(const QString& source, const QString& keycode, InputBase::InputkeyState keyState);
  33. public slots:
  34. void checkAdapter();
  35. private:
  36. void closeCec();
  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(cec_command command);
  42. // libcec callbacks
  43. static int CecLogMessage(void* cbParam, const cec_log_message message);
  44. static int CecCommand(void* cbParam, const cec_command command);
  45. static int 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