pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Moddable API (Alloy)
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • Alloy
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AlarmService
      • AppFocusService
      • BacklightService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
      • TouchService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Gesture Recognizers
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • Speaker
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Worker
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

AccelerometerService

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.

Function Documentation

int accel_service_peek(AccelData * data)

Peek at the last recorded reading.

Note

Cannot be used when subscribed to accelerometer data events.

Parameters

data (out)

a pointer to a pre-allocated AccelData item

Returns

-1 if the accel is not running

-2 if subscribed to accelerometer events.

int accel_service_set_sampling_rate(AccelSamplingRate rate)

Change the accelerometer sampling rate.

Parameters

rate

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

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.

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

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.

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

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.

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

handler

A callback to be executed on accelerometer data events

samples_per_update

the number of samples to buffer, between 0 and 25.

Data Structure Documentation

struct AccelData

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

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

bool did_vibrate

true if the watch vibrated when this sample was collected

uint64_t timestamp

timestamp, in milliseconds

struct AccelRawData

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

Enum Documentation

enum AccelAxisType

Enumerated values defining the three accelerometer axes.

Enumerators

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.

enum AccelSamplingRate

Valid accelerometer sampling rates, in Hz.

Enumerators

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

Typedef Documentation

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

Callback type for accelerometer data events.

Parameters

data

Pointer to the collected accelerometer samples.

num_samples

the number of samples stored in data.

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

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

Need some help?

Functions

  • accel_service_peek
  • accel_service_set_sampling_rate
  • accel_service_set_samples_per_update
  • accel_data_service_subscribe
  • accel_data_service_unsubscribe
  • accel_tap_service_subscribe
  • accel_tap_service_unsubscribe
  • accel_raw_data_service_subscribe

Data Structures

  • AccelData
  • AccelRawData

Enums

  • AccelAxisType
  • AccelSamplingRate

Typedefs

  • AccelDataHandler
  • AccelRawDataHandler
  • AccelTapHandler

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

Ask on the developer forum.