All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
AccelerometerService

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 Examples/watchapps/feature_accel_discs

Function Documentation

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

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

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

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


Data Structure Documentation

struct AccelData

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

Data Fields
bool did_vibrate true if the watch vibrated when this sample was collected
uint64_t timestamp timestamp, in milliseconds
int16_t x acceleration along the x axis
int16_t y acceleration along the y axis
int16_t z acceleration along the z axis

Typedef Documentation

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

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.

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