Timer

class brainstem.stem.Timer(module, index)[source]

Schedules events to occur at future times.

Reflex routines can be written which will be executed upon expiration of the timer entity. The timer can be set to fire only once, or to repeat at a certain interval.

Useful Constants:
  • SINGLE_SHOT_MODE (0)

  • REPEAT_MODE (1)

  • DEFAULT_MODE (SINGLE_SHOT_MODE)

getExpiration()[source]

Get the currently set expiration time in microseconds.

This is not a “live” timer. That is, it shows the expiration time originally set with setExpiration; it does not “tick down” to show the time remaining before expiration.

Returns

Return result object with NO_ERROR set and the timer expiration in uSeconds in the Result.value or an Error.

Return type

Result

getMode()[source]

Get the mode of the timer.

Valid timer modes are single mode and repeat mode.

Returns

Return result object with NO_ERROR set and the timer mode either single (0) or repeat (1) in the Result.value or an Error.

Return type

Result

setExpiration(usecDuration)[source]

Set the expiration time for the timer entity.

When the timer expires, it will fire the associated timer[index]() reflex.

Parameters

usecDuration (int) – The duration before timer expiration in microseconds.

Returns

Return NO_ERROR on success, or one of the common

sets of return error codes on failure.

Return type

Result.error

setMode(mode)[source]

Set the mode of the timer.

Parameters

mode (int) – The mode of the timer. aTIMER_MODE_REPEAT or aTIMER_MODE_SINGLE.

Returns

Return NO_ERROR on success, or one of the common

sets of return error codes on failure.

Return type

Result.error