Timer.h 744 B

123456789101112131415161718192021222324252627282930
  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. * Maximum period is at least 49 days. Resolution is one millisecond. To save memory, doesn't store timer period.
  12. * If you wish timer which is storing period, derive from this. If you need time intervals smaller than 65 seconds
  13. * consider implementing timer with smaller underlying type.
  14. */
  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(unsigned long msPeriod);
  23. private:
  24. bool m_isRunning;
  25. unsigned long m_started;
  26. };
  27. #endif /* TIMER_H */