Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
magnetometer.cpp
- Committer:
- skyscraper
- Date:
- 2020-03-26
- Revision:
- 8:c5dc1ce10722
- Child:
- 9:87a7169b4d5c
File content as of revision 8:c5dc1ce10722:
#include "magnetometer.h"
#include "quan_time.h"
#include "hmc5883.h"
#include "resourceManager.h"
namespace {
hmc5883L hmc5883L_ID1{resource::i2c1,0x3D};
}
bool mag_init()
{
// allow magnetometer hardware time to start
auto now = Kernel::get_ms_count();
if ( now < 500U){
ThisThread::sleep_until(500);
}
if (! hmc5883L_ID1.detected(true)){
return false; // usr has been notified
}
hmc5883L_ID1.set_idle_mode();
constexpr auto earth_magnetic_field_flux_density = 31.869_uT;
bool const success =
hmc5883L_ID1.set_samples_average(8) &&
hmc5883L_ID1.set_range( earth_magnetic_field_flux_density * 2U);
//gains frm calib engine
quan::three_d::vect<double> gain{1.37689,1.35057,1.56647};
hmc5883L_ID1.set_gain(gain);
// offsets from calib engine
quan::three_d::vect<
quan::magnetic_flux_density::uT
> offset{10.5724_uT,-10.869_uT,2.241468_uT};
hmc5883L_ID1.set_offset(offset);
// set gain and offsets
return success;
}
bool mag_start_measurement()
{
return hmc5883L_ID1.start_measurement();
}
bool mag_data_ready()
{
return hmc5883L_ID1.data_ready();
}
bool mag_read(quan::three_d::vect<quan::magnetic_flux_density::uT> & v)
{
return hmc5883L_ID1.read(v);
}