Min-Max Times

template <class Timer>
class MinMaxTimes : public Profiling::MinMax<uint32_t>, public Timer

Public Types

template<>
using Millis = NanoTime::TimeSource<Clock, NanoTime::Milliseconds, uint32_t>
template<>
using Micros = NanoTime::TimeSource<Clock, NanoTime::Microseconds, TimeType>

Public Functions

MinMaxTimes(const String &title)
void update()
NanoTime::Time<uint32_t> getMinTime() const
NanoTime::Time<uint32_t> getMaxTime() const
NanoTime::Time<uint32_t> getAverageTime() const
NanoTime::Time<uint32_t> getTotalTime() const
size_t printTo(Print &p) const
const String &getTitle() const
void clear()
void update(T value)
T getMin() const
T getMax() const
T getTotal() const
T getAverage() const
unsigned getCount() const
DelegateCallbackTimer &initializeUs(TimerDelegate delegateFunction)

Initialise timer in microseconds, with static check.

Template Parameters
  • microseconds: Timer interval in microseconds
Parameters
  • delegateFunction: Function to call when timer triggers
Return Value
  • ExtendedCallbackTimer&: Reference to timer

DelegateCallbackTimer &initializeUs(uint32_t microseconds, TimerDelegate delegateFunction)

Initialise microsecond timer.

Note
Delegate callback method
Parameters
  • microseconds: Duration of timer in milliseconds
  • delegateFunction: Function to call when timer triggers

CallbackTimer &initializeUs(TimerCallback callback, void *arg = nullptr)

Initialise timer in microseconds (static check) with Timer Callback and optional argument.

CallbackTimer &initializeUs(InterruptCallback callback = nullptr)

Initialise timer in microseconds (static check) with optional Interrupt Callback (no argument)

CallbackTimer &initializeUs(TimeType microseconds, TimerCallback callback, void *arg = nullptr)

Initialise timer in microseconds with Timer Callback and optional argument.

CallbackTimer &initializeUs(TimeType microseconds, InterruptCallback callback = nullptr)

Initialise timer in microseconds with optional Interrupt Callback (no arg)

DelegateCallbackTimer &initializeMs(TimerDelegate delegateFunction)

Initialise hardware timer in milliseconds, with static check.

Template Parameters
  • milliseconds: Timer interval in milliseconds
Parameters
  • delegateFunction: Function to call when timer triggers
Return Value
  • ExtendedCallbackTimer&: Reference to timer

DelegateCallbackTimer &initializeMs(uint32_t milliseconds, TimerDelegate delegateFunction)

Initialise millisecond timer.

Note
Delegate callback method
Parameters
  • milliseconds: Duration of timer in milliseconds
  • delegateFunction: Function to call when timer triggers

CallbackTimer &initializeMs(TimerCallback callback, void *arg = nullptr)

Initialise hardware timer in milliseconds (static check) with Timer Callback and optional argument.

CallbackTimer &initializeMs(InterruptCallback callback = nullptr)

Initialise hardware timer in milliseconds (static check) and optional Interrupt Callback (no arg)

CallbackTimer &initializeMs(uint32_t milliseconds, TimerCallback callback, void *arg = nullptr)

Initialise hardware timer in milliseconds with Timer Callback and optional argument.

CallbackTimer &initializeMs(uint32_t milliseconds, InterruptCallback callback = nullptr)

Initialise hardware timer in milliseconds with optional Interrupt Callback (no arg)

void setCallback(TimerDelegate delegateFunction)

Set timer trigger function using Delegate callback method.

Note
Don’t use this for interrupt timers
Parameters
  • delegateFunction: Function to be called on timer trigger

void setCallback(TimerCallback callback, void *arg = nullptr)

Set timer trigger callback.

Parameters
  • callback: Function to call when timer triggers
  • arg: Optional argument passed to callback

void setCallback(InterruptCallback callback)

Set timer trigger callback.

Note
Provided for convenience where callback argument not required
Parameters
  • callback: Function to call when timer triggers

CallbackTimer &initialize(TimerCallback callback, void *arg = nullptr)

Initialise timer with an interval (static check) and callback.

Note
If interval out of range compilation will fail with error
Template Parameters
  • unit: Time unit for interval
  • time: Timer interval
Parameters
  • callback: Callback function to call when timer triggers
  • arg: Optional argument passed to callback
Return Value
  • CallbackTimer&: Reference to timer

CallbackTimer &initialize(TimeType time, TimerCallback callback, void *arg = nullptr)

Initialise timer with an interval and callback.

Template Parameters
  • unit: Time unit for interval
Parameters
  • time: Timer interval
  • callback: Callback function to call when timer triggers
  • arg: Optional argument passed to callback
Return Value
  • CallbackTimer&: Reference to timer

bool start(bool repeating = true)

Start timer running.

Parameters
  • repeating: True to restart timer when it triggers, false for one-shot (Default: true)
Return Value
  • bool: True if timer started

bool startOnce()

Start one-shot timer.

Note
Timer starts and will run for configured period then stop
Return Value
  • bool: True if timer started

void stop()

Stops timer.

bool restart()

Restart timer.

Note
Timer is stopped then started with current configuration
Return Value
  • bool: True if timer started

bool isStarted() const

Check if timer is started.

Return Value
  • bool: True if started

NanoTime::Time<TimeType> getIntervalUs() const

Get timer interval in microseconds.

NanoTime::Time<uint32_t> getIntervalMs() const

Get timer interval in milliseconds.

TickType getInterval() const

Get timer interval in clock ticks.

bool checkInterval(TickType ticks) const

Check timer interval is valid.

Parameters
  • ticks: Interval to check
Return Value
  • bool: true if interval is within acceptable range for this timer

bool setInterval(TickType ticks)

Set timer interval in timer ticks.

Parameters
  • ticks: Interval in timer ticks

void setInterval()

Set timer interval in timer ticks (static check)

Note
On error, compilation fails with error message
Template Parameters
  • ticks: Interval in ticks

void setInterval()

Set timer interval in specific time unit (static check)

Note
On error, compilation fails with error message
Template Parameters
  • unit:
  • time: Interval to set

bool setInterval(TimeType time)

Set timer interval in timer ticks.

Template Parameters
  • unit:
Parameters
  • time: Interval in given units

bool setIntervalUs(TimeType microseconds)

Set timer interval in microseconds.

void setIntervalUs()

Set timer interval in microseconds (static check)

bool setIntervalMs(uint32_t milliseconds)

Set timer interval in milliseconds.

void setIntervalMs()

Set timer interval in milliseconds (static check)

Public Static Functions

static constexpr Millis millis()

Get a millisecond time source.

static constexpr Micros micros()

Get a microsecond time source.

static constexpr uint64_t usToTicks()

Convert microsecond count into timer ticks.

static TickType usToTicks(TimeType time)

Convert microsecond count into timer ticks.

static constexpr uint64_t ticksToUs()

Convert timer ticks into microseconds.

static TimeType ticksToUs(TickType ticks)

Convert timer ticks into microseconds.

static constexpr void checkInterval()

Check timer interval in ticks is valid (static check)

Note
On error, compilation fails with error message
Template Parameters
  • ticks: Timer interval to check

static constexpr void checkInterval()

Check timer interval in specific time unit is valid (static check)

Note
On error, compilation fails with error message
Template Parameters
  • unit: Time unit for interval
  • time: Interval to check

static constexpr void checkIntervalMs()

Check timer interval in milliseconds is valid (static check)

static constexpr void checkIntervalUs()

Check timer interval in microseconds is valid (static check)

Protected Types

template<>
using Clock = OsTimerApi::Clock
template<>
using TickType = uint64_t
template<>
using TimeType = uint64_t

Protected Functions

bool isArmed() const
TickType ticks() const
void arm(bool repeating)
void disarm()
String name() const
String toString() const
operator String() const

Protected Attributes

TimerCallback func
void *arg

Protected Static Functions

static constexpr const char *typeName()
static constexpr TickType minTicks()
static constexpr TickType maxTicks()