Closed jj-uk closed 4 years ago
Please consider the following:
Set status = STOPPED; in the constructor. (otherwise it's used uninitialised.)
status = STOPPED;
Allow NULL function pointers. This allows the timer to run, and be polled instead of calling the callback.
Remove all checks on callback:
callback
// if (callback == NULL) return;
Change update to the following:
update
void Ticker::update() { if (tick()) { if( callback ) callback(); }
Change both instances of:
if (repeat - counts == 1) { enabled = false; }
to be as follows:
if ((repeat - counts) == 1) { enabled = false; status = STOPPED; }
With the above changes implemented, a "blocking" delay(ms) routine can easily be coded without having to provide a dummy callback:
void DelayBlocked( uint32_t ms ) { Ticker t( NULL, ms, 1, MILLIS ); t.start(); do { t.update(); } while( STOPPED != t.state() ); }
Without my suggested changes, a "blocking" delay(ms) routine looks like this:
void DelayBlocked( uint32_t ms ) { Ticker t( DummyCallback, ms, 1, MILLIS ); t.start(); do { t.update(); } while( 1 != t.counter() ); } void DummyCallback() { }
For a blockig delay simply use delay()
Please consider the following:
Set
status = STOPPED;
in the constructor. (otherwise it's used uninitialised.)Allow NULL function pointers. This allows the timer to run, and be polled instead of calling the callback.
Remove all checks on
callback
:Change
update
to the following:Change both instances of:
to be as follows:
With the above changes implemented, a "blocking" delay(ms) routine can easily be coded without having to provide a dummy callback:
Without my suggested changes, a "blocking" delay(ms) routine looks like this: