COSA
An Object-Oriented Platform for Arduino Programming
|
#include <HMC5883L.hh>
Classes | |
struct | config_t |
struct | data_t |
struct | status_t |
Public Types | |
enum | Bias { NORMAL_BIAS = 0x00, POSITIVE_BIAS = 0x01, NEGATIVE_BIAS = 0x02 } |
enum | Rate { OUTPUT_RATE_0_75_HZ, OUTPUT_RATE_1_5_HZ, OUTPUT_RATE_3_HZ, OUTPUT_RATE_7_5_HZ, OUTPUT_RATE_15_HZ, OUTPUT_RATE_30_HZ, OUTPUT_RATE_75_HZ } |
enum | Avg { SAMPLES_AVG_1, SAMPLES_AVG_2, SAMPLES_AVG_4, SAMPLES_AVG_8 } |
enum | Range { RANGE_0_88_GA, RANGE_1_3_GA, RANGE_1_9_GA, RANGE_2_5_GA, RANGE_4_0_GA, RANGE_4_7_GA, RANGE_5_6_GA, RANGE_8_1_GA } |
enum | Mode { CONTINOUS_MEASUREMENT_MODE, SINGLE_MEASUREMENT_MODE, IDLE_MEASUREMENT_MODE } |
Public Member Functions | |
HMC5883L (uint8_t mode=SLEEP_MODE_IDLE) | |
bool | begin () |
bool | end () |
void | await_mode (uint8_t mode) |
void | bias (Bias bias) |
void | output_rate (Rate rate) |
void | samples_avg (Avg avg) |
void | range (Range range) |
bool | write_config () |
void | heading (data_t &data) const |
bool | mode (Mode mode) |
bool | read_status (status_t &status) |
bool | available () |
bool | sample_heading_request () |
void | await () |
bool | read_heading () |
bool | read_heading (data_t &data) |
bool | is_overflow () const |
void | to_milli_gauss () |
bool | is_async () const |
void | sync_request () |
void | async_request () |
virtual void | on_completion (uint8_t type, int count) |
Protected Types | |
enum | Register { CONFIG = 0x00, MODE = 0x02, OUTPUT = 0x03, STATUS = 0x09, IDENTITY = 0x0a } |
Protected Attributes | |
config_t | m_config |
uint8_t | m_mode |
bool | m_overflow |
data_t | m_output |
uint8_t | m_addr |
bool | m_async |
Static Protected Attributes | |
static const uint16_t | s_gain [] |
Driver for the HMC5883L 3-Axis Digital Compass IC, a vector magnetometer.
The GY-80 10DOF module with pull-up resistors (4K7) for TWI signals and 3V3 internal voltage converter.
Definition at line 57 of file HMC5883L.hh.
enum HMC5883L::Avg |
Enumerator | |
---|---|
SAMPLES_AVG_1 |
Number of averaged samples per output. |
SAMPLES_AVG_2 | |
SAMPLES_AVG_4 | |
SAMPLES_AVG_8 |
Definition at line 78 of file HMC5883L.hh.
enum HMC5883L::Bias |
Configuration Register A (pp. 12).
Enumerator | |
---|---|
NORMAL_BIAS |
Table 6: Measurement Modes. |
POSITIVE_BIAS | |
NEGATIVE_BIAS |
Definition at line 62 of file HMC5883L.hh.
enum HMC5883L::Mode |
Mode Register (pp. 14).
Enumerator | |
---|---|
CONTINOUS_MEASUREMENT_MODE | |
SINGLE_MEASUREMENT_MODE | |
IDLE_MEASUREMENT_MODE |
Definition at line 102 of file HMC5883L.hh.
enum HMC5883L::Range |
Configuration Register B (pp. 13)
Enumerator | |
---|---|
RANGE_0_88_GA |
Table 9: Gain Setting. |
RANGE_1_3_GA | |
RANGE_1_9_GA | |
RANGE_2_5_GA | |
RANGE_4_0_GA | |
RANGE_4_7_GA | |
RANGE_5_6_GA | |
RANGE_8_1_GA |
Definition at line 88 of file HMC5883L.hh.
enum HMC5883L::Rate |
Enumerator | |
---|---|
OUTPUT_RATE_0_75_HZ |
Table 5: Data Output Rates. |
OUTPUT_RATE_1_5_HZ | |
OUTPUT_RATE_3_HZ | |
OUTPUT_RATE_7_5_HZ | |
OUTPUT_RATE_15_HZ | |
OUTPUT_RATE_30_HZ | |
OUTPUT_RATE_75_HZ |
Definition at line 68 of file HMC5883L.hh.
|
protected |
Register List (Table 2, pp 11).
Enumerator | |
---|---|
CONFIG |
Configuration register A, B. |
MODE |
Mode register. |
OUTPUT |
Output data register X, Y, Z. |
STATUS |
Status register. |
IDENTITY |
Identity register(0-2). |
Definition at line 323 of file HMC5883L.hh.
|
inline |
Construct HMC5883L device with bus address(0x1e) (pp. 11).
Definition at line 140 of file HMC5883L.hh.
|
inlineinherited |
|
inline |
Return true(1) if output data is available otherwise false(0).
Definition at line 254 of file HMC5883L.hh.
|
inline |
Wait for measurement to complete. Processor is put to sleep with the mode given by set_sleep_mode() or constructor.
Definition at line 276 of file HMC5883L.hh.
|
inline |
Set await sleep mode.
[in] | mode | power sleep mode. |
Definition at line 169 of file HMC5883L.hh.
bool HMC5883L::begin | ( | ) |
Begin interaction with device. Return true(1) if successful otherwise false(0).
Definition at line 35 of file HMC5883L.cpp.
|
inline |
Set device bias pin configuration. Call write_config() after configuration changes.
[in] | bias | current configuration. |
Definition at line 179 of file HMC5883L.hh.
|
inline |
End interaction with device. Put into idle mode. Return true(1) if successful otherwise false(0).
Definition at line 160 of file HMC5883L.hh.
|
inline |
Get output data from device driver.
[out] | data. |
Definition at line 226 of file HMC5883L.hh.
|
inlineinherited |
|
inline |
Returns true(1) if the latest reading contained an overflow on any of the channels.
Definition at line 308 of file HMC5883L.hh.
bool HMC5883L::mode | ( | Mode | mode | ) |
Set device operation mode and write mode change to device. Return true(1) if successful otherwise false(0). Must be called for each sample in SINGLE_MEASUREMENT_MODE. There is a delay before the output data becomes available from the device (rate setting). Monitor with available() or the ready pin.
[in] | mode | of operation. |
Definition at line 62 of file HMC5883L.cpp.
|
inlinevirtualinherited |
Service completion callback when a read/write has been completed.
[in] | type | event code. |
[in] | count | number of bytes in request. |
Reimplemented in TWI::Slave.
|
inline |
Set device output rates in continous measurement mode. Call write_config() after configuration changes.
[in] | rate | of data output. |
Definition at line 189 of file HMC5883L.hh.
|
inline |
Set gain configuration bits for a given recommended sensor field range. Call write_config() after configuration changes.
[in] | range | gauss. |
Definition at line 209 of file HMC5883L.hh.
bool HMC5883L::read_heading | ( | ) |
Read output data from device. Return true(1) if successful otherwise false(0).
Definition at line 81 of file HMC5883L.cpp.
|
inline |
Read output data from device. Return true(1) if successful otherwise false(0).
[out] | data. |
Definition at line 295 of file HMC5883L.hh.
bool HMC5883L::read_status | ( | status_t & | status | ) |
Read status from device. Return true(1) if successful otherwise false(0).
[out] | status. |
Definition at line 71 of file HMC5883L.cpp.
|
inline |
Issue single measurement. Return true(1) if successful otherwise false(0).
Definition at line 267 of file HMC5883L.hh.
|
inline |
Set number of samples averaged per measurement output. Call write_config() after configuration changes.
[in] | avg | number of samples. |
Definition at line 199 of file HMC5883L.hh.
|
inlineinherited |
void HMC5883L::to_milli_gauss | ( | ) |
Convert the latest reading to milli-gauss using the current gain setting and the gain table.
Definition at line 102 of file HMC5883L.cpp.
bool HMC5883L::write_config | ( | ) |
Write configuration change to device. Return true(1) if successful otherwise false(0). Should be called after configuration changes.
Definition at line 53 of file HMC5883L.cpp.
|
protectedinherited |
|
protectedinherited |
|
protected |
Configuration mirror register.
Definition at line 351 of file HMC5883L.hh.
|
protected |
Sleep mode while waiting for data.
Definition at line 354 of file HMC5883L.hh.
|
protected |
Output register latest read.
Definition at line 360 of file HMC5883L.hh.
|
protected |
Overflow detected.
Definition at line 357 of file HMC5883L.hh.
|
staticprotected |
Gain conversion table.
Definition at line 332 of file HMC5883L.hh.