pulse_joiner.h 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include "stdint.h"
  3. class PulseJoiner {
  4. public:
  5. /**
  6. * @brief Push timer pulse. First negative pulse is ommited.
  7. *
  8. * @param polarity pulse polarity: true = high2low, false = low2high
  9. * @param period overall period time in timer clicks
  10. * @param pulse pulse time in timer clicks
  11. *
  12. * @return true - next pulse can and must be popped immediatly
  13. */
  14. bool push_pulse(bool polarity, uint16_t period, uint16_t pulse);
  15. /**
  16. * @brief Get the next timer pulse. Call only if push_pulse returns true.
  17. *
  18. * @param period overall period time in timer clicks
  19. * @param pulse pulse time in timer clicks
  20. */
  21. void pop_pulse(uint16_t* period, uint16_t* pulse);
  22. PulseJoiner();
  23. private:
  24. struct Pulse {
  25. bool polarity;
  26. uint16_t time;
  27. };
  28. uint8_t pulse_index = 0;
  29. static const uint8_t pulse_max = 6;
  30. Pulse pulses[pulse_max];
  31. };