PebbleOS
Loading...
Searching...
No Matches
Typedefs | Functions
Accelerometer manager

Shares the accelerometer between subscribers. More...

Typedefs

typedef void(* AccelDataReadyCallback) (void *context)
 Called when a subscriber's sample buffer is full.
 
typedef struct AccelManagerState AccelManagerState
 Opaque accelerometer subscription.
 

Functions

uint32_t sys_accel_manager_get_max_samples_per_update (void)
 Get the maximum number of samples that can be batched per update.
 
void accel_manager_init (void)
 Initialize the accelerometer manager.
 
void accel_manager_enable (bool on)
 Enable or disable the accelerometer.
 
void accel_manager_set_motion_backlight_enabled (bool enabled)
 Enable or disable the kernel's shake subscription for the motion backlight.
 
int sys_accel_manager_peek (AccelData *accel_data)
 Read the current accelerometer sample.
 
AccelManagerState * sys_accel_manager_data_subscribe (AccelSamplingRate rate, AccelDataReadyCallback data_cb, void *context, PebbleTask handler_task)
 Subscribe to accelerometer data.
 
bool sys_accel_manager_data_unsubscribe (AccelManagerState *state)
 Remove a subscription and free it.
 
int sys_accel_manager_set_sampling_rate (AccelManagerState *state, AccelSamplingRate rate)
 Change the sampling rate of a subscription.
 
uint32_t accel_manager_set_jitterfree_sampling_rate (AccelManagerState *state, uint32_t min_rate_mHz)
 Use the lowest jitter-free sampling rate of at least min_rate_mHz.
 
int sys_accel_manager_set_sample_buffer (AccelManagerState *state, AccelRawData *buffer, uint32_t samples_per_update)
 Set the buffer that receives a subscription's samples.
 
uint32_t sys_accel_manager_get_num_samples (AccelManagerState *state, uint64_t *timestamp_ms)
 Get the number of samples currently in a subscription's buffer.
 
bool sys_accel_manager_consume_samples (AccelManagerState *state, uint32_t samples)
 Release a subscription's buffered samples and refill its buffer.
 
void accel_enable_high_sensitivity (bool high_sensitivity)
 Make shake detection sensitive enough to trigger on small movements.
 
void accel_manager_update_sensitivity (uint8_t sensitivity_percent)
 Set the motion sensitivity from the user preference.
 
bool accel_is_idle (void)
 Check whether the watch has been idle.
 

Detailed Description

Shares the accelerometer between subscribers.

Samples from the accelerometer driver are queued in a shared buffer and copied, subsampled to each subscriber's rate, into a buffer the subscriber provides. Once a subscriber's buffer holds the requested number of samples, its callback runs on the task chosen at subscription. The manager also arms shake and double tap detection while event service subscribers exist.

The sys_ functions are syscalls usable from unprivileged code; subscription handles passed in from userspace are validated against the subscriber list.

Typedef Documentation

◆ AccelDataReadyCallback

typedef void(* AccelDataReadyCallback) (void *context)

Called when a subscriber's sample buffer is full.

Parameters
contextContext given to sys_accel_manager_data_subscribe().

◆ AccelManagerState

Opaque accelerometer subscription.

Function Documentation

◆ accel_enable_high_sensitivity()

void accel_enable_high_sensitivity ( bool  high_sensitivity)

Make shake detection sensitive enough to trigger on small movements.

Used to leave low power mode as soon as a stationary watch is moved.

Parameters
high_sensitivitytrue for high sensitivity, false for the normal setting.

◆ accel_is_idle()

bool accel_is_idle ( void  )

Check whether the watch has been idle.

Compares the last read sample with the position captured on the hourly analytics heartbeat, without reading the hardware.

Returns
true if no significant movement was seen since then.

◆ accel_manager_enable()

void accel_manager_enable ( bool  on)

Enable or disable the accelerometer.

While disabled, sampling and shake/double tap detection are stopped; enabling restores the configuration required by the current subscribers.

Parameters
ontrue to enable, false to disable.

◆ accel_manager_init()

void accel_manager_init ( void  )

Initialize the accelerometer manager.

Registers the shake and double tap event services and applies the saved motion sensitivity.

◆ accel_manager_set_jitterfree_sampling_rate()

uint32_t accel_manager_set_jitterfree_sampling_rate ( AccelManagerState *  state,
uint32_t  min_rate_mHz 
)

Use the lowest jitter-free sampling rate of at least min_rate_mHz.

Only 12.5 Hz is currently supported; requesting more asserts.

Parameters
stateSubscription to reconfigure.
min_rate_mHzLowest acceptable sampling rate, in millihertz.
Returns
Resulting sampling rate in millihertz, 0 if no rate is high enough.

◆ accel_manager_set_motion_backlight_enabled()

void accel_manager_set_motion_backlight_enabled ( bool  enabled)

Enable or disable the kernel's shake subscription for the motion backlight.

When disabled, shake detection is only active if apps have subscribed.

Parameters
enabledtrue to subscribe, false to unsubscribe.

◆ accel_manager_update_sensitivity()

void accel_manager_update_sensitivity ( uint8_t  sensitivity_percent)

Set the motion sensitivity from the user preference.

Only has an effect on accelerometers that support adjustable sensitivity.

Parameters
sensitivity_percentSensitivity from 0 (least) to 100 (most sensitive).

◆ sys_accel_manager_consume_samples()

bool sys_accel_manager_consume_samples ( AccelManagerState *  state,
uint32_t  samples 
)

Release a subscription's buffered samples and refill its buffer.

Samples not consumed are dropped.

Parameters
stateSubscription.
samplesNumber of samples processed by the subscriber.
Returns
true if samples matched the number of buffered samples.

◆ sys_accel_manager_data_subscribe()

AccelManagerState * sys_accel_manager_data_subscribe ( AccelSamplingRate  rate,
AccelDataReadyCallback  data_cb,
void *  context,
PebbleTask  handler_task 
)

Subscribe to accelerometer data.

data_cb is called with context on handler_task whenever the buffer set with sys_accel_manager_set_sample_buffer() holds the requested number of samples. Unprivileged callers always get the callback on their own task (App or Worker).

Parameters
rateSampling rate.
data_cbCallback invoked when data is available.
contextContext passed to data_cb.
handler_taskTask on which data_cb runs: App, Worker, KernelMain, KernelBackground or NewTimers.
Returns
Subscription allocated on the kernel heap; free it with sys_accel_manager_data_unsubscribe().

◆ sys_accel_manager_data_unsubscribe()

bool sys_accel_manager_data_unsubscribe ( AccelManagerState *  state)

Remove a subscription and free it.

Parameters
stateSubscription to remove.
Returns
true if a data callback had been posted and not yet processed.

◆ sys_accel_manager_get_max_samples_per_update()

uint32_t sys_accel_manager_get_max_samples_per_update ( void  )

Get the maximum number of samples that can be batched per update.

Returns
Depth of the accelerometer's hardware FIFO, in samples.

◆ sys_accel_manager_get_num_samples()

uint32_t sys_accel_manager_get_num_samples ( AccelManagerState *  state,
uint64_t *  timestamp_ms 
)

Get the number of samples currently in a subscription's buffer.

Parameters
stateSubscription.
[out]timestamp_msTimestamp of the first buffered sample, in milliseconds.
Returns
Number of buffered samples.

◆ sys_accel_manager_peek()

int sys_accel_manager_peek ( AccelData *  accel_data)

Read the current accelerometer sample.

Parameters
[out]accel_dataLatest sample.
Returns
0 on success, nonzero if the driver failed to read a sample.

◆ sys_accel_manager_set_sample_buffer()

int sys_accel_manager_set_sample_buffer ( AccelManagerState *  state,
AccelRawData *  buffer,
uint32_t  samples_per_update 
)

Set the buffer that receives a subscription's samples.

Parameters
stateSubscription.
bufferBuffer of at least samples_per_update samples, owned by the caller.
samples_per_updateSamples to batch before calling the data callback, 0 to drop all data. Must not exceed sys_accel_manager_get_max_samples_per_update().
Return values
0Success.
-1samples_per_update is too large.

◆ sys_accel_manager_set_sampling_rate()

int sys_accel_manager_set_sampling_rate ( AccelManagerState *  state,
AccelSamplingRate  rate 
)

Change the sampling rate of a subscription.

Jitter-inducing subsampling may be used to reach the requested rate.

Parameters
stateSubscription to reconfigure.
rateNew sampling rate.
Return values
0Success.
-1rate is not one of the AccelSamplingRate values.