Procházet zdrojové kódy

Pretty printed the Arduino code with astyle

Baozhu Zuo před 6 roky
rodič
revize
4aa64709eb

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 472 - 516
SparkFunLSM6DS3.cpp


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 866 - 869
SparkFunLSM6DS3.h


+ 48 - 51
examples/FreeFallDetect/FreeFallDetect.ino

@@ -1,14 +1,14 @@
-/*****************************************************************************/  
+/*****************************************************************************/
 //  FreeFallDetect.ino
 //  Hardware:      Grove - 6-Axis Accelerometer&Gyroscope
 //  Arduino IDE:   Arduino-1.65
-//  Author:        Lambor 
+//  Author:        Lambor
 //  Date:          Nov,2015
 //  Version:       v1.0
 //
-//  Modified by: 
-//  Data:        
-//  Description: 
+//  Modified by:
+//  Data:
+//  Description:
 //
 //  by www.seeedstudio.com
 //
@@ -32,59 +32,56 @@
 #include "Wire.h"
 
 #define CLEAR_STEP      true
-#define NOT_CLEAR_STEP  false 
+#define NOT_CLEAR_STEP  false
 
 //Create a instance of class LSM6DS3
-LSM6DS3 lsm6ds3( I2C_MODE, 0x6A );  //I2C device address 0x6A
+LSM6DS3 lsm6ds3(I2C_MODE, 0x6A);    //I2C device address 0x6A
 uint16_t detectCount = 0;
 
-void setup() {  
-  Serial.begin(9600);    
-  if( lsm6ds3.begin() != 0 ){
-    Serial.println("Device error");
-  }
-  else{
-      Serial.println("Device OK!");
-  }
-  
-  if(0 != config_free_fall_detect())
-    Serial.println("Fail to configure!");
-  else
-    Serial.println("Success to Configure!");
+void setup() {
+    Serial.begin(9600);
+    if (lsm6ds3.begin() != 0) {
+        Serial.println("Device error");
+    } else {
+        Serial.println("Device OK!");
+    }
+
+    if (0 != config_free_fall_detect()) {
+        Serial.println("Fail to configure!");
+    } else {
+        Serial.println("Success to Configure!");
+    }
 }
 
-void loop()
-{
-  uint8_t readDataByte = 0;
-	//Read the wake-up source register
-	lsm6ds3.readRegister(&readDataByte, LSM6DS3_ACC_GYRO_WAKE_UP_SRC);
-	//Mask off the FF_IA bit for free-fall detection
-	readDataByte &= 0x20;	
-  if( readDataByte )
-	{   
-    detectCount ++;
-		Serial.print("Free fall detected!  ");        
-    Serial.println(detectCount);
-	}  
-  delay(10);  
+void loop() {
+    uint8_t readDataByte = 0;
+    //Read the wake-up source register
+    lsm6ds3.readRegister(&readDataByte, LSM6DS3_ACC_GYRO_WAKE_UP_SRC);
+    //Mask off the FF_IA bit for free-fall detection
+    readDataByte &= 0x20;
+    if (readDataByte) {
+        detectCount ++;
+        Serial.print("Free fall detected!  ");
+        Serial.println(detectCount);
+    }
+    delay(10);
 }
 
-int config_free_fall_detect(void)
-{  
-	uint8_t error = 0;  
-  uint8_t dataToWrite = 0;  
-  
-  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
-  dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
-  dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_416Hz;
-  
-  error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
-	error += lsm6ds3.writeRegister( LSM6DS3_ACC_GYRO_WAKE_UP_DUR, 0x00 );
-  error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_FREE_FALL, 0x33);
-  error += lsm6ds3.writeRegister( LSM6DS3_ACC_GYRO_MD1_CFG, 0x10 );
-	error += lsm6ds3.writeRegister( LSM6DS3_ACC_GYRO_MD2_CFG, 0x10 );
-  error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x01);
-  
-  return error;
+int config_free_fall_detect(void) {
+    uint8_t error = 0;
+    uint8_t dataToWrite = 0;
+
+    dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
+    dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
+    dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_416Hz;
+
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_DUR, 0x00);
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_FREE_FALL, 0x33);
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x10);
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_MD2_CFG, 0x10);
+    error += lsm6ds3.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x01);
+
+    return error;
 }
 

+ 40 - 44
examples/HighLevelExample/HighLevelExample.ino

@@ -1,14 +1,14 @@
-/*****************************************************************************/	
+/*****************************************************************************/
 //  HighLevelExample.ino
 //  Hardware:      Grove - 6-Axis Accelerometer&Gyroscope
 //	Arduino IDE:   Arduino-1.65
-//	Author:	       Lambor	
+//	Author:	       Lambor
 //	Date: 	       Oct,2015
 //	Version:       v1.0
 //
-//  Modified by: 
-//  Data:        
-//  Description: 
+//  Modified by:
+//  Data:
+//  Description:
 //
 //	by www.seeedstudio.com
 //
@@ -32,48 +32,44 @@
 #include "Wire.h"
 
 //Create a instance of class LSM6DS3
-LSM6DS3 myIMU( I2C_MODE, 0x6A );  //I2C device address 0x6A
+LSM6DS3 myIMU(I2C_MODE, 0x6A);    //I2C device address 0x6A
 
 void setup() {
-  // put your setup code here, to run once:
-  Serial.begin(9600);  
-  //Call .begin() to configure the IMUs
-  if( myIMU.begin() != 0 )
-  {
-	  Serial.println("Device error");
-  }
-  else  
-  {
-      Serial.println("Device OK!");
-  }
+    // put your setup code here, to run once:
+    Serial.begin(9600);
+    //Call .begin() to configure the IMUs
+    if (myIMU.begin() != 0) {
+        Serial.println("Device error");
+    } else {
+        Serial.println("Device OK!");
+    }
 }
 
-void loop()
-{
-  //Accelerometer
-  Serial.print("\nAccelerometer:\n");
-  Serial.print(" X1 = ");
-  Serial.println(myIMU.readFloatAccelX(), 4);
-  Serial.print(" Y1 = ");
-  Serial.println(myIMU.readFloatAccelY(), 4);
-  Serial.print(" Z1 = ");
-  Serial.println(myIMU.readFloatAccelZ(), 4);
-  
-  //Gyroscope 
-  Serial.print("\nGyroscope:\n");
-  Serial.print(" X1 = ");
-  Serial.println(myIMU.readFloatGyroX(), 4);
-  Serial.print(" Y1 = ");
-  Serial.println(myIMU.readFloatGyroY(), 4);
-  Serial.print(" Z1 = ");
-  Serial.println(myIMU.readFloatGyroZ(), 4);
+void loop() {
+    //Accelerometer
+    Serial.print("\nAccelerometer:\n");
+    Serial.print(" X1 = ");
+    Serial.println(myIMU.readFloatAccelX(), 4);
+    Serial.print(" Y1 = ");
+    Serial.println(myIMU.readFloatAccelY(), 4);
+    Serial.print(" Z1 = ");
+    Serial.println(myIMU.readFloatAccelZ(), 4);
 
-  //Thermometer  
-  Serial.print("\nThermometer:\n");
-  Serial.print(" Degrees C1 = ");
-  Serial.println(myIMU.readTempC(), 4);
-  Serial.print(" Degrees F1 = ");
-  Serial.println(myIMU.readTempF(), 4);
-  
-  delay(1000);
+    //Gyroscope
+    Serial.print("\nGyroscope:\n");
+    Serial.print(" X1 = ");
+    Serial.println(myIMU.readFloatGyroX(), 4);
+    Serial.print(" Y1 = ");
+    Serial.println(myIMU.readFloatGyroY(), 4);
+    Serial.print(" Z1 = ");
+    Serial.println(myIMU.readFloatGyroZ(), 4);
+
+    //Thermometer
+    Serial.print("\nThermometer:\n");
+    Serial.print(" Degrees C1 = ");
+    Serial.println(myIMU.readTempC(), 4);
+    Serial.print(" Degrees F1 = ");
+    Serial.println(myIMU.readTempF(), 4);
+
+    delay(1000);
 }

+ 61 - 68
examples/LowLevelExample/LowLevelExample.ino

@@ -1,14 +1,14 @@
-/*****************************************************************************/	
+/*****************************************************************************/
 //  LowLevelExample.ino
 //  Hardware:      Grove - 6-Axis Accelerometer&Gyroscope
 //	Arduino IDE:   Arduino-1.65
-//	Author:	       Lambor	
+//	Author:	       Lambor
 //	Date: 	       Oct,2015
 //	Version:       v1.0
 //
-//  Modified by: 
-//  Data:        
-//  Description: 
+//  Modified by:
+//  Data:
+//  Description:
 //
 //	by www.seeedstudio.com
 //
@@ -35,72 +35,65 @@
 uint16_t errorsAndWarnings = 0;
 
 //Create instance of LSM6DS3Core
-LSM6DS3Core myIMU( I2C_MODE, 0x6A );  //I2C device address 0x6A
+LSM6DS3Core myIMU(I2C_MODE, 0x6A);    //I2C device address 0x6A
 
 void setup() {
-  //Init Serial port
-  Serial.begin(9600);
-  
-  //Call .beginCore() to configure the IMU
-  if( myIMU.beginCore() != 0 )
-  {
-    Serial.print("\nDevice Error.\n");
-  }
-  else
-  {
-    Serial.print("\nDevice OK.\n");
-  }
-  
-  uint8_t dataToWrite = 0;  //Temporary variable
-
-  //Setup the accelerometer******************************
-  dataToWrite = 0; //Start Fresh!
-  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz;
-  dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_8g;
-  dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz;
-
-  //Now, write the patched together data
-  errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
-
-  //Set the ODR bit
-  errorsAndWarnings += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
-  dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
+    //Init Serial port
+    Serial.begin(9600);
+
+    //Call .beginCore() to configure the IMU
+    if (myIMU.beginCore() != 0) {
+        Serial.print("\nDevice Error.\n");
+    } else {
+        Serial.print("\nDevice OK.\n");
+    }
+
+    uint8_t dataToWrite = 0;  //Temporary variable
+
+    //Setup the accelerometer******************************
+    dataToWrite = 0; //Start Fresh!
+    dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz;
+    dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_8g;
+    dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz;
+
+    //Now, write the patched together data
+    errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
+
+    //Set the ODR bit
+    errorsAndWarnings += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
+    dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
 
 }
 
-void loop()
-{
-  int16_t temp;
-  //Get all parameters
-  Serial.print("\nAccelerometer Counts:\n");  
-  
-  //Acelerometer axis X
-  if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0 )
-  {
-    errorsAndWarnings++;
-  }
-  Serial.print(" X = ");
-  Serial.println(temp);  
-  
-  //Acelerometer axis Y 
-  if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTY_L_XL) != 0 )
-  {
-    errorsAndWarnings++;
-  }
-  Serial.print(" Y = ");
-  Serial.println(temp);
-  
-  //Acelerometer axis Z  
-  if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTZ_L_XL) != 0 )
-  {
-    errorsAndWarnings++;
-  }
-  Serial.print(" Z = ");  
-  Serial.println(temp);
-  
-  Serial.println();
-  Serial.print("Total reported Errors and Warnings: ");
-  Serial.println(errorsAndWarnings);
-  
-  delay(1000);
+void loop() {
+    int16_t temp;
+    //Get all parameters
+    Serial.print("\nAccelerometer Counts:\n");
+
+    //Acelerometer axis X
+    if (myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0) {
+        errorsAndWarnings++;
+    }
+    Serial.print(" X = ");
+    Serial.println(temp);
+
+    //Acelerometer axis Y
+    if (myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTY_L_XL) != 0) {
+        errorsAndWarnings++;
+    }
+    Serial.print(" Y = ");
+    Serial.println(temp);
+
+    //Acelerometer axis Z
+    if (myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTZ_L_XL) != 0) {
+        errorsAndWarnings++;
+    }
+    Serial.print(" Z = ");
+    Serial.println(temp);
+
+    Serial.println();
+    Serial.print("Total reported Errors and Warnings: ");
+    Serial.println(errorsAndWarnings);
+
+    delay(1000);
 }

+ 64 - 67
examples/Pedometer/Pedometer.ino

@@ -1,14 +1,14 @@
-/*****************************************************************************/  
+/*****************************************************************************/
 //  Pedometer.ino
 //  Hardware:      Grove - 6-Axis Accelerometer&Gyroscope
 //  Arduino IDE:   Arduino-1.65
-//  Author:        Lambor 
+//  Author:        Lambor
 //  Date:          Nov,2015
 //  Version:       v1.0
 //
-//  Modified by: 
-//  Data:        
-//  Description: 
+//  Modified by:
+//  Data:
+//  Description:
 //
 //  by www.seeedstudio.com
 //
@@ -32,74 +32,71 @@
 #include "Wire.h"
 
 #define CLEAR_STEP      true
-#define NOT_CLEAR_STEP  false 
+#define NOT_CLEAR_STEP  false
 
 //Create a instance of class LSM6DS3
-LSM6DS3 pedometer( I2C_MODE, 0x6A );  //I2C device address 0x6A
-
-void setup() {  
-  Serial.begin(9600);    
-  if( pedometer.begin() != 0 ){
-    Serial.println("Device error");
-  }
-  else{
-      Serial.println("Device OK!");
-  }
-  
-  //Configure LSM6DS3 as pedometer 
-  if( 0 != config_pedometer(NOT_CLEAR_STEP) )
-  {
-    Serial.println("Configure pedometer fail!");
-  }
-  Serial.println("Success to Configure pedometer!");
+LSM6DS3 pedometer(I2C_MODE, 0x6A);    //I2C device address 0x6A
+
+void setup() {
+    Serial.begin(9600);
+    if (pedometer.begin() != 0) {
+        Serial.println("Device error");
+    } else {
+        Serial.println("Device OK!");
+    }
+
+    //Configure LSM6DS3 as pedometer
+    if (0 != config_pedometer(NOT_CLEAR_STEP)) {
+        Serial.println("Configure pedometer fail!");
+    }
+    Serial.println("Success to Configure pedometer!");
 }
 
-void loop()
-{
-  uint8_t dataByte = 0;
-  uint16_t stepCount = 0;
-  
-  pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_H);
-  stepCount = (dataByte << 8) & 0xFFFF;
-  
-  pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_L);
-  stepCount |=  dataByte;
-  
-  Serial.print("Step: ");
-  Serial.println(stepCount);
-  
-  delay(500);
+void loop() {
+    uint8_t dataByte = 0;
+    uint16_t stepCount = 0;
+
+    pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_H);
+    stepCount = (dataByte << 8) & 0xFFFF;
+
+    pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_L);
+    stepCount |=  dataByte;
+
+    Serial.print("Step: ");
+    Serial.println(stepCount);
+
+    delay(500);
 }
 
 //Setup pedometer mode
-int config_pedometer(bool clearStep)
-{
-  uint8_t errorAccumulator = 0;
-	uint8_t dataToWrite = 0;  //Temporary variable
-
-	//Setup the accelerometer******************************
-	dataToWrite = 0; 
-  
-	//  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
-	dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
-	dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_26Hz;
-
-  
-	// Step 1: Configure ODR-26Hz and FS-2g
-	errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
-
-	// Step 2: Set bit Zen_G, Yen_G, Xen_G, FUNC_EN, PEDO_RST_STEP(1 or 0)
-  if(clearStep)
-    errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3E);
-  else
-    errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3C);
-  
-  // Step 3:	Enable pedometer algorithm
-	errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x40);
-  
-  //Step 4:	Step Detector interrupt driven to INT1 pin, set bit INT1_FIFO_OVR
-	errorAccumulator += pedometer.writeRegister( LSM6DS3_ACC_GYRO_INT1_CTRL, 0x10 );
-	
-	return errorAccumulator;
+int config_pedometer(bool clearStep) {
+    uint8_t errorAccumulator = 0;
+    uint8_t dataToWrite = 0;  //Temporary variable
+
+    //Setup the accelerometer******************************
+    dataToWrite = 0;
+
+    //  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
+    dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
+    dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_26Hz;
+
+
+    // Step 1: Configure ODR-26Hz and FS-2g
+    errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
+
+    // Step 2: Set bit Zen_G, Yen_G, Xen_G, FUNC_EN, PEDO_RST_STEP(1 or 0)
+    if (clearStep) {
+        errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3E);
+    } else {
+        errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3C);
+    }
+
+    // Step 3:	Enable pedometer algorithm
+    errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x40);
+
+    //Step 4:	Step Detector interrupt driven to INT1 pin, set bit INT1_FIFO_OVR
+    errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_INT1_CTRL, 0x10);
+
+    return errorAccumulator;
 }
 

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů