Shares the accelerometer between subscribers.
More...
|
| 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.
|
| |
| void | accel_manager_remove_task_subscriptions (PebbleTask task) |
| | Remove every subscription that delivers its data to task.
|
| |
| 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, uint32_t *generation) |
| | Get the number of samples currently in a subscription's buffer.
|
| |
| bool | sys_accel_manager_consume_samples (AccelManagerState *state, uint32_t samples, uint32_t generation, bool *more) |
| | Finish handling a data callback, so the next one can be posted.
|
| |
| 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.
|
| |
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.
◆ AccelDataReadyCallback
| typedef void(* AccelDataReadyCallback) (void *context) |
Called when a subscriber's sample buffer is full.
No further callback is posted until sys_accel_manager_consume_samples() is called, so each call must end with one, even of 0 samples, unless the subscription has been dropped meanwhile. It handles the next batch itself while the consume reports more. The buffer can hold fewer samples than requested if it was changed meanwhile.
- Parameters
-
◆ AccelManagerState
Opaque accelerometer subscription.
◆ 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_sensitivity | true 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
-
| on | true 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_remove_task_subscriptions()
| void accel_manager_remove_task_subscriptions |
( |
PebbleTask |
task | ) |
|
Remove every subscription that delivers its data to task.
- Parameters
-
| task | Task whose subscriptions to remove. |
◆ 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
-
| state | Subscription to reconfigure. |
| min_rate_mHz | Lowest 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
-
| enabled | true 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_percent | Sensitivity from 0 (least) to 100 (most sensitive). |
◆ sys_accel_manager_consume_samples()
| bool sys_accel_manager_consume_samples |
( |
AccelManagerState * |
state, |
|
|
uint32_t |
samples, |
|
|
uint32_t |
generation, |
|
|
bool * |
more |
|
) |
| |
Finish handling a data callback, so the next one can be posted.
With the current generation and samples above 0, the buffer is emptied and samples not consumed are dropped. With samples 0 or an older generation, the buffer is kept.
- Parameters
-
| state | Subscription. |
| samples | Number of samples processed by the subscriber. |
| generation | Generation from sys_accel_manager_get_num_samples(). |
| [out] | more | true if the refilled buffer already holds the next batch. The running callback handles it, since no new one is posted for it. |
- Returns
- false if
samples is from the current generation and didn't match the number of buffered samples.
◆ sys_accel_manager_data_subscribe()
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
-
| rate | Sampling rate. |
| data_cb | Callback invoked when data is available. |
| context | Context passed to data_cb. |
| handler_task | Task on which data_cb runs: App, Worker, KernelMain, SysWorkq or SysWorkqHigh. |
- Returns
- Subscription allocated on the kernel heap; free it with sys_accel_manager_data_unsubscribe().
◆ sys_accel_manager_data_unsubscribe()
Remove a subscription and free it.
- Parameters
-
| state | Subscription to remove. |
- Returns
- true if a data callback was posted and hasn't been consumed yet, including one running.
◆ 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, |
|
|
uint32_t * |
generation |
|
) |
| |
Get the number of samples currently in a subscription's buffer.
- Parameters
-
- 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_data | Latest sample. |
- Returns
- 0 on success, nonzero if the driver failed to read a sample.
◆ sys_accel_manager_set_sample_buffer()
Set the buffer that receives a subscription's samples.
Empties the buffer and bumps its generation. An event already out stays out until its consume, which then sees the new generation.
- Parameters
-
| state | Subscription. |
| buffer | Buffer of at least samples_per_update samples, owned by the caller. Can be NULL when samples_per_update is 0. |
| samples_per_update | Samples 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
-
| 0 | Success. |
| -1 | samples_per_update is too large. |
◆ sys_accel_manager_set_sampling_rate()
Change the sampling rate of a subscription.
Jitter-inducing subsampling may be used to reach the requested rate.
- Parameters
-
| state | Subscription to reconfigure. |
| rate | New sampling rate. |
- Return values
-
| 0 | Success. |
| -1 | rate is not one of the AccelSamplingRate values. |