62 writeReg(0x00, S1 | Hz75 | NORMAL);
84 void writeReg(uint8_t reg, uint8_t val) {
98 this->Axes.x = rq.
data.buf[1] | (rq.
data.buf[0] << 8);
99 this->Axes.y = rq.
data.buf[3] | (rq.
data.buf[2] << 8);
100 this->Axes.z = rq.
data.buf[5] | (rq.
data.buf[4] << 8);
102 this->heading = atan2(this->Axes.y, this->Axes.x);
104 this->heading += this->declinationAngle;
105 if(this->heading < 0)
106 this->heading += 2 * M_PI;
107 if(this->heading > 2 * M_PI)
108 this->heading -= 2 * M_PI;
111 double getHeadingDegree() {
112 return heading * 180 / M_PI;
120 double declinationAngle = 0.0303;
size_t size
total capacity of buffer
Definition buffer.h:23
Implementation of the HMC5883L multi-chip three-axis magnetic sensor.
Definition HMC5883L.h:17
HMC5883L(Sink< I2C::Request > &bus, enum ADDR addr=DEFAULT)
initialize the sensor
Definition HMC5883L.h:59
void measure()
start async read of angle
Definition HMC5883L.h:72
void callback(const I2C::Request &rq) override
callback.
Definition HMC5883L.h:95
generic I2C device wrapper.
Definition i2c.h:21
Device(Sink< Request > &bus, uint8_t address)
construct device on bus with given address
Definition i2c.h:26
struct defining an I2C request.
Definition i2c.h:37
Buffer< uint8_t > data
transfer data
Definition i2c.h:39
generic object sink, i.e.
Definition streams.h:15
void trypush(T &&t)
use this if you don't care if it's going to be successful. data gets discarded if sink is full.
Definition streams.h:28