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

Revision:
10:75c8ce89aeb7
Parent:
9:87a7169b4d5c
Child:
11:de7c9ae7ef65
--- a/main.cpp	Thu Mar 26 21:35:19 2020 +0000
+++ b/main.cpp	Thu Mar 26 21:59:18 2020 +0000
@@ -2,40 +2,18 @@
 #include "mbed.h"
 #include "magnetometer.h"
 
-
-void mag_adjusted_values(
-    quan::time::ms const & update_rate, 
-    quan::three_d::vect<double> const & gains,
-    quan::three_d::vect<quan::magnetic_flux_density::uT> const & offsets
-);
-void mag_raw_values(quan::time::ms const & update_rate);
-void mag_offset_calibrate();
+namespace {   
 
-namespace {
-    
-    // terminal loop, printing message periodically
-    void loop_forever(std::string const & str)
-    {
-        DigitalOut led1(LED1,1);
-        // stop but print error dynamically
-        int count = 0;
-        for (;;) {
-            led1 = 1;
-            std::cout << str << " " << count++ << '\n';
-            ThisThread::sleep_for(200U);
-            led1 = 0;
-            ThisThread::sleep_for(800U);
-        }
-    }
-    
-    // do something with mag output
+    // do something with magnetometer output
     void callback(quan::three_d::vect<quan::magnetic_flux_density::uT> const & v)
     {
-         std::cout << "val = " << v << '\n';
+        std::cout << "val = " << v << '\n';
     }
     
 }// namespace
 
+void loop_forever(std::string const & str);
+
 int main()
 {
     DigitalOut led2(LED2,1);
@@ -53,6 +31,7 @@
     for (;;){
         
         mag_start_measurement();
+        
         do{
            ThisThread::sleep_for(10U);
         }  while ( ! mag_data_ready() ); 
@@ -61,12 +40,13 @@
         if (mag_read(v)){
             callback(v);
         }
+        
         if ( (now - prev_led) >= 500U){
             prev_led = now;
             led2 = (led2 == 0) ? 1: 0;
         }
-        auto const next_wake = now +
-            static_cast<uint64_t>(update_rate_ms);
+        
+        auto const next_wake = now + update_rate_ms;
         ThisThread::sleep_until(next_wake);
         now = next_wake;
     }