First draft HMC5883 magnetometer sensor using physical quantities, outputting via serial port using std::cout on mbed os 5

Revision:
8:c5dc1ce10722
Child:
9:87a7169b4d5c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/magnetometer.cpp	Thu Mar 26 21:13:44 2020 +0000
@@ -0,0 +1,56 @@
+
+
+#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);
+}