irda_worker.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include <irda.h>
  3. #include <api-hal.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Interface struct of irda worker */
  8. typedef struct IrdaWorker IrdaWorker;
  9. /** Interface struct of received signal */
  10. typedef struct IrdaWorkerSignal IrdaWorkerSignal;
  11. /** Callback type to call by IrdaWorker thread when new signal is received */
  12. typedef void (*IrdaWorkerReceivedSignalCallback)(void* context, IrdaWorkerSignal* received_signal);
  13. /** Allocate IrdaWorker
  14. *
  15. * @return just created instance of IrdaWorker
  16. */
  17. IrdaWorker* irda_worker_alloc();
  18. /** Free IrdaWorker
  19. *
  20. * @param[in] instance - IrdaWorker instance
  21. */
  22. void irda_worker_free(IrdaWorker* instance);
  23. /** Received data callback IrdaWorker
  24. *
  25. * @param[in] instance - IrdaWorker instance
  26. * @param[in] callback - IrdaWorkerReceivedSignalCallback callback
  27. */
  28. void irda_worker_set_received_signal_callback(IrdaWorker* instance, IrdaWorkerReceivedSignalCallback callback);
  29. /** Context callback IrdaWorker
  30. *
  31. * @param[in] instance - IrdaWorker instance
  32. * @param[in] context - context to pass to callbacks
  33. */
  34. void irda_worker_set_context(IrdaWorker* instance, void* context);
  35. /** Start IrdaWorker thread, initialise api-hal, prepare all work.
  36. *
  37. * @param[in] instance - IrdaWorker instance
  38. */
  39. void irda_worker_start(IrdaWorker* instance);
  40. /** Stop IrdaWorker thread, deinitialize api-hal.
  41. *
  42. * @param[in] instance - IrdaWorker instance
  43. */
  44. void irda_worker_stop(IrdaWorker* instance);
  45. /** Clarify is received signal either decoded or raw
  46. *
  47. * @param[in] signal - received signal
  48. * @return true if signal is decoded, false if signal is raw
  49. */
  50. bool irda_worker_signal_is_decoded(const IrdaWorkerSignal* signal);
  51. /** Acquire raw signal from interface struct 'IrdaWorkerSignal'.
  52. * First, you have to ensure that signal is raw.
  53. *
  54. * @param[in] signal - received signal
  55. * @param[out] timings - pointer to array of timings
  56. * @param[out] timings_cnt - pointer to amount of timings
  57. */
  58. void irda_worker_get_raw_signal(const IrdaWorkerSignal* signal, const uint32_t** timings, size_t* timings_cnt);
  59. /** Acquire decoded message from interface struct 'IrdaWorkerSignal'.
  60. * First, you have to ensure that signal is decoded.
  61. *
  62. * @param[in] signal - received signal
  63. * @return decoded irda message
  64. */
  65. const IrdaMessage* irda_worker_get_decoded_message(const IrdaWorkerSignal* signal);
  66. /** Enable blinking on receiving any signal on IR port.
  67. *
  68. * @param[in] instance - instance of IrdaWorker
  69. * @param[in] enable - true if you want to enable blinking
  70. * false otherwise
  71. */
  72. void irda_worker_enable_blink_on_receiving(IrdaWorker* instance, bool enable);
  73. #ifdef __cplusplus
  74. }
  75. #endif