v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Public Member Functions | Static Public Attributes | List of all members
Sifteo::MotionIterator Class Reference

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.
 

Detailed Description

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().

Constructor & Destructor Documentation

Sifteo::MotionIterator::MotionIterator ( _SYSMotionBuffer *  buffer)
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.

Member Function Documentation

Byte3 Sifteo::MotionIterator::accel ( ) const
inline

Return the acceleration sample at the iterator's current position.

The units and coordinate system are identical to that of CubeID::accel().

void Sifteo::MotionIterator::adjustTicks ( int32_t  value)
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.

bool Sifteo::MotionIterator::next ( )
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.

float Sifteo::MotionIterator::seconds ( ) const
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.

uint32_t Sifteo::MotionIterator::ticks ( ) const
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.


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