IMU LSM9DS1 Library (fixed)

Dependencies:   PinDetect

Fork of LSM9DS1_Library by Jason Mar

Files at this revision

API Documentation at this revision

Comitter:
cduck
Date:
Thu Aug 03 22:26:53 2017 +0000
Parent:
1:87d535bf8c53
Child:
3:77883952d12e
Commit message:
Fix compile errors and warnings

Changed in this revision

LSM9DS1.cpp Show annotated file Show diff for this revision Revisions of this file
LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/LSM9DS1.cpp	Mon Oct 26 16:14:04 2015 +0000
+++ b/LSM9DS1.cpp	Thu Aug 03 22:26:53 2017 +0000
@@ -36,7 +36,6 @@
 #define LSM9DS1_COMMUNICATION_TIMEOUT 1000
 
 float magSensitivity[4] = {0.00014, 0.00029, 0.00043, 0.00058};
-extern Serial pc;
 
 LSM9DS1::LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr)
     :i2c(sda, scl)
@@ -170,7 +169,6 @@
     // each device. Store those in a variable so we can return them.
     uint8_t mTest = mReadByte(WHO_AM_I_M);      // Read the gyro WHO_AM_I
     uint8_t xgTest = xgReadByte(WHO_AM_I_XG);   // Read the accel/mag WHO_AM_I
-    pc.printf("%x, %x, %x, %x\n\r", mTest, xgTest, _xgAddress, _mAddress);
     uint16_t whoAmICombined = (xgTest << 8) | mTest;
     
     if (whoAmICombined != ((WHO_AM_I_AG_RSP << 8) | WHO_AM_I_M_RSP))
@@ -334,7 +332,6 @@
 // is good practice.
 void LSM9DS1::calibrate(bool autoCalc)
 {  
-    uint8_t data[6] = {0, 0, 0, 0, 0, 0};
     uint8_t samples = 0;
     int ii;
     int32_t aBiasRawTemp[3] = {0, 0, 0};
@@ -356,7 +353,7 @@
         readAccel();
         aBiasRawTemp[0] += ax;
         aBiasRawTemp[1] += ay;
-        aBiasRawTemp[2] += az - (int16_t)(1./aRes); // Assumes sensor facing up!
+        aBiasRawTemp[2] += az - (int16_t)(1.f/aRes); // Assumes sensor facing up!
     }  
     for (ii = 0; ii < 3; ii++)
     {
@@ -751,12 +748,12 @@
 
 void LSM9DS1::calcgRes()
 {
-    gRes = ((float) settings.gyro.scale) / 32768.0;
+    gRes = ((float) settings.gyro.scale) / 32768.0f;
 }
 
 void LSM9DS1::calcaRes()
 {
-    aRes = ((float) settings.accel.scale) / 32768.0;
+    aRes = ((float) settings.accel.scale) / 32768.0f;
 }
 
 void LSM9DS1::calcmRes()
@@ -984,7 +981,6 @@
     // Whether we're using I2C or SPI, write a byte using the
     // gyro-specific I2C address or SPI CS pin.
     if (settings.device.commInterface == IMU_MODE_I2C) {
-        printf("yo");
         I2CwriteByte(_xgAddress, subAddress, data);
     } else if (settings.device.commInterface == IMU_MODE_SPI) {
         SPIwriteByte(_xgAddress, subAddress, data);
@@ -1009,6 +1005,8 @@
         return I2CreadByte(_xgAddress, subAddress);
     else if (settings.device.commInterface == IMU_MODE_SPI)
         return SPIreadByte(_xgAddress, subAddress);
+    else
+        return 0;
 }
 
 void LSM9DS1::xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count)
@@ -1030,6 +1028,8 @@
         return I2CreadByte(_mAddress, subAddress);
     else if (settings.device.commInterface == IMU_MODE_SPI)
         return SPIreadByte(_mAddress, subAddress);
+    else
+        return 0;
 }
 
 void LSM9DS1::mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count)
@@ -1151,7 +1151,7 @@
     
     i2c.write(address, temp, 1);
     //i2c.write(address & 0xFE);
-    temp[1] = 0x00;
+    temp[0] = 0x00;
     i2c.write(address, temp, 1);
     //i2c.write( address | 0x01);
     int a = i2c.read(address, &data, 1);
--- a/LSM9DS1.h	Mon Oct 26 16:14:04 2015 +0000
+++ b/LSM9DS1.h	Thu Aug 03 22:26:53 2017 +0000
@@ -312,7 +312,8 @@
     *    Any OR'd combination of ZIEN, YIEN, XIEN
     *  - activeLow = Interrupt active configuration
     *    Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
-    */  - latch: latch gyroscope interrupt request.
+    *  - latch: latch gyroscope interrupt request.
+    */
     void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true);
     
     /** configMagThs() -- Configure the threshold of a gyroscope axis
--- a/mbed.bld	Mon Oct 26 16:14:04 2015 +0000
+++ b/mbed.bld	Thu Aug 03 22:26:53 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/fd96258d940d
\ No newline at end of file