irda.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct IrdaHandler IrdaHandler;
  8. // Do not change protocol order, as it can be saved into memory and fw update can be performed!
  9. typedef enum {
  10. IrdaProtocolUnknown = -1,
  11. IrdaProtocolSamsung32 = 0,
  12. IrdaProtocolNEC = 1,
  13. IrdaProtocolNECext = 2,
  14. } IrdaProtocol;
  15. typedef struct {
  16. IrdaProtocol protocol;
  17. uint32_t address;
  18. uint32_t command;
  19. bool repeat;
  20. } IrdaMessage;
  21. /**
  22. * Initialize decoder.
  23. *
  24. * \return returns pointer to IRDA decoder handler if success, otherwise - error.
  25. */
  26. IrdaHandler* irda_alloc_decoder(void);
  27. /**
  28. * Provide to decoder next timing. If message is ready, it returns decoded message,
  29. * otherwise NULL.
  30. *
  31. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  32. * \param[in] level - high(true) or low(false) level of input signal to analyze.
  33. * it should alternate every call, otherwise it is an error case,
  34. * and decoder resets its state and start decoding from the start.
  35. * \param[in] duration - duration of steady high/low input signal.
  36. * \return if message is ready, returns pointer to decoded message, returns NULL.
  37. */
  38. const IrdaMessage* irda_decode(IrdaHandler* handler, bool level, uint32_t duration);
  39. /**
  40. * Deinitialize decoder and free allocated memory.
  41. *
  42. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  43. */
  44. void irda_free_decoder(IrdaHandler* handler);
  45. /**
  46. * Reset IRDA decoder.
  47. *
  48. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  49. */
  50. void irda_reset_decoder(IrdaHandler* handler);
  51. /**
  52. * Send message over IRDA.
  53. *
  54. * \param[in] message - message to send.
  55. * \param[in] times - number of times message should be sent.
  56. */
  57. void irda_send(const IrdaMessage* message, int times);
  58. /**
  59. * Get protocol name by protocol enum.
  60. *
  61. * \param[in] protocol - protocol identifier.
  62. * \return string to protocol name.
  63. */
  64. const char* irda_get_protocol_name(IrdaProtocol protocol);
  65. /**
  66. * Get protocol enum by protocol name.
  67. *
  68. * \param[in] protocol_name - string to protocol name.
  69. * \return protocol identifier.
  70. */
  71. IrdaProtocol irda_get_protocol_by_name(const char* protocol_name);
  72. /**
  73. * Get address length by protocol enum.
  74. *
  75. * \param[in] protocol - protocol identifier.
  76. * \return length of address in nibbles.
  77. */
  78. uint8_t irda_get_protocol_address_length(IrdaProtocol protocol);
  79. /**
  80. * Get command length by protocol enum.
  81. *
  82. * \param[in] protocol - protocol identifier.
  83. * \return length of command in nibbles.
  84. */
  85. uint8_t irda_get_protocol_command_length(IrdaProtocol protocol);
  86. /**
  87. * Checks whether protocol valid.
  88. *
  89. * \param[in] protocol - protocol identifier.
  90. * \return true if protocol is valid, false otherwise.
  91. */
  92. bool irda_is_protocol_valid(IrdaProtocol protocol);
  93. #ifdef __cplusplus
  94. }
  95. #endif