infrared_app_signal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file infrared_app_signal.h
  3. * Infrared: Signal class
  4. */
  5. #pragma once
  6. #include <infrared_worker.h>
  7. #include <stdint.h>
  8. #include <string>
  9. #include <infrared.h>
  10. /** Infrared application signal class */
  11. class InfraredAppSignal {
  12. public:
  13. /** Raw signal structure */
  14. typedef struct {
  15. /** Timings amount */
  16. size_t timings_cnt;
  17. /** Samples of raw signal in ms */
  18. uint32_t* timings;
  19. /** PWM Frequency of raw signal */
  20. uint32_t frequency;
  21. /** PWM Duty cycle of raw signal */
  22. float duty_cycle;
  23. } RawSignal;
  24. private:
  25. /** if true - signal is raw, if false - signal is parsed */
  26. bool raw_signal;
  27. /** signal data, either raw or parsed */
  28. union {
  29. /** signal data for parsed signal */
  30. InfraredMessage message;
  31. /** raw signal data */
  32. RawSignal raw;
  33. } payload;
  34. /** Copy raw signal into object
  35. *
  36. * @param timings - timings (samples) of raw signal
  37. * @param size - number of timings
  38. * @frequency - PWM frequency of raw signal
  39. * @duty_cycle - PWM duty cycle
  40. */
  41. void
  42. copy_raw_signal(const uint32_t* timings, size_t size, uint32_t frequency, float duty_cycle);
  43. /** Clear and free timings data */
  44. void clear_timings();
  45. public:
  46. /** Construct Infrared signal class */
  47. InfraredAppSignal() {
  48. raw_signal = false;
  49. payload.message.protocol = InfraredProtocolUnknown;
  50. }
  51. /** Destruct signal class and free all allocated data */
  52. ~InfraredAppSignal() {
  53. clear_timings();
  54. }
  55. /** Construct object with raw signal
  56. *
  57. * @param timings - timings (samples) of raw signal
  58. * @param size - number of timings
  59. * @frequency - PWM frequency of raw signal
  60. * @duty_cycle - PWM duty cycle
  61. */
  62. InfraredAppSignal(
  63. const uint32_t* timings,
  64. size_t timings_cnt,
  65. uint32_t frequency,
  66. float duty_cycle);
  67. /** Construct object with parsed signal
  68. *
  69. * @param infrared_message - parsed_signal to construct from
  70. */
  71. InfraredAppSignal(const InfraredMessage* infrared_message);
  72. /** Copy constructor */
  73. InfraredAppSignal(const InfraredAppSignal& other);
  74. /** Move constructor */
  75. InfraredAppSignal(InfraredAppSignal&& other);
  76. /** Assignment operator */
  77. InfraredAppSignal& operator=(const InfraredAppSignal& signal);
  78. /** Set object to parsed signal
  79. *
  80. * @param infrared_message - parsed_signal to construct from
  81. */
  82. void set_message(const InfraredMessage* infrared_message);
  83. /** Set object to raw signal
  84. *
  85. * @param timings - timings (samples) of raw signal
  86. * @param size - number of timings
  87. * @frequency - PWM frequency of raw signal
  88. * @duty_cycle - PWM duty cycle
  89. */
  90. void
  91. set_raw_signal(uint32_t* timings, size_t timings_cnt, uint32_t frequency, float duty_cycle);
  92. /** Transmit held signal (???) */
  93. void transmit() const;
  94. /** Show is held signal raw
  95. *
  96. * @retval true if signal is raw, false if signal is parsed
  97. */
  98. bool is_raw(void) const {
  99. return raw_signal;
  100. }
  101. /** Get parsed signal.
  102. * User must check is_raw() signal before calling this function.
  103. *
  104. * @retval parsed signal pointer
  105. */
  106. const InfraredMessage& get_message(void) const {
  107. furi_assert(!raw_signal);
  108. return payload.message;
  109. }
  110. /** Get raw signal.
  111. * User must check is_raw() signal before calling this function.
  112. *
  113. * @retval raw signal
  114. */
  115. const RawSignal& get_raw_signal(void) const {
  116. furi_assert(raw_signal);
  117. return payload.raw;
  118. }
  119. };