irda.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. IrdaProtocolSamsung32 = 0,
  11. IrdaProtocolNEC = 1,
  12. } IrdaProtocol;
  13. typedef struct {
  14. IrdaProtocol protocol;
  15. uint32_t address;
  16. uint32_t command;
  17. bool repeat;
  18. } IrdaMessage;
  19. /**
  20. * Initialize decoder.
  21. *
  22. * \return returns pointer to IRDA decoder handler if success, otherwise - error.
  23. */
  24. IrdaHandler* irda_alloc_decoder(void);
  25. /**
  26. * Provide to decoder next timing. If message is ready, it returns decoded message,
  27. * otherwise NULL.
  28. *
  29. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  30. * \param[in] level - high(true) or low(false) level of input signal to analyze.
  31. * it should alternate every call, otherwise it is an error case,
  32. * and decoder resets its state and start decoding from the start.
  33. * \param[in] duration - duration of steady high/low input signal.
  34. * \return if message is ready, returns pointer to decoded message, returns NULL.
  35. */
  36. const IrdaMessage* irda_decode(IrdaHandler* handler, bool level, uint32_t duration);
  37. /**
  38. * Deinitialize decoder and free allocated memory.
  39. *
  40. * \param[in] handler - handler to irda decoders. Should be aquired with \c irda_alloc_decoder().
  41. */
  42. void irda_free_decoder(IrdaHandler* handler);
  43. /**
  44. * Send message over IRDA.
  45. *
  46. * \param[in] message - message to send.
  47. * \param[in] times - number of times message should be sent.
  48. */
  49. void irda_send(const IrdaMessage* message, int times);
  50. /**
  51. * Get protocol name by protocol enum.
  52. *
  53. * \param[in] protocol - protocol identifier.
  54. * \return string to protocol name.
  55. */
  56. const char* irda_get_protocol_name(IrdaProtocol protocol);
  57. #ifdef __cplusplus
  58. }
  59. #endif