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

A standard recognizer for shake and tilt gestures. More...

#include <sifteo/motion.h>

Public Types

enum  ChangeFlags {
  Shake_Begin = 1 << 0, Shake_End = 1 << 1, Shake_Change = Shake_Begin | Shake_End, Tilt_XNeg = 1 << 2,
  Tilt_XZero = 1 << 3, Tilt_XPos = 1 << 4, Tilt_XChange = Tilt_XNeg | Tilt_XZero | Tilt_XPos, Tilt_YNeg = 1 << 5,
  Tilt_YZero = 1 << 6, Tilt_YPos = 1 << 7, Tilt_YChange = Tilt_YNeg | Tilt_YZero | Tilt_YPos, Tilt_ZNeg = 1 << 8,
  Tilt_ZZero = 1 << 9, Tilt_ZPos = 1 << 10, Tilt_ZChange = Tilt_ZNeg | Tilt_ZZero | Tilt_ZPos, Tilt_Change = Tilt_XChange | Tilt_YChange | Tilt_ZChange
}
 Change flags, returned by update() to indicate what just changed. More...
 

Public Member Functions

void attach (_SYSCubeID id)
 Initialize this TiltShakeRecognizer and attach it to a cube. More...
 
Byte3 physicalTilt () const
 Return the physical tilt reading for the attached cube. More...
 
unsigned update (int latency=kFilterLatency)
 Update the state of the TiltShakeRecognizer. More...
 
Byte3 virtualTilt (Side orientation) const
 Return the virtual tilt reading for the attached cube. More...
 

Public Attributes

MotionBuffer buffer
 The MotionBuffer used by this TiltShakeRecognizer. More...
 
MotionMedian median
 The most recent median data calculated by the TiltShakeRecognizer. More...
 
bool shake
 The most recent binary shake state.
 
Byte3 tilt
 The most recent tilt value. More...
 

Detailed Description

A standard recognizer for shake and tilt gestures.

This class contains a MotionBuffer as well as other state which is necessary to detect the standard tilt and shake gestures. This filter can be updated as a result of an Events::cubeAccelChange event, or once per frame, or even less often. We provide median statistics, as well as simple binary tilt and shake outputs with hysteresis.

Member Function Documentation

void Sifteo::TiltShakeRecognizer::attach ( _SYSCubeID  id)
inline

Initialize this TiltShakeRecognizer and attach it to a cube.

This invokes MotionBuffer::attach(), and resets the state of the TiltShakeRecognizer itself.

Byte3 Sifteo::TiltShakeRecognizer::physicalTilt ( ) const
inline

Return the physical tilt reading for the attached cube.

The resulting vector is oriented with respect to the cube hardware. The underlying tilt state is only updated after an explicit call to update().

unsigned Sifteo::TiltShakeRecognizer::update ( int  latency = kFilterLatency)
inline

Update the state of the TiltShakeRecognizer.

Using data captured in our MotionBuffer, this updates the state of the median filter, and calculates a new tilt and shake state for the attached cube. After this call, the tilt and shake members will contain the latest state.

Parameters
latency(optional) Specifies the duration of the window on which the filter operates. The default is MotionBuffer<>::TICK_HZ / 30, or 1/30th of a second.
Returns
a bitmap of ChangeFlags which describe which changes just occurred.
Byte3 Sifteo::TiltShakeRecognizer::virtualTilt ( Side  orientation) const
inline

Return the virtual tilt reading for the attached cube.

The resulting vector is oriented with respect to the current LCD rotation. The underlying tilt state is only updated after an explicit call to update().

Requires the orientation of the attached cube, which can be obtained via VideoBuffer::orientation().

Member Data Documentation

MotionBuffer Sifteo::TiltShakeRecognizer::buffer

The MotionBuffer used by this TiltShakeRecognizer.

This is part of the TiltShakeRecognizer class in order to make the common use case convenient, but it may also be used directly if your application must process raw motion data as well as these standard gestures.

MotionMedian Sifteo::TiltShakeRecognizer::median

The most recent median data calculated by the TiltShakeRecognizer.

This contains the results of the intermediate median, minimum, and maximum statistics as calculated during update(). If your application needs to perform additional processing on the motion data, these results are available at no extra cost.

Byte3 Sifteo::TiltShakeRecognizer::tilt

The most recent tilt value.

Each axis is -1, 0, or +1. The coordinate system is identical to that used by CubeID::accel().


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