Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
Coroutine Class Reference

A coroutine essentially is a throttling mechanism: it takes in a tick-event or tick count and executes its action when the time (number of ticks) passed between the last call and the current one is larger than the time the action reported the next call needed to wait. More...

#include <cs_Coroutine.h>

Public Types

typedef std::function< uint32_t(void)> Action
 

Public Member Functions

 Coroutine ()=default
 
 Coroutine (Action a)
 
void onTick (uint32_t currentTickCount)
 To be called on tick event. More...
 
bool handleEvent (event_t &evt)
 Convenience function replacing onTick(). More...
 
uint32_t getNextCallTickCount () const
 

Static Public Member Functions

static uint32_t delayMs (uint32_t ms)
 
static uint32_t delayS (uint32_t s)
 

Public Attributes

Action action
 

Private Attributes

uint32_t nextCallTickcount = 0
 

Detailed Description

A coroutine essentially is a throttling mechanism: it takes in a tick-event or tick count and executes its action when the time (number of ticks) passed between the last call and the current one is larger than the time the action reported the next call needed to wait.

Example: uint32_t sayHi() { LOGd("hi"); return 42; } Coroutine hiSayer (sayHi);

for (int i = 0; ; i++){ hiSayer.onTick(i); }

This will log "hi" only one in 42 calls.

Note that the return value of sayHi determines the delay, so that a coroutine can dynamically determine if it needs to be called more often or not.

Member Typedef Documentation

◆ Action

typedef std::function<uint32_t(void)> Coroutine::Action

Constructor & Destructor Documentation

◆ Coroutine() [1/2]

Coroutine::Coroutine ( )
default

◆ Coroutine() [2/2]

Member Function Documentation

◆ delayMs()

static uint32_t Coroutine::delayMs ( uint32_t  ms)
inlinestatic

◆ delayS()

static uint32_t Coroutine::delayS ( uint32_t  s)
inlinestatic

◆ getNextCallTickCount()

uint32_t Coroutine::getNextCallTickCount ( ) const
inline

◆ handleEvent()

bool Coroutine::handleEvent ( event_t evt)
inline

Convenience function replacing onTick().

To be called on event.

◆ onTick()

void Coroutine::onTick ( uint32_t  currentTickCount)
inline

To be called on tick event.

Member Data Documentation

◆ action

Action Coroutine::action

◆ nextCallTickcount

uint32_t Coroutine::nextCallTickcount = 0
private

The documentation for this class was generated from the following file: