Timer.h 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @file
  3. * @author Marek Bel
  4. */
  5. #ifndef TIMER_H
  6. #define TIMER_H
  7. /**
  8. * @brief simple timer
  9. *
  10. * Simple and memory saving implementation. Should handle timer register wrap around well.
  11. * Resolution is one millisecond. To save memory, doesn't store timer period.
  12. * If you wish timer which is storing period, derive from this.
  13. */
  14. template <class T>
  15. class Timer
  16. {
  17. public:
  18. Timer();
  19. void start();
  20. void stop(){m_isRunning = false;}
  21. bool running(){return m_isRunning;}
  22. bool expired(T msPeriod);
  23. private:
  24. bool m_isRunning;
  25. T m_started;
  26. };
  27. /**
  28. * @brief Timer unsigned long specialization
  29. *
  30. * Maximum period is at least 49 days.
  31. */
  32. using LongTimer = Timer<unsigned long>;
  33. /**
  34. * @brief Timer unsigned short specialization
  35. *
  36. * Maximum period is at least 65 seconds.
  37. */
  38. using ShortTimer = Timer<unsigned short>;
  39. #endif /* TIMER_H */