pulse_decoder.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @file pulse_decoder.h
  3. *
  4. * Generic pulse protocol decoder library
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "pulse_protocol.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. typedef struct PulseDecoder PulseDecoder;
  14. /**
  15. * Allocate decoder
  16. * @return PulseDecoder*
  17. */
  18. PulseDecoder* pulse_decoder_alloc();
  19. /**
  20. * Deallocate decoder
  21. * @param decoder
  22. */
  23. void pulse_decoder_free(PulseDecoder* decoder);
  24. /**
  25. * Add protocol to decoder
  26. * @param decoder
  27. * @param protocol protocol implementation
  28. * @param index protocol index, should not be repeated
  29. */
  30. void pulse_decoder_add_protocol(PulseDecoder* decoder, PulseProtocol* protocol, int32_t index);
  31. /**
  32. * Push and process pulse with decoder
  33. * @param decoder
  34. * @param polarity
  35. * @param length
  36. */
  37. void pulse_decoder_process_pulse(PulseDecoder* decoder, bool polarity, uint32_t length);
  38. /**
  39. * Get indec of decoded protocol
  40. * @param decoder
  41. * @return int32_t, -1 if nothing decoded, or index of decoded protocol
  42. */
  43. int32_t pulse_decoder_get_decoded_index(PulseDecoder* decoder);
  44. /**
  45. * Reset all protocols in decoder
  46. * @param decoder
  47. */
  48. void pulse_decoder_reset(PulseDecoder* decoder);
  49. /**
  50. * Get decoded data from protocol
  51. * @param decoder
  52. * @param index
  53. * @param data
  54. * @param length
  55. */
  56. void pulse_decoder_get_data(PulseDecoder* decoder, int32_t index, uint8_t* data, size_t length);
  57. #ifdef __cplusplus
  58. }
  59. #endif