Shares the accelerometer between subscribers.
More...
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.
- 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_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 |
|
) |
| |
Release a subscription's buffered samples and refill its buffer.
Samples not consumed are dropped.
- Parameters
-
| state | Subscription. |
| samples | Number of samples processed by the subscriber. |
- Returns
- true if
samples matched 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, KernelBackground or NewTimers. |
- 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 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
-
| state | Subscription. |
| [out] | timestamp_ms | Timestamp 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_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.
- Parameters
-
| state | Subscription. |
| buffer | Buffer of at least samples_per_update samples, owned by the caller. |
| 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. |