Pebble Foundation Classes  0.2.0
C++ for Pebble
AccelerometerService

Using the Pebble accelerometer. More...

Collaboration diagram for AccelerometerService:

Typedefs

typedef void(* AccelDataHandler) (AccelData *data, uint32_t num_samples)
 
typedef void(* AccelRawDataHandler) (AccelRawData *data, uint32_t num_samples, uint64_t timestamp)
 
typedef void(* AccelTapHandler) (AccelAxisType axis, int32_t direction)
 
typedef void(* AccelDataHandler) (AccelData *data, uint32_t num_samples)
 
typedef void(* AccelRawDataHandler) (AccelRawData *data, uint32_t num_samples, uint64_t timestamp)
 
typedef void(* AccelTapHandler) (AccelAxisType axis, int32_t direction)
 

Enumerations

enum  AccelAxisType {
  ACCEL_AXIS_X = 0, ACCEL_AXIS_Y = 1, ACCEL_AXIS_Z = 2, ACCEL_AXIS_X = 0,
  ACCEL_AXIS_Y = 1, ACCEL_AXIS_Z = 2
}
 Enumerated values defining the three accelerometer axes. More...
 
enum  AccelSamplingRate {
  ACCEL_SAMPLING_10HZ = 10, ACCEL_SAMPLING_25HZ = 25, ACCEL_SAMPLING_50HZ = 50, ACCEL_SAMPLING_100HZ = 100,
  ACCEL_SAMPLING_10HZ = 10, ACCEL_SAMPLING_25HZ = 25, ACCEL_SAMPLING_50HZ = 50, ACCEL_SAMPLING_100HZ = 100
}
 Valid accelerometer sampling rates, in Hz. More...
 
enum  AccelAxisType {
  ACCEL_AXIS_X = 0, ACCEL_AXIS_Y = 1, ACCEL_AXIS_Z = 2, ACCEL_AXIS_X = 0,
  ACCEL_AXIS_Y = 1, ACCEL_AXIS_Z = 2
}
 Enumerated values defining the three accelerometer axes. More...
 
enum  AccelSamplingRate {
  ACCEL_SAMPLING_10HZ = 10, ACCEL_SAMPLING_25HZ = 25, ACCEL_SAMPLING_50HZ = 50, ACCEL_SAMPLING_100HZ = 100,
  ACCEL_SAMPLING_10HZ = 10, ACCEL_SAMPLING_25HZ = 25, ACCEL_SAMPLING_50HZ = 50, ACCEL_SAMPLING_100HZ = 100
}
 Valid accelerometer sampling rates, in Hz. More...
 

Functions

struct __attribute__ ((__packed__))
 A single accelerometer sample for all three axes. More...
 
int accel_service_peek (AccelData *data)
 
int accel_service_set_sampling_rate (AccelSamplingRate rate)
 
int accel_service_set_samples_per_update (uint32_t num_samples)
 
void accel_data_service_subscribe (uint32_t samples_per_update, AccelDataHandler handler)
 
void accel_data_service_unsubscribe (void)
 
void accel_tap_service_subscribe (AccelTapHandler handler)
 
void accel_tap_service_unsubscribe (void)
 
void accel_raw_data_service_subscribe (uint32_t samples_per_update, AccelRawDataHandler handler)
 

Variables

 AccelData
 
 AccelRawData
 
 AccelData
 
 AccelRawData
 

Detailed Description

Using the Pebble accelerometer.

The AccelerometerService enables the Pebble accelerometer to detect taps, perform measures at a given frequency, and transmit samples in batches to save CPU time and processing.

For available code samples, see the feature-accel-discs example app.

Typedef Documentation

◆ AccelDataHandler [1/2]

typedef void(* AccelDataHandler) (AccelData *data, uint32_t num_samples)

Callback type for accelerometer data events

Parameters
dataPointer to the collected accelerometer samples.
num_samplesthe number of samples stored in data.

◆ AccelDataHandler [2/2]

typedef void(* AccelDataHandler) (AccelData *data, uint32_t num_samples)

Callback type for accelerometer data events

Parameters
dataPointer to the collected accelerometer samples.
num_samplesthe number of samples stored in data.

◆ AccelRawDataHandler [1/2]

typedef void(* AccelRawDataHandler) (AccelRawData *data, uint32_t num_samples, uint64_t timestamp)

Callback type for accelerometer raw data events

Parameters
dataPointer to the collected accelerometer samples.
num_samplesthe number of samples stored in data.
timestampthe timestamp, in ms, of the first sample.

◆ AccelRawDataHandler [2/2]

typedef void(* AccelRawDataHandler) (AccelRawData *data, uint32_t num_samples, uint64_t timestamp)

Callback type for accelerometer raw data events

Parameters
dataPointer to the collected accelerometer samples.
num_samplesthe number of samples stored in data.
timestampthe timestamp, in ms, of the first sample.

◆ AccelTapHandler [1/2]

typedef void(* AccelTapHandler) (AccelAxisType axis, int32_t direction)

Callback type for accelerometer tap events

Parameters
axisthe axis on which a tap was registered (x, y, or z)
directionthe direction (-1 or +1) of the tap

◆ AccelTapHandler [2/2]

typedef void(* AccelTapHandler) (AccelAxisType axis, int32_t direction)

Callback type for accelerometer tap events

Parameters
axisthe axis on which a tap was registered (x, y, or z)
directionthe direction (-1 or +1) of the tap

Enumeration Type Documentation

◆ AccelAxisType [1/2]

Enumerated values defining the three accelerometer axes.

Enumerator
ACCEL_AXIS_X 

Accelerometer's X axis. The positive direction along the X axis goes toward the right of the watch.

ACCEL_AXIS_Y 

Accelerometer's Y axis. The positive direction along the Y axis goes toward the top of the watch.

ACCEL_AXIS_Z 

Accelerometer's Z axis. The positive direction along the Z axis goes vertically out of the watchface.

ACCEL_AXIS_X 

Accelerometer's X axis. The positive direction along the X axis goes toward the right of the watch.

ACCEL_AXIS_Y 

Accelerometer's Y axis. The positive direction along the Y axis goes toward the top of the watch.

ACCEL_AXIS_Z 

Accelerometer's Z axis. The positive direction along the Z axis goes vertically out of the watchface.

◆ AccelAxisType [2/2]

Enumerated values defining the three accelerometer axes.

Enumerator
ACCEL_AXIS_X 

Accelerometer's X axis. The positive direction along the X axis goes toward the right of the watch.

ACCEL_AXIS_Y 

Accelerometer's Y axis. The positive direction along the Y axis goes toward the top of the watch.

ACCEL_AXIS_Z 

Accelerometer's Z axis. The positive direction along the Z axis goes vertically out of the watchface.

ACCEL_AXIS_X 

Accelerometer's X axis. The positive direction along the X axis goes toward the right of the watch.

ACCEL_AXIS_Y 

Accelerometer's Y axis. The positive direction along the Y axis goes toward the top of the watch.

ACCEL_AXIS_Z 

Accelerometer's Z axis. The positive direction along the Z axis goes vertically out of the watchface.

◆ AccelSamplingRate [1/2]

Valid accelerometer sampling rates, in Hz.

Enumerator
ACCEL_SAMPLING_10HZ 

10 HZ sampling rate

ACCEL_SAMPLING_25HZ 

25 HZ sampling rate [Default]

ACCEL_SAMPLING_50HZ 

50 HZ sampling rate

ACCEL_SAMPLING_100HZ 

100 HZ sampling rate

ACCEL_SAMPLING_10HZ 

10 HZ sampling rate

ACCEL_SAMPLING_25HZ 

25 HZ sampling rate [Default]

ACCEL_SAMPLING_50HZ 

50 HZ sampling rate

ACCEL_SAMPLING_100HZ 

100 HZ sampling rate

◆ AccelSamplingRate [2/2]

Valid accelerometer sampling rates, in Hz.

Enumerator
ACCEL_SAMPLING_10HZ 

10 HZ sampling rate

ACCEL_SAMPLING_25HZ 

25 HZ sampling rate [Default]

ACCEL_SAMPLING_50HZ 

50 HZ sampling rate

ACCEL_SAMPLING_100HZ 

100 HZ sampling rate

ACCEL_SAMPLING_10HZ 

10 HZ sampling rate

ACCEL_SAMPLING_25HZ 

25 HZ sampling rate [Default]

ACCEL_SAMPLING_50HZ 

50 HZ sampling rate

ACCEL_SAMPLING_100HZ 

100 HZ sampling rate

Function Documentation

◆ __attribute__()

struct __attribute__ ( (__packed__)  )

A single accelerometer sample for all three axes.

A single accelerometer sample for all three axes including timestamp and vibration rumble status.

Data structure for one serialized key/value tuple

Note
The structure is variable length! The length depends on the value data that the tuple contains.

acceleration along the x axis

acceleration along the y axis

acceleration along the z axis

true if the watch vibrated when this sample was collected

timestamp, in milliseconds

acceleration along the x axis

acceleration along the y axis

acceleration along the z axis

The key

The type of data that the .value fields contains.

The length of .value in bytes

The value itself.

The different union fields are provided for convenience, avoiding the need for manual casts.

Note
The array length is of incomplete length on purpose, to facilitate variable length data and because a data length of zero is valid.
Important: The integers are little endian!

The byte array value. Valid when .type is TUPLE_BYTE_ARRAY.

The C-string value. Valid when .type is TUPLE_CSTRING.

The 8-bit unsigned integer value. Valid when .type is TUPLE_UINT and .length is 1 byte.

The 16-bit unsigned integer value. Valid when .type is TUPLE_UINT and .length is 2 byte.

The 32-bit unsigned integer value. Valid when .type is TUPLE_UINT and .length is 4 byte.

The 8-bit signed integer value. Valid when .type is TUPLE_INT and .length is 1 byte.

The 16-bit signed integer value. Valid when .type is TUPLE_INT and .length is 2 byte.

The 32-bit signed integer value. Valid when .type is TUPLE_INT and .length is 4 byte.

acceleration along the x axis

acceleration along the y axis

acceleration along the z axis

true if the watch vibrated when this sample was collected

timestamp, in milliseconds

acceleration along the x axis

acceleration along the y axis

acceleration along the z axis

◆ accel_data_service_subscribe()

void accel_data_service_subscribe ( uint32_t  samples_per_update,
AccelDataHandler  handler 
)

Subscribe to the accelerometer data event service. Once subscribed, the handler gets called every time there are new accelerometer samples available.

Note
Cannot use accel_service_peek() when subscribed to accelerometer data events.
Parameters
handlerA callback to be executed on accelerometer data events
samples_per_updatethe number of samples to buffer, between 0 and 25.

◆ accel_data_service_unsubscribe()

void accel_data_service_unsubscribe ( void  )

Unsubscribe from the accelerometer data event service. Once unsubscribed, the previously registered handler will no longer be called.

◆ accel_raw_data_service_subscribe()

void accel_raw_data_service_subscribe ( uint32_t  samples_per_update,
AccelRawDataHandler  handler 
)

Subscribe to the accelerometer raw data event service. Once subscribed, the handler gets called every time there are new accelerometer samples available.

Note
Cannot use accel_service_peek() when subscribed to accelerometer data events.
Parameters
handlerA callback to be executed on accelerometer data events
samples_per_updatethe number of samples to buffer, between 0 and 25.

◆ accel_service_peek()

int accel_service_peek ( AccelData *  data)

Peek at the last recorded reading.

Parameters
[out]dataa pointer to a pre-allocated AccelData item
Note
Cannot be used when subscribed to accelerometer data events.
Returns
-1 if the accel is not running
-2 if subscribed to accelerometer events.

◆ accel_service_set_samples_per_update()

int accel_service_set_samples_per_update ( uint32_t  num_samples)

Change the number of samples buffered between each accelerometer data event

Parameters
num_samplesthe number of samples to buffer, between 0 and 25.

◆ accel_service_set_sampling_rate()

int accel_service_set_sampling_rate ( AccelSamplingRate  rate)

Change the accelerometer sampling rate.

Parameters
rateThe sampling rate in Hz (10Hz, 25Hz, 50Hz, and 100Hz possible)

◆ accel_tap_service_subscribe()

void accel_tap_service_subscribe ( AccelTapHandler  handler)

Subscribe to the accelerometer tap event service. Once subscribed, the handler gets called on every tap event emitted by the accelerometer.

Parameters
handlerA callback to be executed on tap event

◆ accel_tap_service_unsubscribe()

void accel_tap_service_unsubscribe ( void  )

Unsubscribe from the accelerometer tap event service. Once unsubscribed, the previously registered handler will no longer be called.