Errors and other functions¶
errorCode¶
The result of most functions. OK (0) is success, negative values are warnings (the function did its
job with a restriction), positive values are errors (the function could not do its job).
| Code | Value | Meaning | Returned by |
|---|---|---|---|
OK |
0 | success | all |
periodOverflow |
-100 | period or delay too long, the maximum is used | begin(), setPeriod(), setNextPeriod(), trigger(), triggerDirect(), getTriggerReload() |
prescalerIgnored |
-103 | setPrescaler() before begin() on a timer without prescaler |
begin() |
invalidArgument |
100 | invalid argument (negative period or delay, invalid prescaler) | begin(), setPeriod(), setNextPeriod(), trigger(), setPrescaler() |
noCallback |
101 | empty callback (nullptr) |
begin() |
zeroPeriod |
102 | period 0 | begin() (periodic), setPeriod(), setNextPeriod() |
poolExhausted |
103 | the timer pool has no free timer | begin() |
noFreeChannel |
104 | the requested timer type has no free channel | begin() |
notSupported |
105 | the timer doesn't support the function | see Timer types |
notInitialized |
106 | called before begin() |
all functions except begin(), end(), setPrescaler(), OneShotTimer::start() |
The names of version 1.4 (argument, callback, reload, noFreeModule, notImplemented) are
deprecated aliases of invalidArgument, noCallback, zeroPeriod, poolExhausted and notSupported.
The codes -101 and -102 are not used; values of 200 and above are reserved for internal errors of the
timer modules.
attachErrFunc()¶
Sets a function which is called for every result other than OK, exactly once per failed call, also for
getters that return NAN. Replaces a previously attached function; nullptr removes it.
| Parameter | |
|---|---|
errorFunction |
a function, lambda or functor with the signature void(errorCode), or nullptr |
See also: Error handling.
ErrorHandler¶
class ErrorHandler
{
public:
ErrorHandler(Stream& stream);
void operator()(errorCode code) const;
};
A ready-made error function for attachErrFunc(): attachErrFunc(ErrorHandler(Serial));
- Warnings are printed as
W-<code>: <text>; the sketch continues. - Errors are printed as
E-<code>: <text>; the handler then blinksLED_BUILTINin an endless loop.
The constructor sets LED_BUILTIN to output.
tick()¶
Evaluates the TCK timers and invokes the callbacks that are due. With the default configuration, the
library calls tick() from yield(); a sketch only calls it itself with the configuration option
YIELD_NONE, then as often as possible.
PeriodMode¶
The second parameter of setPeriod().
Prescaler constants¶
PSC_1, PSC_2, PSC_4, PSC_8, PSC_16, PSC_32, PSC_64, PSC_128 // TMR and GPT
PSC_256, PSC_512, PSC_1024, PSC_2048, PSC_4096 // GPT only
PSC_AUTO // FTM_DEFAULT_PSC only (configuration)
The parameter of setPrescaler() and the prescaler settings of the
configuration.