Magnetometer-based compass heading.
More...
Magnetometer-based compass heading.
While a process subscribes to PEBBLE_COMPASS_DATA_EVENT, the magnetometer and accelerometer are sampled and a tilt-compensated magnetic heading is published with each event. Hard iron correction is calibrated on the fly, first at a higher sampling rate for a few minutes; calibration is suspended while the charger is plugged in and restarted once unplugged. The heading types shared with the app SDK (CompassHeading, CompassStatus, CompassHeadingData) are documented in the SDK.
◆ MagCalStatus
Result of feeding a sample to the hard iron calibration.
| Enumerator |
|---|
| MagCalStatusNoSolution | No new correction estimate available.
|
| MagCalStatusSavedSampleMatch | Several fits close to the saved correction were found.
|
| MagCalStatusNewSolutionAvail | A new correction estimate is available.
|
| MagCalStatusNewLockedSolutionAvail | Several fits close to one another were found; the correction is their average.
|
◆ ecomp_corr_add_raw_mag_sample()
| MagCalStatus ecomp_corr_add_raw_mag_sample |
( |
int16_t * |
sample, |
|
|
int16_t * |
saved_corr, |
|
|
int16_t * |
new_corr |
|
) |
| |
|
extern |
Feed a raw magnetometer sample to the hard iron calibration.
Selects well-spread points among the samples and fits a sphere to them; its origin is the hard iron correction.
- Parameters
-
| sample | Raw sample, 3 axes. |
| saved_corr | Previously saved correction, 3 axes, or NULL if none. |
| [out] | new_corr | Correction found, 3 axes; valid unless MagCalStatusNoSolution is returned. |
- Returns
- Calibration status.
◆ ecomp_corr_reset()
| void ecomp_corr_reset |
( |
void |
| ) |
|
|
extern |
◆ ecompass_handle_battery_state_change_event()
Handle a battery state change.
Plugging the charger invalidates the calibration; unplugging it restarts calibration.
- Parameters
-
| new_state | New battery state. |
◆ ecompass_service_handle()
| void ecompass_service_handle |
( |
void |
| ) |
|
|
extern |
Process a new magnetometer sample.
Called from KernelMain when the magnetometer has data. Updates the calibration and posts a PEBBLE_COMPASS_DATA_EVENT with the new heading.
◆ ecompass_service_init()
| void ecompass_service_init |
( |
void |
| ) |
|
|
extern |
Register the compass with the event service.
◆ sys_ecompass_get_last_heading()
Get the last published heading.
- Parameters
-
| [out] | data | Heading and calibration status. |
◆ sys_ecompass_service_subscribed()
| bool sys_ecompass_service_subscribed |
( |
void |
| ) |
|
Check whether the current task is subscribed to the compass.
- Returns
- true if subscribed.