Utility for reading low-level motion events from a MotionBuffer. More...
#include <sifteo/motion.h>
Public Member Functions | |
Byte3 | accel () const |
Return the acceleration sample at the iterator's current position. More... | |
void | adjustTicks (int32_t value) |
Add a value to the tick counter. More... | |
MotionIterator (_SYSMotionBuffer *buffer) | |
Construct a new MotionIterator, attached to the provided MotionBuffer. More... | |
bool | next () |
Advance to the next motion sample, if possible. More... | |
float | seconds () const |
Return the timestamp at the iterator's current position, in seconds. More... | |
void | setTicks (uint32_t value) |
Modify the tick counter. | |
uint32_t | ticks () const |
Return the timestamp at the iterator's current position, in ticks. More... | |
Static Public Attributes | |
static const unsigned | TICK_HZ = MotionBuffer<>::TICK_HZ |
Reciprocal of the MotionBuffer's timestamp unit, in Hertz. | |
static const unsigned | TICK_NS = MotionBuffer<>::TICK_NS |
Duration of the MotionBuffer's timestamp unit, in nanoseconds. | |
static const unsigned | TICK_US = MotionBuffer<>::TICK_US |
Duration of the MotionBuffer's timestamp unit, in microseconds. | |
Utility for reading low-level motion events from a MotionBuffer.
This object keeps track of the state necessary to extract a stream of motion events from a MotionBuffer. It manages the FIFO head pointer, and keeps track of the current time.
After it is created, the iterator has an indeterminate state. It may be advanced to the next available motion sample with next().
|
inline |
Construct a new MotionIterator, attached to the provided MotionBuffer.
The read pointer is initialized to be equal to the system's write pointer, meaning that next() will return false until the first new acceleration sample is collected after this iterator has been constructed.
|
inline |
Return the acceleration sample at the iterator's current position.
The units and coordinate system are identical to that of CubeID::accel().
|
inline |
Add a value to the tick counter.
This helps with use cases where you'd like to use the tick counter as an accumulator for sample rate conversion. If you want to collect a sample every N ticks, for example, you can wait until ticks() is at least N, then use adjustTicks(-N) to remove that span of time from the accumulator.
|
inline |
Advance to the next motion sample, if possible.
If another sample is available, advances to it and returns true. If no more samples are ready, returns false.
|
inline |
Return the timestamp at the iterator's current position, in seconds.
This is like ticks(), except we scale the result to seconds, and return it as a floating point number. Note that this has less precision than ticks(), and there is no good way to handle roll-over, so it should only be used if you know you won't be sampling data for a very long period of time.
|
inline |
Return the timestamp at the iterator's current position, in ticks.
This timestamp starts out at zero, and increases at each call to next(). It is a 32-bit counter, in units of ticks as described by TICK_NS, TICK_US, and TICK_HZ.
This timestamp counter will roll over after approximately 12 days.
Sifteo SDK v1.1.0 (see all versions)
Last updated Tue Dec 23 2014, by Doxygen