Просмотр исходного кода

Pretty printed the Arduino code with astyle

Baozhu Zuo 6 лет назад
Родитель
Сommit
b8def86f1a
3 измененных файлов с 266 добавлено и 295 удалено
  1. 49 75
      HMC5883L.cpp
  2. 12 15
      HMC5883L.h
  3. 205 205
      examples/HMC5883L_Example/HMC5883L_Example.ino

+ 49 - 75
HMC5883L.cpp

@@ -26,40 +26,35 @@
 #include <Arduino.h>
 #include "HMC5883L.h"
 
-HMC5883L::HMC5883L(TwoWire &w)
-{
+HMC5883L::HMC5883L(TwoWire& w) {
     _wire = & w;
     m_Scale = 1;
 }
 
-void HMC5883L::initCompass()
-{
-    
+void HMC5883L::initCompass() {
+
     delay(5);
-    
+
     int error = setScale(1.3);                              // Set the scale of the compass.
-    
-    if(error != 0)                                                  // If there is an error, print it out.
-    {
+
+    if (error != 0) {                                               // If there is an error, print it out.
         Serial.println(getErrorText(error));
     }
-    
+
     error = setMeasurementMode(MEASUREMENT_CONTINUOUS);     // Set the measurement mode to Continuous
-    
-    if(error != 0)                                                  // If there is an error, print it out.
-    {
+
+    if (error != 0) {                                               // If there is an error, print it out.
         Serial.println(getErrorText(error));
     }
-    
-#if __Dbg
+
+    #if __Dbg
     //cout << "val_origin = " << val_origin << endl;
     //cout <<"init ok" << endl;
-#endif
+    #endif
 }
 
 
-int HMC5883L::getCompass()
-{
+int HMC5883L::getCompass() {
     MagnetometerRaw raw = readRawAxis();
     // Retrived the scaled values from the compass (scaled to the configured scale).
     MagnetometerScaled scaled = readScaledAxis();
@@ -78,27 +73,28 @@ int HMC5883L::getCompass()
     heading += declinationAngle;
 
     // Correct for when signs are reversed.
-    if(heading < 0)
-    heading += 2*PI;
+    if (heading < 0) {
+        heading += 2 * PI;
+    }
 
     // Check for wrap due to addition of declination.
-    if(heading > 2*PI)
-    heading -= 2*PI;
+    if (heading > 2 * PI) {
+        heading -= 2 * PI;
+    }
 
     // Convert radians to degrees for readability.
-    float headingDegrees = heading * 180/M_PI;
+    float headingDegrees = heading * 180 / M_PI;
 
     // Output the data via the serial port.
-    
-    int degree = headingDegrees*10;
-    
+
+    int degree = headingDegrees * 10;
+
     return degree;
 }
 
 
 
-MagnetometerRaw HMC5883L::readRawAxis()
-{
+MagnetometerRaw HMC5883L::readRawAxis() {
     uint8_t* buffer = read(DATA_REGISTER_BEGIN, 6);
     MagnetometerRaw raw = MagnetometerRaw();
     raw.XAxis = (buffer[0] << 8) | buffer[1];
@@ -107,8 +103,7 @@ MagnetometerRaw HMC5883L::readRawAxis()
     return raw;
 }
 
-MagnetometerScaled HMC5883L::readScaledAxis()
-{
+MagnetometerScaled HMC5883L::readScaledAxis() {
     MagnetometerRaw raw = readRawAxis();
     MagnetometerScaled scaled = MagnetometerScaled();
     scaled.XAxis = raw.XAxis * m_Scale;
@@ -117,78 +112,59 @@ MagnetometerScaled HMC5883L::readScaledAxis()
     return scaled;
 }
 
-short HMC5883L::setScale(float gauss)
-{
+short HMC5883L::setScale(float gauss) {
     uint8_t regValue = 0x00;
 
-/* Some of these values; e.g. 1.3 - cause comparison
- * issues with the compiler that the Arduino IDE uses.
- */
+    /*  Some of these values; e.g. 1.3 - cause comparison
+        issues with the compiler that the Arduino IDE uses.
+    */
 #define CLOSEENOUGH(x,y) (fabs(x-y)<0.001)
 
-    if(CLOSEENOUGH(gauss , 0.88))
-    {
+    if (CLOSEENOUGH(gauss, 0.88)) {
         regValue = 0x00;
         m_Scale = 0.73;
-    }
-    else if(CLOSEENOUGH(gauss , 1.3))
-    {
+    } else if (CLOSEENOUGH(gauss, 1.3)) {
         regValue = 0x01;
         m_Scale = 0.92;
-    }
-    else if(CLOSEENOUGH(gauss , 1.9))
-    {
+    } else if (CLOSEENOUGH(gauss, 1.9)) {
         regValue = 0x02;
         m_Scale = 1.22;
-    }
-    else if(CLOSEENOUGH(gauss , 2.5))
-    {
+    } else if (CLOSEENOUGH(gauss, 2.5)) {
         regValue = 0x03;
         m_Scale = 1.52;
-    }
-    else if(CLOSEENOUGH(gauss , 4.0))
-    {
+    } else if (CLOSEENOUGH(gauss, 4.0)) {
         regValue = 0x04;
         m_Scale = 2.27;
-    }
-    else if(CLOSEENOUGH(gauss , 4.7))
-    {
+    } else if (CLOSEENOUGH(gauss, 4.7)) {
         regValue = 0x05;
         m_Scale = 2.56;
-    }
-    else if(CLOSEENOUGH(gauss , 5.6))
-    {
+    } else if (CLOSEENOUGH(gauss, 5.6)) {
         regValue = 0x06;
         m_Scale = 3.03;
-    }
-    else if(CLOSEENOUGH(gauss , 8.1))
-    {
+    } else if (CLOSEENOUGH(gauss, 8.1)) {
         regValue = 0x07;
         m_Scale = 4.35;
+    } else {
+        return ERRORCODE_1_NUM;
     }
-    else
-    return ERRORCODE_1_NUM;
 
     // Setting is in the top 3 bits of the register.
     regValue = regValue << 5;
     write(CONFIGURATION_REGISTERB, regValue);
 }
 
-short HMC5883L::setMeasurementMode(uint8_t mode)
-{
+short HMC5883L::setMeasurementMode(uint8_t mode) {
     write(MODE_REGISTER, mode);
 }
 
-void HMC5883L::write(short address, short data)
-{
+void HMC5883L::write(short address, short data) {
     _wire->beginTransmission(HMC5883L_ADDRESS);
     _wire->write(address);
     _wire->write(data);
     _wire->endTransmission();
 }
 
-uint8_t* HMC5883L::read(short address, short length)
-{
+uint8_t* HMC5883L::read(short address, short length) {
     _wire->beginTransmission(HMC5883L_ADDRESS);
     _wire->write(address);
     _wire->endTransmission();
@@ -196,22 +172,20 @@ uint8_t* HMC5883L::read(short address, short length)
     _wire->beginTransmission(HMC5883L_ADDRESS);
     _wire->requestFrom(HMC5883L_ADDRESS, length);
 
-    if(_wire->available() == length)
-    {
-        for(uint8_t i = 0; i < length && i < sizeof(_buffer); i++)
-        {
+    if (_wire->available() == length) {
+        for (uint8_t i = 0; i < length && i < sizeof(_buffer); i++) {
             _buffer[i] = _wire->read();
         }
     }
-    
+
     _wire->endTransmission();
     return _buffer;
 }
 
-char* HMC5883L::getErrorText(short errorCode)
-{
-    if(ERRORCODE_1_NUM == 1)
-    return ERRORCODE_1;
+char* HMC5883L::getErrorText(short errorCode) {
+    if (ERRORCODE_1_NUM == 1) {
+        return ERRORCODE_1;
+    }
 
     return "Error not defined.";
 }

+ 12 - 15
HMC5883L.h

@@ -44,30 +44,27 @@
 #define ERRORCODE_1 "Entered scale was not valid, valid gauss values are: 0.88, 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1"
 #define ERRORCODE_1_NUM 1
 
-struct MagnetometerScaled
-{
+struct MagnetometerScaled {
     float XAxis;
     float YAxis;
     float ZAxis;
 };
 
-struct MagnetometerRaw
-{
+struct MagnetometerRaw {
     short XAxis;
     short YAxis;
     short ZAxis;
 };
 
-class HMC5883L
-{
+class HMC5883L {
 
-public:         // used by xadow phone
+  public:         // used by xadow phone
 
     void initCompass();
     int getCompass();
-    
-public:
-    HMC5883L(TwoWire &w = Wire);
+
+  public:
+    HMC5883L(TwoWire& w = Wire);
 
 
     MagnetometerRaw readRawAxis();
@@ -77,15 +74,15 @@ public:
     short setScale(float gauss);
 
     char* getErrorText(short errorCode);
-    
-    
-protected:
+
+
+  protected:
 
     void write(short address, short byte);
     uint8_t* read(short address, short length);
 
-    private:
-    TwoWire * _wire;
+  private:
+    TwoWire* _wire;
     float m_Scale;
     uint8_t _buffer[16];
 };

+ 205 - 205
examples/HMC5883L_Example/HMC5883L_Example.ino

@@ -1,4 +1,4 @@
-/*****************************************************************************/	
+/*****************************************************************************/
 //	Function:	 Get the Geographic direction of the X-axis.
 //				If X-axis points to the North, it is 0 degree.
 //				If X-axis points to the East, it is 90 degrees.
@@ -6,7 +6,7 @@
 //				If X-axis points to the West, it is 270 degrees.
 //  Hardware:   Grove - 3-Axis Digital Compass
 //	Arduino IDE: Arduino-1.0
-//	Author:	 Frankie.Chu		
+//	Author:	 Frankie.Chu
 //	Date: 	 Jan 10,2013
 //	Version: v1.0
 //
@@ -48,218 +48,218 @@ MagnetometerScaled valueOffset;
 
 
 // Out setup routine, here we will configure the microcontroller and compass.
-void setup()
-{
-  // Initialize the serial port.
-  Serial.begin(115200);
-  delay(2000);
-  Serial.println("Starting the I2C interface.");
-  Wire.begin(); // Start the I2C interface.
-
-  Serial.println("Constructing new HMC5883L");
-    
-  Serial.println("Setting scale to +/- 1.3 Ga");
-  error = compass.setScale(1.3); // Set the scale of the compass.
-  if(error != 0) // If there is an error, print it out.
-    Serial.println(compass.getErrorText(error));
-  
-  Serial.println("Setting measurement mode to continous.");
-  error = compass.setMeasurementMode(MEASUREMENT_CONTINUOUS); // Set the measurement mode to Continuous
-  if(error != 0) // If there is an error, print it out.
-    Serial.println(compass.getErrorText(error));
-    
-  compassCalibrate();
-}
+void setup() {
+    // Initialize the serial port.
+    Serial.begin(115200);
+    delay(2000);
+    Serial.println("Starting the I2C interface.");
+    Wire.begin(); // Start the I2C interface.
 
-// calibrate offset of x, y and z
-void compassCalibrate(void)
-{
-  //Serial << ">>>> calibrate the compass\n";
-  Serial.println("calibrate the compass");
-  MagnetometerScaled valueMax = {0, 0, 0};
-  MagnetometerScaled valueMin = {0, 0, 0};
-
-  // calculate x, y and z offset
-  
-  //Serial << "please rotate the compass" << endl;
-  Serial.println("please rotate the compass");
-  int xcount = 0;
-  int ycount = 0;
-  int zcount = 0;
-  boolean xZero = false;
-  boolean yZero = false;
-  boolean zZero = false;
-  MagnetometerScaled value;
-  while (xcount < 3 || ycount < 3 || zcount < 3) {
-    value = compass.readScaledAxis();
-    if ((fabs(value.XAxis) > 600) || (fabs(value.YAxis) > 600) || (fabs(value.ZAxis) > 600)) {
-      continue;
-    }
-    
-    if (valueMin.XAxis > value.XAxis) {
-      valueMin.XAxis = value.XAxis;
-    } else if (valueMax.XAxis < value.XAxis) {
-      valueMax.XAxis = value.XAxis;
-    }
-    
-    if (valueMin.YAxis > value.YAxis) {
-      valueMin.YAxis = value.YAxis;
-    } else if (valueMax.YAxis < value.YAxis) {
-      valueMax.YAxis = value.YAxis;
-    }
-    
-    if (valueMin.ZAxis > value.ZAxis) {
-      valueMin.ZAxis = value.ZAxis;
-    } else if (valueMax.ZAxis < value.ZAxis) {
-      valueMax.ZAxis = value.ZAxis;
-    }
-    
-    
-    if (xZero) {
-      if (fabs(value.XAxis) > 50) {
-        xZero = false;
-        xcount++;
-      }
-    } else {
-      if (fabs(value.XAxis) < 40) {
-        xZero = true;
-      }
+    Serial.println("Constructing new HMC5883L");
+
+    Serial.println("Setting scale to +/- 1.3 Ga");
+    error = compass.setScale(1.3); // Set the scale of the compass.
+    if (error != 0) { // If there is an error, print it out.
+        Serial.println(compass.getErrorText(error));
     }
-    
-    if (yZero) {
-      if (fabs(value.YAxis) > 50) {
-        yZero = false;
-        ycount++;
-      }
-    } else {
-      if (fabs(value.YAxis) < 40) {
-        yZero = true;
-      }
+
+    Serial.println("Setting measurement mode to continous.");
+    error = compass.setMeasurementMode(MEASUREMENT_CONTINUOUS); // Set the measurement mode to Continuous
+    if (error != 0) { // If there is an error, print it out.
+        Serial.println(compass.getErrorText(error));
     }
-    
-    if (zZero) {
-      if (fabs(value.ZAxis) > 50) {
-        zZero = false;
-        zcount++;
-      }
-    } else {
-      if (fabs(value.ZAxis) < 40) {
-        zZero = true;
-      }
+
+    compassCalibrate();
+}
+
+// calibrate offset of x, y and z
+void compassCalibrate(void) {
+    //Serial << ">>>> calibrate the compass\n";
+    Serial.println("calibrate the compass");
+    MagnetometerScaled valueMax = {0, 0, 0};
+    MagnetometerScaled valueMin = {0, 0, 0};
+
+    // calculate x, y and z offset
+
+    //Serial << "please rotate the compass" << endl;
+    Serial.println("please rotate the compass");
+    int xcount = 0;
+    int ycount = 0;
+    int zcount = 0;
+    boolean xZero = false;
+    boolean yZero = false;
+    boolean zZero = false;
+    MagnetometerScaled value;
+    while (xcount < 3 || ycount < 3 || zcount < 3) {
+        value = compass.readScaledAxis();
+        if ((fabs(value.XAxis) > 600) || (fabs(value.YAxis) > 600) || (fabs(value.ZAxis) > 600)) {
+            continue;
+        }
+
+        if (valueMin.XAxis > value.XAxis) {
+            valueMin.XAxis = value.XAxis;
+        } else if (valueMax.XAxis < value.XAxis) {
+            valueMax.XAxis = value.XAxis;
+        }
+
+        if (valueMin.YAxis > value.YAxis) {
+            valueMin.YAxis = value.YAxis;
+        } else if (valueMax.YAxis < value.YAxis) {
+            valueMax.YAxis = value.YAxis;
+        }
+
+        if (valueMin.ZAxis > value.ZAxis) {
+            valueMin.ZAxis = value.ZAxis;
+        } else if (valueMax.ZAxis < value.ZAxis) {
+            valueMax.ZAxis = value.ZAxis;
+        }
+
+
+        if (xZero) {
+            if (fabs(value.XAxis) > 50) {
+                xZero = false;
+                xcount++;
+            }
+        } else {
+            if (fabs(value.XAxis) < 40) {
+                xZero = true;
+            }
+        }
+
+        if (yZero) {
+            if (fabs(value.YAxis) > 50) {
+                yZero = false;
+                ycount++;
+            }
+        } else {
+            if (fabs(value.YAxis) < 40) {
+                yZero = true;
+            }
+        }
+
+        if (zZero) {
+            if (fabs(value.ZAxis) > 50) {
+                zZero = false;
+                zcount++;
+            }
+        } else {
+            if (fabs(value.ZAxis) < 40) {
+                zZero = true;
+            }
+        }
+
+        delay(30);
     }
-    
-    delay(30);
-  }
-  
-  valueOffset.XAxis = (valueMax.XAxis + valueMin.XAxis) / 2;
-  valueOffset.YAxis = (valueMax.YAxis + valueMin.YAxis) / 2;
-  valueOffset.ZAxis = (valueMax.ZAxis + valueMin.ZAxis) / 2;
-#if 0 
-  Serial << "max: " << valueMax.XAxis << '\t' << valueMax.YAxis << '\t' << valueMax.ZAxis << endl;
-  Serial << "min: " << valueMin.XAxis << '\t' << valueMin.YAxis << '\t' << valueMin.ZAxis << endl;
-  Serial << "offset: " << valueOffset.XAxis << '\t' << valueOffset.YAxis << '\t' << valueOffset.ZAxis << endl;
-  
-  Serial << "<<<<" << endl;
-#endif  
-  Serial.print("max: ");
-  Serial.print(valueMax.XAxis);
-  Serial.print(valueMax.YAxis);
-  Serial.println(valueMax.ZAxis);
-  Serial.print("min: ");
-  Serial.print(valueMin.XAxis);
-  Serial.print(valueMin.YAxis);
-  Serial.println(valueMin.ZAxis);
-  Serial.print("offset: ");
-  Serial.print(valueOffset.XAxis);
-  Serial.print(valueOffset.YAxis);
-  Serial.println(valueOffset.ZAxis);
+
+    valueOffset.XAxis = (valueMax.XAxis + valueMin.XAxis) / 2;
+    valueOffset.YAxis = (valueMax.YAxis + valueMin.YAxis) / 2;
+    valueOffset.ZAxis = (valueMax.ZAxis + valueMin.ZAxis) / 2;
+    #if 0
+    Serial << "max: " << valueMax.XAxis << '\t' << valueMax.YAxis << '\t' << valueMax.ZAxis << endl;
+    Serial << "min: " << valueMin.XAxis << '\t' << valueMin.YAxis << '\t' << valueMin.ZAxis << endl;
+    Serial << "offset: " << valueOffset.XAxis << '\t' << valueOffset.YAxis << '\t' << valueOffset.ZAxis << endl;
+
+    Serial << "<<<<" << endl;
+    #endif
+    Serial.print("max: ");
+    Serial.print(valueMax.XAxis);
+    Serial.print(valueMax.YAxis);
+    Serial.println(valueMax.ZAxis);
+    Serial.print("min: ");
+    Serial.print(valueMin.XAxis);
+    Serial.print(valueMin.YAxis);
+    Serial.println(valueMin.ZAxis);
+    Serial.print("offset: ");
+    Serial.print(valueOffset.XAxis);
+    Serial.print(valueOffset.YAxis);
+    Serial.println(valueOffset.ZAxis);
 }
 
 // Our main program loop.
-void loop()
-{
-  // Retrive the raw values from the compass (not scaled).
-  MagnetometerRaw raw = compass.readRawAxis();
-  // Retrived the scaled values from the compass (scaled to the configured scale).
-  MagnetometerScaled scaled = compass.readScaledAxis();
-  
-  scaled.XAxis -= valueOffset.XAxis;
-  scaled.YAxis -= valueOffset.YAxis;
-  scaled.ZAxis -= valueOffset.ZAxis;
-  
-  // Values are accessed like so:
-  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)
-
-  // Calculate heading when the magnetometer is level, then correct for signs of axis.
-  float yxHeading = atan2(scaled.YAxis, scaled.XAxis);
-  float zxHeading = atan2(scaled.ZAxis, scaled.XAxis);
-  
-  float heading = yxHeading;
-  
-  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
-  // Find yours here: http://www.magnetic-declination.com/
-  // Mine is: -2��37' which is -2.617 Degrees, or (which we need) -0.0456752665 radians, I will use -0.0457
-  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
-  float declinationAngle = -0.0457;
-  heading += declinationAngle;
-  
-  // Correct for when signs are reversed.
-  if(heading < 0)
-    heading += 2*PI;
-    
-  // Check for wrap due to addition of declination.
-  if(heading > 2*PI)
-    heading -= 2*PI;
-   
-  // Convert radians to degrees for readability.
-  float headingDegrees = heading * 180/M_PI; 
-  
-  float yxHeadingDegrees = yxHeading * 180 / M_PI;
-  float zxHeadingDegrees = zxHeading * 180 / M_PI;
-
-  // Output the data via the serial port.
-  // Output(raw, scaled, heading, headingDegrees);
-  
-//  Serial << scaled.XAxis << ' ' << scaled.YAxis << ' ' << scaled.ZAxis << endl;
-//  Serial << "arctan y/x: " << yxHeadingDegrees << " \tarctan z/x: " << zxHeadingDegrees << endl;
-  
-  Serial.print(scaled.XAxis);
-  Serial.print(scaled.YAxis);
-  Serial.println(scaled.ZAxis);
-  
-  Serial.print("arctan y/x: ");
-  Serial.print(yxHeadingDegrees);
-  Serial.print("arctan z/x: ");  
-  Serial.print(zxHeadingDegrees);
-  
-  // Normally we would delay the application by 66ms to allow the loop
-  // to run at 15Hz (default bandwidth for the HMC5883L).
-  // However since we have a long serial out (104ms at 9600) we will let
-  // it run at its natural speed.
-  delay(1000);//of course it can be delayed longer.
+void loop() {
+    // Retrive the raw values from the compass (not scaled).
+    MagnetometerRaw raw = compass.readRawAxis();
+    // Retrived the scaled values from the compass (scaled to the configured scale).
+    MagnetometerScaled scaled = compass.readScaledAxis();
+
+    scaled.XAxis -= valueOffset.XAxis;
+    scaled.YAxis -= valueOffset.YAxis;
+    scaled.ZAxis -= valueOffset.ZAxis;
+
+    // Values are accessed like so:
+    int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)
+
+    // Calculate heading when the magnetometer is level, then correct for signs of axis.
+    float yxHeading = atan2(scaled.YAxis, scaled.XAxis);
+    float zxHeading = atan2(scaled.ZAxis, scaled.XAxis);
+
+    float heading = yxHeading;
+
+    // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
+    // Find yours here: http://www.magnetic-declination.com/
+    // Mine is: -2��37' which is -2.617 Degrees, or (which we need) -0.0456752665 radians, I will use -0.0457
+    // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
+    float declinationAngle = -0.0457;
+    heading += declinationAngle;
+
+    // Correct for when signs are reversed.
+    if (heading < 0) {
+        heading += 2 * PI;
+    }
+
+    // Check for wrap due to addition of declination.
+    if (heading > 2 * PI) {
+        heading -= 2 * PI;
+    }
+
+    // Convert radians to degrees for readability.
+    float headingDegrees = heading * 180 / M_PI;
+
+    float yxHeadingDegrees = yxHeading * 180 / M_PI;
+    float zxHeadingDegrees = zxHeading * 180 / M_PI;
+
+    // Output the data via the serial port.
+    // Output(raw, scaled, heading, headingDegrees);
+
+    //  Serial << scaled.XAxis << ' ' << scaled.YAxis << ' ' << scaled.ZAxis << endl;
+    //  Serial << "arctan y/x: " << yxHeadingDegrees << " \tarctan z/x: " << zxHeadingDegrees << endl;
+
+    Serial.print(scaled.XAxis);
+    Serial.print(scaled.YAxis);
+    Serial.println(scaled.ZAxis);
+
+    Serial.print("arctan y/x: ");
+    Serial.print(yxHeadingDegrees);
+    Serial.print("arctan z/x: ");
+    Serial.print(zxHeadingDegrees);
+
+    // Normally we would delay the application by 66ms to allow the loop
+    // to run at 15Hz (default bandwidth for the HMC5883L).
+    // However since we have a long serial out (104ms at 9600) we will let
+    // it run at its natural speed.
+    delay(1000);//of course it can be delayed longer.
 }
 
 // Output the data down the serial port.
-void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
-{
-   Serial.print("Raw:\t");
-   Serial.print(raw.XAxis);
-   Serial.print("   ");   
-   Serial.print(raw.YAxis);
-   Serial.print("   ");   
-   Serial.print(raw.ZAxis);
-   Serial.print("   \tScaled:\t");
-   
-   Serial.print(scaled.XAxis);
-   Serial.print("   ");   
-   Serial.print(scaled.YAxis);
-   Serial.print("   ");   
-   Serial.print(scaled.ZAxis);
-
-   Serial.print("   \tHeading:\t");
-   Serial.print(heading);
-   Serial.print(" Radians   \t");
-   Serial.print(headingDegrees);
-   Serial.println(" Degrees   \t");
+void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees) {
+    Serial.print("Raw:\t");
+    Serial.print(raw.XAxis);
+    Serial.print("   ");
+    Serial.print(raw.YAxis);
+    Serial.print("   ");
+    Serial.print(raw.ZAxis);
+    Serial.print("   \tScaled:\t");
+
+    Serial.print(scaled.XAxis);
+    Serial.print("   ");
+    Serial.print(scaled.YAxis);
+    Serial.print("   ");
+    Serial.print(scaled.ZAxis);
+
+    Serial.print("   \tHeading:\t");
+    Serial.print(heading);
+    Serial.print(" Radians   \t");
+    Serial.print(headingDegrees);
+    Serial.println(" Degrees   \t");
 }