infrared_worker.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 512
  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. /** Clarify is received signal either decoded or raw
  65. *
  66. * @param[in] signal - received signal
  67. * @return true if signal is decoded, false if signal is raw
  68. */
  69. bool infrared_worker_signal_is_decoded(const InfraredWorkerSignal* signal);
  70. /** Start transmitting signal. Callback InfraredWorkerGetSignalCallback should be
  71. * set before this function is called, as it calls for it to fill buffer before
  72. * starting transmission.
  73. *
  74. * @param[in] instance - InfraredWorker instance
  75. */
  76. void infrared_worker_tx_start(InfraredWorker* instance);
  77. /** Stop transmitting signal. Waits for end of current signal and stops transmission.
  78. *
  79. * @param[in] instance - InfraredWorker instance
  80. */
  81. void infrared_worker_tx_stop(InfraredWorker* instance);
  82. /** Set callback for providing next signal to send
  83. *
  84. * @param[in] instance - InfraredWorker instance
  85. * @param[in] context - context to pass to callbacks
  86. * @param[in] callback - InfraredWorkerGetSignalCallback callback
  87. */
  88. void infrared_worker_tx_set_get_signal_callback(
  89. InfraredWorker* instance,
  90. InfraredWorkerGetSignalCallback callback,
  91. void* context);
  92. /** Set callback for end of signal transmitting
  93. *
  94. * @param[in] instance - InfraredWorker instance
  95. * @param[in] context - context to pass to callbacks
  96. * @param[in] callback - InfraredWorkerMessageSentCallback callback
  97. */
  98. void infrared_worker_tx_set_signal_sent_callback(
  99. InfraredWorker* instance,
  100. InfraredWorkerMessageSentCallback callback,
  101. void* context);
  102. /** Callback to pass to infrared_worker_tx_set_get_signal_callback() if signal
  103. * is steady and will not be changed between infrared_worker start and stop.
  104. * Before starting transmission, desired steady signal must be set with
  105. * infrared_worker_make_decoded_signal() or infrared_worker_make_raw_signal().
  106. *
  107. * This function should not be implicitly called.
  108. *
  109. * @param[in] context - context
  110. * @param[out] instance - InfraredWorker instance
  111. */
  112. InfraredWorkerGetSignalResponse
  113. infrared_worker_tx_get_signal_steady_callback(void* context, InfraredWorker* instance);
  114. /** Acquire raw signal from interface struct 'InfraredWorkerSignal'.
  115. * First, you have to ensure that signal is raw.
  116. *
  117. * @param[in] signal - received signal
  118. * @param[out] timings - pointer to array of timings
  119. * @param[out] timings_cnt - pointer to amount of timings
  120. */
  121. void infrared_worker_get_raw_signal(
  122. const InfraredWorkerSignal* signal,
  123. const uint32_t** timings,
  124. size_t* timings_cnt);
  125. /** Acquire decoded message from interface struct 'InfraredWorkerSignal'.
  126. * First, you have to ensure that signal is decoded.
  127. *
  128. * @param[in] signal - received signal
  129. * @return decoded INFRARED message
  130. */
  131. const InfraredMessage* infrared_worker_get_decoded_signal(const InfraredWorkerSignal* signal);
  132. /** Set current decoded signal for InfraredWorker instance
  133. *
  134. * @param[out] instance - InfraredWorker instance
  135. * @param[in] message - decoded signal
  136. */
  137. void infrared_worker_set_decoded_signal(InfraredWorker* instance, const InfraredMessage* message);
  138. /** Set current raw signal for InfraredWorker instance
  139. *
  140. * @param[out] instance - InfraredWorker instance
  141. * @param[in] timings - array of raw timings
  142. * @param[in] timings_cnt - size of array of raw timings
  143. */
  144. void infrared_worker_set_raw_signal(
  145. InfraredWorker* instance,
  146. const uint32_t* timings,
  147. size_t timings_cnt);
  148. #ifdef __cplusplus
  149. }
  150. #endif