PebbleOS
Loading...
Searching...
No Matches
Enumerations | Functions
Compass

Magnetometer-based compass heading. More...

Enumerations

enum  MagCalStatus { MagCalStatusNoSolution , MagCalStatusSavedSampleMatch , MagCalStatusNewSolutionAvail , MagCalStatusNewLockedSolutionAvail }
 Result of feeding a sample to the hard iron calibration. More...
 

Functions

void ecompass_service_init (void)
 Register the compass with the event service.
 
void ecompass_service_handle (void)
 Process a new magnetometer sample.
 
void ecompass_handle_battery_state_change_event (PreciseBatteryChargeState new_state)
 Handle a battery state change.
 
MagCalStatus ecomp_corr_add_raw_mag_sample (int16_t *sample, int16_t *saved_corr, int16_t *new_corr)
 Feed a raw magnetometer sample to the hard iron calibration.
 
void ecomp_corr_reset (void)
 Drop the samples collected by ecomp_corr_add_raw_mag_sample() and reset its state.
 
bool sys_ecompass_service_subscribed (void)
 Check whether the current task is subscribed to the compass.
 
void sys_ecompass_get_last_heading (CompassHeadingData *data)
 Get the last published heading.
 

Detailed Description

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.

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ 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
sampleRaw sample, 3 axes.
saved_corrPreviously saved correction, 3 axes, or NULL if none.
[out]new_corrCorrection found, 3 axes; valid unless MagCalStatusNoSolution is returned.
Returns
Calibration status.

◆ ecomp_corr_reset()

void ecomp_corr_reset ( void  )
extern

Drop the samples collected by ecomp_corr_add_raw_mag_sample() and reset its state.

◆ ecompass_handle_battery_state_change_event()

void ecompass_handle_battery_state_change_event ( PreciseBatteryChargeState  new_state)
extern

Handle a battery state change.

Plugging the charger invalidates the calibration; unplugging it restarts calibration.

Parameters
new_stateNew 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()

void sys_ecompass_get_last_heading ( CompassHeadingData *  data)

Get the last published heading.

Parameters
[out]dataHeading 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.