InputCEC.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. InputCEC(QObject* parent);
  16. virtual const char* inputName()
  17. { return CEC_INPUT_NAME; }
  18. virtual bool initInput();
  19. private:
  20. QThread* m_cecThread;
  21. InputCECWorker* m_cecWorker;
  22. };
  23. /////////////////////////////////////////////////////////////////////////////////////////
  24. class InputCECWorker : public QObject
  25. {
  26. Q_OBJECT
  27. public:
  28. InputCECWorker(QObject* parent = 0) : QObject(parent), m_adapter(0), m_adapterPort("")
  29. {
  30. }
  31. ~InputCECWorker();
  32. Q_SLOT bool init();
  33. Q_SIGNAL void receivedInput(const QString& source, const QString& keycode, float amount);
  34. public slots:
  35. void checkAdapter();
  36. private:
  37. void closeCec();
  38. bool openAdapter();
  39. void closeAdapter();
  40. QString getCommandString(cec_user_control_code code, unsigned int duration);
  41. void sendReceivedInput(const QString& source, const QString& keycode, float amount = 1.0);
  42. QString getCommandParamsList(cec_command command);
  43. // libcec callbacks
  44. static int CecLogMessage(void* cbParam, const cec_log_message message);
  45. static int CecKeyPress(void* cbParam, const cec_keypress key);
  46. static int CecCommand(void* cbParam, const cec_command command);
  47. static int CecAlert(void* cbParam, const libcec_alert type, const libcec_parameter param);
  48. libcec_configuration m_configuration;
  49. ICECCallbacks m_callbacks;
  50. ICECAdapter* m_adapter;
  51. QString m_adapterPort;
  52. QTimer* m_timer;
  53. bool m_verboseLogging;
  54. };
  55. #endif // INPUTCEC_H