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
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
-
handler | A callback to be executed on accelerometer data events |
samples_per_update | the 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.
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
-
handler | A callback to be executed on accelerometer data events |
samples_per_update | the number of samples to buffer, between 0 and 25. |
Peek at the last recorded reading.
- Parameters
-
[out] | data | a 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_samples | the number of samples to buffer, between 0 and 25. |
Change the accelerometer sampling rate.
- Parameters
-
rate | The sampling rate in Hz (10Hz, 25Hz, 50Hz, and 100Hz possible) |
Subscribe to the accelerometer tap event service. Once subscribed, the handler gets called on every tap event emitted by the accelerometer.
- Parameters
-
handler | A 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.
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 |
A single accelerometer sample for all three axes.
Data Fields |
int16_t |
x |
acceleration along the x axis |
int16_t |
y |
acceleration along the y axis |
int16_t |
z |
acceleration along the z axis |
Callback type for accelerometer data events.
- Parameters
-
data | Pointer to the collected accelerometer samples. |
num_samples | the number of samples stored in data. |
Callback type for accelerometer raw data events.
- Parameters
-
data | Pointer to the collected accelerometer samples. |
num_samples | the number of samples stored in data. |
timestamp | the timestamp, in ms, of the first sample. |
typedef void(* AccelTapHandler)(AccelAxisType axis, int32_t direction) |
Callback type for accelerometer tap events.
- Parameters
-
axis | the axis on which a tap was registered (x, y, or z) |
direction | the direction (-1 or +1) of the tap |
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
|