infrared_worker.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #pragma once
  2. #include <infrared.h>
  3. #include <furi_hal.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #define MAX_TIMINGS_AMOUNT 1024
  8. /** Interface struct of infrared worker */
  9. typedef struct InfraredWorker InfraredWorker;
  10. /** Interface struct of received signal */
  11. typedef struct InfraredWorkerSignal InfraredWorkerSignal;
  12. typedef enum {
  13. InfraredWorkerGetSignalResponseNew, /** Signal, provided by callback is new and encoder should be reseted */
  14. InfraredWorkerGetSignalResponseSame, /** Signal, provided by callback is same. No encoder resetting. */
  15. InfraredWorkerGetSignalResponseStop, /** No more signals available. */
  16. } InfraredWorkerGetSignalResponse;
  17. /** Callback type for providing next signal to send. Should be used with
  18. * infrared_worker_make_decoded_signal() or infrared_worker_make_raw_signal()
  19. */
  20. typedef InfraredWorkerGetSignalResponse (
  21. *InfraredWorkerGetSignalCallback)(void* context, InfraredWorker* instance);
  22. /** Callback type for 'message is sent' event */
  23. typedef void (*InfraredWorkerMessageSentCallback)(void* context);
  24. /** Callback type to call by InfraredWorker thread when new signal is received */
  25. typedef void (
  26. *InfraredWorkerReceivedSignalCallback)(void* context, InfraredWorkerSignal* received_signal);
  27. /** Allocate InfraredWorker
  28. *
  29. * @return just created instance of InfraredWorker
  30. */
  31. InfraredWorker* infrared_worker_alloc();
  32. /** Free InfraredWorker
  33. *
  34. * @param[in] instance - InfraredWorker instance
  35. */
  36. void infrared_worker_free(InfraredWorker* instance);
  37. /** Start InfraredWorker thread, initialise furi_hal, prepare all work.
  38. *
  39. * @param[in] instance - InfraredWorker instance
  40. */
  41. void infrared_worker_rx_start(InfraredWorker* instance);
  42. /** Stop InfraredWorker thread, deinitialize furi_hal.
  43. *
  44. * @param[in] instance - InfraredWorker instance
  45. */
  46. void infrared_worker_rx_stop(InfraredWorker* instance);
  47. /** Set received data callback InfraredWorker
  48. *
  49. * @param[in] instance - InfraredWorker instance
  50. * @param[in] context - context to pass to callbacks
  51. * @param[in] callback - InfraredWorkerReceivedSignalCallback callback
  52. */
  53. void infrared_worker_rx_set_received_signal_callback(
  54. InfraredWorker* instance,
  55. InfraredWorkerReceivedSignalCallback callback,
  56. void* context);
  57. /** Enable blinking on receiving any signal on IR port.
  58. *
  59. * @param[in] instance - instance of InfraredWorker
  60. * @param[in] enable - true if you want to enable blinking
  61. * false otherwise
  62. */
  63. void infrared_worker_rx_enable_blink_on_receiving(InfraredWorker* instance, bool enable);
  64. /** Enable decoding of received infrared signals.
  65. *
  66. * @param[in] instance - instance of InfraredWorker
  67. * @param[in] enable - true if you want to enable decoding
  68. * false otherwise
  69. */
  70. void infrared_worker_rx_enable_signal_decoding(InfraredWorker* instance, bool enable);
  71. /** Clarify is received signal either decoded or raw
  72. *
  73. * @param[in] signal - received signal
  74. * @return true if signal is decoded, false if signal is raw
  75. */
  76. bool infrared_worker_signal_is_decoded(const InfraredWorkerSignal* signal);
  77. /** Start transmitting signal. Callback InfraredWorkerGetSignalCallback should be
  78. * set before this function is called, as it calls for it to fill buffer before
  79. * starting transmission.
  80. *
  81. * @param[in] instance - InfraredWorker instance
  82. */
  83. void infrared_worker_tx_start(InfraredWorker* instance);
  84. /** Stop transmitting signal. Waits for end of current signal and stops transmission.
  85. *
  86. * @param[in] instance - InfraredWorker instance
  87. */
  88. void infrared_worker_tx_stop(InfraredWorker* instance);
  89. /** Set callback for providing next signal to send
  90. *
  91. * @param[in] instance - InfraredWorker instance
  92. * @param[in] context - context to pass to callbacks
  93. * @param[in] callback - InfraredWorkerGetSignalCallback callback
  94. */
  95. void infrared_worker_tx_set_get_signal_callback(
  96. InfraredWorker* instance,
  97. InfraredWorkerGetSignalCallback callback,
  98. void* context);
  99. /** Set callback for end of signal transmitting
  100. *
  101. * @param[in] instance - InfraredWorker instance
  102. * @param[in] context - context to pass to callbacks
  103. * @param[in] callback - InfraredWorkerMessageSentCallback callback
  104. */
  105. void infrared_worker_tx_set_signal_sent_callback(
  106. InfraredWorker* instance,
  107. InfraredWorkerMessageSentCallback callback,
  108. void* context);
  109. /** Callback to pass to infrared_worker_tx_set_get_signal_callback() if signal
  110. * is steady and will not be changed between infrared_worker start and stop.
  111. * Before starting transmission, desired steady signal must be set with
  112. * infrared_worker_make_decoded_signal() or infrared_worker_make_raw_signal().
  113. *
  114. * This function should not be implicitly called.
  115. *
  116. * @param[in] context - context
  117. * @param[out] instance - InfraredWorker instance
  118. */
  119. InfraredWorkerGetSignalResponse
  120. infrared_worker_tx_get_signal_steady_callback(void* context, InfraredWorker* instance);
  121. /** Acquire raw signal from interface struct 'InfraredWorkerSignal'.
  122. * First, you have to ensure that signal is raw.
  123. *
  124. * @param[in] signal - received signal
  125. * @param[out] timings - pointer to array of timings
  126. * @param[out] timings_cnt - pointer to amount of timings
  127. */
  128. void infrared_worker_get_raw_signal(
  129. const InfraredWorkerSignal* signal,
  130. const uint32_t** timings,
  131. size_t* timings_cnt);
  132. /** Acquire decoded message from interface struct 'InfraredWorkerSignal'.
  133. * First, you have to ensure that signal is decoded.
  134. *
  135. * @param[in] signal - received signal
  136. * @return decoded INFRARED message
  137. */
  138. const InfraredMessage* infrared_worker_get_decoded_signal(const InfraredWorkerSignal* signal);
  139. /** Set current decoded signal for InfraredWorker instance
  140. *
  141. * @param[out] instance - InfraredWorker instance
  142. * @param[in] message - decoded signal
  143. */
  144. void infrared_worker_set_decoded_signal(InfraredWorker* instance, const InfraredMessage* message);
  145. /** Set current raw signal for InfraredWorker instance
  146. *
  147. * @param[out] instance - InfraredWorker instance
  148. * @param[in] timings - array of raw timings
  149. * @param[in] timings_cnt - size of array of raw timings
  150. */
  151. void infrared_worker_set_raw_signal(
  152. InfraredWorker* instance,
  153. const uint32_t* timings,
  154. size_t timings_cnt);
  155. #ifdef __cplusplus
  156. }
  157. #endif