pulse_protocol.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @file pulse_protocol.h
  3. *
  4. * Generic pulse protocol decoder library, protocol interface
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <stdlib.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * Anonymous PulseProtocol struct
  15. */
  16. typedef struct PulseProtocol PulseProtocol;
  17. /**
  18. * Process pulse callback
  19. */
  20. typedef void (*PulseProtocolPulseCallback)(void* context, bool polarity, uint32_t length);
  21. /**
  22. * Reset protocol callback
  23. */
  24. typedef void (*PulseProtocolResetCallback)(void* context);
  25. /**
  26. * Get decoded data callback
  27. */
  28. typedef void (*PulseProtocolGetDataCallback)(void* context, uint8_t* data, size_t length);
  29. /**
  30. * Is protocol decoded callback
  31. */
  32. typedef bool (*PulseProtocolDecodedCallback)(void* context);
  33. /**
  34. * Allocate protocol
  35. * @return PulseProtocol*
  36. */
  37. PulseProtocol* pulse_protocol_alloc();
  38. /**
  39. * Deallocate protocol
  40. * @param protocol
  41. */
  42. void pulse_protocol_free(PulseProtocol* protocol);
  43. /**
  44. * Set context for callbacks
  45. * @param protocol
  46. * @param context
  47. */
  48. void pulse_protocol_set_context(PulseProtocol* protocol, void* context);
  49. /**
  50. * Set "Process pulse" callback. Called from the decoder when a new pulse is received.
  51. * @param protocol
  52. * @param callback
  53. */
  54. void pulse_protocol_set_pulse_cb(PulseProtocol* protocol, PulseProtocolPulseCallback callback);
  55. /**
  56. * Set "Reset protocol" callback. Called from the decoder when the decoder is reset.
  57. * @param protocol
  58. * @param callback
  59. */
  60. void pulse_protocol_set_reset_cb(PulseProtocol* protocol, PulseProtocolResetCallback callback);
  61. /**
  62. * Set "Get decoded data" callback. Called from the decoder when the decoder wants to get decoded data.
  63. * @param protocol
  64. * @param callback
  65. */
  66. void pulse_protocol_set_get_data_cb(PulseProtocol* protocol, PulseProtocolGetDataCallback callback);
  67. /**
  68. * Set "Is protocol decoded" callback. Called from the decoder when the decoder wants to know if a protocol has been decoded.
  69. * @param protocol
  70. * @param callback
  71. */
  72. void pulse_protocol_set_decoded_cb(PulseProtocol* protocol, PulseProtocolDecodedCallback callback);
  73. /**
  74. * Part of decoder interface.
  75. * @param protocol
  76. * @param polarity
  77. * @param length
  78. */
  79. void pulse_protocol_process_pulse(PulseProtocol* protocol, bool polarity, uint32_t length);
  80. /**
  81. * Part of decoder interface.
  82. * @param protocol
  83. * @return true
  84. * @return false
  85. */
  86. bool pulse_protocol_decoded(PulseProtocol* protocol);
  87. /**
  88. * Part of decoder interface.
  89. * @param protocol
  90. * @return true
  91. * @return false
  92. */
  93. void pulse_protocol_get_data(PulseProtocol* protocol, uint8_t* data, size_t length);
  94. /**
  95. * Part of decoder interface.
  96. * @param protocol
  97. * @return true
  98. * @return false
  99. */
  100. void pulse_protocol_reset(PulseProtocol* protocol);
  101. #ifdef __cplusplus
  102. }
  103. #endif