avr-classes
Public Member Functions | Protected Member Functions | List of all members
OneShotTimer< COUNTERTYPE > Class Template Reference

#include <oneshottimer.h>

Inheritance diagram for OneShotTimer< COUNTERTYPE >:
TimerService PeriodicTimer< COUNTERTYPE >

Public Member Functions

 OneShotTimer (EventReceiver *receiver, const Event &event, COUNTERTYPE timeout)
 
COUNTERTYPE getTimeout (void) const
 
void setTimeout (COUNTERTYPE timeout)
 
virtual void onTick (void) override
 
void reset (void)
 
void restart (void)
 
- Public Member Functions inherited from TimerService
 TimerService (void)
 
void start (void)
 
void stop (void)
 
bool isRunning (void) const
 

Protected Member Functions

virtual void elapsed (void)
 

Detailed Description

template<class COUNTERTYPE>
class OneShotTimer< COUNTERTYPE >

Countdown timer that sends an event when it has elapsed. A OneShotTimer can be paused using the stop() and start() methods, and reset to the original timeout value using reset(). The OneShotTimer needs to be added to a TimerServiceHost instance. The base tick frequency of the TimerServiceHost specifies the rate at which the timeout value is decremented.

Parameters
COUNTERTYPEData type for timeout value, e.g. uint16_t.

Constructor & Destructor Documentation

◆ OneShotTimer()

template<class COUNTERTYPE >
OneShotTimer< COUNTERTYPE >::OneShotTimer ( EventReceiver receiver,
const Event event,
COUNTERTYPE  timeout 
)
inline

Constructor.

Parameters
receiverReceiver of the elapsed event.
eventEvent to be sent when timer has elapsed.
timeoutTimeout value, actual time depends on base tick frequency of used TimerServiceHost.

Member Function Documentation

◆ elapsed()

template<class COUNTERTYPE >
virtual void OneShotTimer< COUNTERTYPE >::elapsed ( void  )
inlineprotectedvirtual

Method that is called when the timer is running and reaches zero.

Reimplemented in PeriodicTimer< COUNTERTYPE >.

◆ getTimeout()

template<class COUNTERTYPE >
COUNTERTYPE OneShotTimer< COUNTERTYPE >::getTimeout ( void  ) const
inline

Gets the currently configured timeout value.

Returns
Currently configured timeout value.

◆ onTick()

template<class COUNTERTYPE >
virtual void OneShotTimer< COUNTERTYPE >::onTick ( void  )
inlineoverridevirtual

Callback for base tick events of TimerServiceHost. Called from ISR context.

Implements TimerService.

◆ reset()

template<class COUNTERTYPE >
void OneShotTimer< COUNTERTYPE >::reset ( void  )
inline

Resets the timeout value to the start value.

◆ restart()

template<class COUNTERTYPE >
void OneShotTimer< COUNTERTYPE >::restart ( void  )
inline

Resets the timeout value to the start value and starts the timer.

◆ setTimeout()

template<class COUNTERTYPE >
void OneShotTimer< COUNTERTYPE >::setTimeout ( COUNTERTYPE  timeout)
inline

Sets the timeout value that is used when restarting the timer.

Parameters
timeoutNew timeout value.
Note
The changed timeout value takes effect with the next restart only.