1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include "Timer.h"
- #include "system_timer.h"
- template<typename T>
- Timer<T>::Timer() : m_isRunning(false), m_started()
- {
- }
- template<typename T>
- void Timer<T>::start()
- {
- m_started = _millis();
- m_isRunning = true;
- }
- template<typename T>
- bool Timer<T>::expired(T msPeriod)
- {
- if (!m_isRunning) return false;
- bool expired = false;
- const T now = _millis();
- if (m_started <= m_started + msPeriod)
- {
- if ((now >= m_started + msPeriod) || (now < m_started))
- {
- expired = true;
- }
- }
- else
- {
- if ((now >= m_started + msPeriod) && (now < m_started))
- {
- expired = true;
- }
- }
- if (expired) m_isRunning = false;
- return expired;
- }
- template class Timer<unsigned long>;
- template class Timer<unsigned short>;
|