irda_worker.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #pragma once
  2. #include <irda.h>
  3. #include <furi_hal.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define MAX_TIMINGS_AMOUNT 512
  8. /** Interface struct of irda worker */
  9. typedef struct IrdaWorker IrdaWorker;
  10. /** Interface struct of received signal */
  11. typedef struct IrdaWorkerSignal IrdaWorkerSignal;
  12. typedef enum {
  13. IrdaWorkerGetSignalResponseNew, /** Signal, provided by callback is new and encoder should be reseted */
  14. IrdaWorkerGetSignalResponseSame, /** Signal, provided by callback is same. No encoder resetting. */
  15. IrdaWorkerGetSignalResponseStop, /** No more signals available. */
  16. } IrdaWorkerGetSignalResponse;
  17. /** Callback type for providing next signal to send. Should be used with
  18. * irda_worker_make_decoded_signal() or irda_worker_make_raw_signal()
  19. */
  20. typedef IrdaWorkerGetSignalResponse (
  21. *IrdaWorkerGetSignalCallback)(void* context, IrdaWorker* instance);
  22. /** Callback type for 'message is sent' event */
  23. typedef void (*IrdaWorkerMessageSentCallback)(void* context);
  24. /** Callback type to call by IrdaWorker thread when new signal is received */
  25. typedef void (*IrdaWorkerReceivedSignalCallback)(void* context, IrdaWorkerSignal* received_signal);
  26. /** Allocate IrdaWorker
  27. *
  28. * @return just created instance of IrdaWorker
  29. */
  30. IrdaWorker* irda_worker_alloc();
  31. /** Free IrdaWorker
  32. *
  33. * @param[in] instance - IrdaWorker instance
  34. */
  35. void irda_worker_free(IrdaWorker* instance);
  36. /** Start IrdaWorker thread, initialise furi_hal, prepare all work.
  37. *
  38. * @param[in] instance - IrdaWorker instance
  39. */
  40. void irda_worker_rx_start(IrdaWorker* instance);
  41. /** Stop IrdaWorker thread, deinitialize furi_hal.
  42. *
  43. * @param[in] instance - IrdaWorker instance
  44. */
  45. void irda_worker_rx_stop(IrdaWorker* instance);
  46. /** Set received data callback IrdaWorker
  47. *
  48. * @param[in] instance - IrdaWorker instance
  49. * @param[in] context - context to pass to callbacks
  50. * @param[in] callback - IrdaWorkerReceivedSignalCallback callback
  51. */
  52. void irda_worker_rx_set_received_signal_callback(
  53. IrdaWorker* instance,
  54. IrdaWorkerReceivedSignalCallback callback,
  55. void* context);
  56. /** Enable blinking on receiving any signal on IR port.
  57. *
  58. * @param[in] instance - instance of IrdaWorker
  59. * @param[in] enable - true if you want to enable blinking
  60. * false otherwise
  61. */
  62. void irda_worker_rx_enable_blink_on_receiving(IrdaWorker* instance, bool enable);
  63. /** Clarify is received signal either decoded or raw
  64. *
  65. * @param[in] signal - received signal
  66. * @return true if signal is decoded, false if signal is raw
  67. */
  68. bool irda_worker_signal_is_decoded(const IrdaWorkerSignal* signal);
  69. /** Start transmitting signal. Callback IrdaWorkerGetSignalCallback should be
  70. * set before this function is called, as it calls for it to fill buffer before
  71. * starting transmission.
  72. *
  73. * @param[in] instance - IrdaWorker instance
  74. */
  75. void irda_worker_tx_start(IrdaWorker* instance);
  76. /** Stop transmitting signal. Waits for end of current signal and stops transmission.
  77. *
  78. * @param[in] instance - IrdaWorker instance
  79. */
  80. void irda_worker_tx_stop(IrdaWorker* instance);
  81. /** Set callback for providing next signal to send
  82. *
  83. * @param[in] instance - IrdaWorker instance
  84. * @param[in] context - context to pass to callbacks
  85. * @param[in] callback - IrdaWorkerGetSignalCallback callback
  86. */
  87. void irda_worker_tx_set_get_signal_callback(
  88. IrdaWorker* instance,
  89. IrdaWorkerGetSignalCallback callback,
  90. void* context);
  91. /** Set callback for end of signal transmitting
  92. *
  93. * @param[in] instance - IrdaWorker instance
  94. * @param[in] context - context to pass to callbacks
  95. * @param[in] callback - IrdaWorkerMessageSentCallback callback
  96. */
  97. void irda_worker_tx_set_signal_sent_callback(
  98. IrdaWorker* instance,
  99. IrdaWorkerMessageSentCallback callback,
  100. void* context);
  101. /** Callback to pass to irda_worker_tx_set_get_signal_callback() if signal
  102. * is steady and will not be changed between irda_worker start and stop.
  103. * Before starting transmission, desired steady signal must be set with
  104. * irda_worker_make_decoded_signal() or irda_worker_make_raw_signal().
  105. *
  106. * This function should not be implicitly called.
  107. *
  108. * @param[in] context - context
  109. * @param[out] instance - IrdaWorker instance
  110. */
  111. IrdaWorkerGetSignalResponse
  112. irda_worker_tx_get_signal_steady_callback(void* context, IrdaWorker* instance);
  113. /** Acquire raw signal from interface struct 'IrdaWorkerSignal'.
  114. * First, you have to ensure that signal is raw.
  115. *
  116. * @param[in] signal - received signal
  117. * @param[out] timings - pointer to array of timings
  118. * @param[out] timings_cnt - pointer to amount of timings
  119. */
  120. void irda_worker_get_raw_signal(
  121. const IrdaWorkerSignal* signal,
  122. const uint32_t** timings,
  123. size_t* timings_cnt);
  124. /** Acquire decoded message from interface struct 'IrdaWorkerSignal'.
  125. * First, you have to ensure that signal is decoded.
  126. *
  127. * @param[in] signal - received signal
  128. * @return decoded IRDA message
  129. */
  130. const IrdaMessage* irda_worker_get_decoded_signal(const IrdaWorkerSignal* signal);
  131. /** Set current decoded signal for IrdaWorker instance
  132. *
  133. * @param[out] instance - IrdaWorker instance
  134. * @param[in] message - decoded signal
  135. */
  136. void irda_worker_set_decoded_signal(IrdaWorker* instance, const IrdaMessage* message);
  137. /** Set current raw signal for IrdaWorker instance
  138. *
  139. * @param[out] instance - IrdaWorker instance
  140. * @param[in] timings - array of raw timings
  141. * @param[in] timings_cnt - size of array of raw timings
  142. */
  143. void irda_worker_set_raw_signal(IrdaWorker* instance, const uint32_t* timings, size_t timings_cnt);
  144. #ifdef __cplusplus
  145. }
  146. #endif