فهرست منبع

Pretty printed the Arduino code with astyle

Baozhu Zuo 6 سال پیش
والد
کامیت
66ece33374

+ 43 - 45
examples/LIS3DHTR_IIC/LIS3DHTR_IIC.ino

@@ -3,55 +3,53 @@
 
 #include "LIS3DHTR.h"
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-  SoftwareWire myWire(3, 2);
-  LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
-  #define WIRE myWire
+    #include <SoftwareWire.h>
+    SoftwareWire myWire(3, 2);
+    LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
+    #define WIRE myWire
 #else
-  #include <Wire.h>
-  LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
-  #define WIRE Wire
+    #include <Wire.h>
+    LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
+    #define WIRE Wire
 #endif
 
 
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial) {};
-  LIS.begin(WIRE); //IIC init
-  LIS.openTemp();//If ADC3 is used, the temperature detection needs to be turned off.
-  //  LIS.closeTemp();//default
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial) {};
+    LIS.begin(WIRE); //IIC init
+    LIS.openTemp();//If ADC3 is used, the temperature detection needs to be turned off.
+    //  LIS.closeTemp();//default
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS) {
-    Serial.println("LIS3DHTR didn't connect.");
-    while (1);
-    return;
-  }
-  //3 axis
-//  Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
-//  Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
-//  Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
-  //ADC
-//    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
-//    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
-//    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //3 axis
+    //  Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
+    //  Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
+    //  Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
+    //ADC
+    //    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
+    //    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
+    //    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
 
-  //temperature
-  Serial.print("temp:"); Serial.println(LIS.getTemperature());
-  delay(500);
+    //temperature
+    Serial.print("temp:"); Serial.println(LIS.getTemperature());
+    delay(500);
 }

+ 35 - 37
examples/LIS3DHTR_IIC_ADC/LIS3DHTR_IIC_ADC.ino

@@ -3,46 +3,44 @@
 
 #include "LIS3DHTR.h"
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-  SoftwareWire myWire(3, 2);
-  LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
-  #define WIRE myWire
+    #include <SoftwareWire.h>
+    SoftwareWire myWire(3, 2);
+    LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
+    #define WIRE myWire
 #else
-  #include <Wire.h>
-  LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
-  #define WIRE Wire
+    #include <Wire.h>
+    LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
+    #define WIRE Wire
 #endif
 
 
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial) {};
-  LIS.begin(WIRE); //IIC init
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial) {};
+    LIS.begin(WIRE); //IIC init
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS) {
-    Serial.println("LIS3DHTR didn't connect.");
-    while (1);
-    return;
-  }
-  //ADC
-  Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
-  Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
-  Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //ADC
+    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
+    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
+    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
+    delay(500);
 }

+ 35 - 37
examples/LIS3DHTR_IIC_AcceleratorReadings/LIS3DHTR_IIC_AcceleratorReadings.ino

@@ -3,47 +3,45 @@
 
 #include "LIS3DHTR.h"
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-  SoftwareWire myWire(3, 2);
-  LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
-  #define WIRE myWire
+    #include <SoftwareWire.h>
+    SoftwareWire myWire(3, 2);
+    LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
+    #define WIRE myWire
 #else
-  #include <Wire.h>
-  LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
-  #define WIRE Wire
+    #include <Wire.h>
+    LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
+    #define WIRE Wire
 #endif
 
 
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial) {};
-  LIS.begin(WIRE); //IIC init
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial) {};
+    LIS.begin(WIRE); //IIC init
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS) {
-    Serial.println("LIS3DHTR didn't connect.");
-    while (1);
-    return;
-  }
-  //3 axis
-  Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
-  Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
-  Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //3 axis
+    Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
+    Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
+    Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
 
-  delay(500);
+    delay(500);
 }

+ 35 - 37
examples/LIS3DHTR_IIC_Temperature/LIS3DHTR_IIC_Temperature.ino

@@ -3,47 +3,45 @@
 
 #include "LIS3DHTR.h"
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-  SoftwareWire myWire(3, 2);
-  LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
-  #define WIRE myWire
+    #include <SoftwareWire.h>
+    SoftwareWire myWire(3, 2);
+    LIS3DHTR<SoftwareWire> LIS(I2C_MODE);//IIC
+    #define WIRE myWire
 #else
-  #include <Wire.h>
-  LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
-  #define WIRE Wire
+    #include <Wire.h>
+    LIS3DHTR<TwoWire> LIS(I2C_MODE);//IIC
+    #define WIRE Wire
 #endif
 
 
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial) {};
-  LIS.begin(WIRE); //IIC init
-  LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
-  //  LIS.closeTemp();//default
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial) {};
+    LIS.begin(WIRE); //IIC init
+    LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
+    //  LIS.closeTemp();//default
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
 
-void loop()
-{
-  if (!LIS) {
-    Serial.println("LIS3DHTR didn't connect.");
-    while (1);
-    return;
-  }
-  //temperature
-  Serial.print("temp:"); Serial.println(LIS.getTemperature());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //temperature
+    Serial.print("temp:"); Serial.println(LIS.getTemperature());
+    delay(500);
 }

+ 36 - 39
examples/LIS3DHTR_SPI/LIS3DHTR_SPI.ino

@@ -2,44 +2,41 @@
 
 #include "LIS3DHTR.h"
 LIS3DHTR<TwoWire> LIS(SPI_MODE); //SPI
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial);
-  LIS.begin(10); //SPI SS/CS
-  LIS.openTemp();//If ADC3 is used, the temperature detection needs to be turned off.
-  //  LIS.closeTemp();//default
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial);
+    LIS.begin(10); //SPI SS/CS
+    LIS.openTemp();//If ADC3 is used, the temperature detection needs to be turned off.
+    //  LIS.closeTemp();//default
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS)
-  {
-    Serial.println("LIS3DHTR didn't connect.");
-    while(1);
-    return;
-  }
-  //3 Axis
-//  Serial.print("x:");Serial.print(LIS.getAccelerationX());Serial.print("  ");
-//  Serial.print("y:");Serial.print(LIS.getAccelerationY());Serial.print("  ");
-//  Serial.print("z:");Serial.println(LIS.getAccelerationZ());
-  //ADC
-//    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
-//    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
-//    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
-  //temperature
-  Serial.print("temp:"); Serial.println(LIS.getTemperature());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //3 Axis
+    //  Serial.print("x:");Serial.print(LIS.getAccelerationX());Serial.print("  ");
+    //  Serial.print("y:");Serial.print(LIS.getAccelerationY());Serial.print("  ");
+    //  Serial.print("z:");Serial.println(LIS.getAccelerationZ());
+    //ADC
+    //    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
+    //    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
+    //    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
+    //temperature
+    Serial.print("temp:"); Serial.println(LIS.getTemperature());
+    delay(500);
 }

+ 28 - 31
examples/LIS3DHTR_SPI_ADC/LIS3DHTR_SPI_ADC.ino

@@ -2,36 +2,33 @@
 
 #include "LIS3DHTR.h"
 LIS3DHTR<TwoWire> LIS(SPI_MODE); //SPI
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial);
-  LIS.begin(10); //SPI SS/CS
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial);
+    LIS.begin(10); //SPI SS/CS
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS)
-  {
-    Serial.println("LIS3DHTR didn't connect.");
-    while(1);
-    return;
-  }
-  //ADC
-  Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
-  Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
-  Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //ADC
+    Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
+    Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
+    Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
+    delay(500);
 }

+ 28 - 31
examples/LIS3DHTR_SPI_AcceleratorReadings/LIS3DHTR_SPI_AcceleratorReadings.ino

@@ -2,36 +2,33 @@
 
 #include "LIS3DHTR.h"
 LIS3DHTR<TwoWire> LIS(SPI_MODE); //SPI
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial);
-  LIS.begin(10); //SPI SS/CS
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial);
+    LIS.begin(10); //SPI SS/CS
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS)
-  {
-    Serial.println("LIS3DHTR didn't connect.");
-    while(1);
-    return;
-  }
-  //3 Axis
-  Serial.print("x:");Serial.print(LIS.getAccelerationX());Serial.print("  ");
-  Serial.print("y:");Serial.print(LIS.getAccelerationY());Serial.print("  ");
-  Serial.print("z:");Serial.println(LIS.getAccelerationZ());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //3 Axis
+    Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print("  ");
+    Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print("  ");
+    Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
+    delay(500);
 }

+ 28 - 31
examples/LIS3DHTR_SPI_Temperature/LIS3DHTR_SPI_Temperature.ino

@@ -2,36 +2,33 @@
 
 #include "LIS3DHTR.h"
 LIS3DHTR<TwoWire> LIS(SPI_MODE); //SPI
-void setup()
-{
-  Serial.begin(115200);
-  while (!Serial);
-  LIS.begin(10); //SPI SS/CS
-  LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
-  //  LIS.closeTemp();//default
-  delay(100);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
-  //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
-  LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
-  //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
+void setup() {
+    Serial.begin(115200);
+    while (!Serial);
+    LIS.begin(10); //SPI SS/CS
+    LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
+    //  LIS.closeTemp();//default
+    delay(100);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
+    //  LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
+    LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
+    //  LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
 }
-void loop()
-{
-  if (!LIS)
-  {
-    Serial.println("LIS3DHTR didn't connect.");
-    while(1);
-    return;
-  }
-  //temperature
-  Serial.print("temp:"); Serial.println(LIS.getTemperature());
-  delay(500);
+void loop() {
+    if (!LIS) {
+        Serial.println("LIS3DHTR didn't connect.");
+        while (1);
+        return;
+    }
+    //temperature
+    Serial.print("temp:"); Serial.println(LIS.getTemperature());
+    delay(500);
 }

+ 255 - 284
src/LIS3DHTR.cpp

@@ -1,66 +1,64 @@
-/*    
- * A library for Grove - 3-Axis Digital Accelerometer ±2g to 16g Ultra-low Power(LIS3DHTR)
- *   
- * Copyright (c) 2019 seeed technology co., ltd.  
- * Author      : Hongtai Liu (lht856@foxmail.com)  
- * Create Time : July 2019
- * Change Log  : 
- *
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+/*
+    A library for Grove - 3-Axis Digital Accelerometer ±2g to 16g Ultra-low Power(LIS3DHTR)
+
+    Copyright (c) 2019 seeed technology co., ltd.
+    Author      : Hongtai Liu (lht856@foxmail.com)
+    Create Time : July 2019
+    Change Log  :
+
+    The MIT License (MIT)
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
 
 
 #include "LIS3DHTR.h"
 #include "SPI.h"
 
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-#else   
-  #include <Wire.h>
+    #include <SoftwareWire.h>
+#else
+    #include <Wire.h>
 #endif
 
 
 template<class T>
-LIS3DHTR<T>::LIS3DHTR(uint8_t busType)
-{
+LIS3DHTR<T>::LIS3DHTR(uint8_t busType) {
     commInterface = busType;
 }
 
 template<class T>
-void LIS3DHTR<T>::begin(T &wire, uint8_t address)
-{
+void LIS3DHTR<T>::begin(T& wire, uint8_t address) {
     _Wire = &wire;
     _Wire->begin();
     devAddr = address;
-    
-    uint8_t config5=LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
-                    LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
-                    
+
+    uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
+                      LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
+
     writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
     delay(LIS3DHTR_CONVERSIONDELAY);
 
     uint8_t config1 =   LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL        |   // Normal Mode
                         LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE        |   // Acceleration Z-Axis Enabled
                         LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE        |   // Acceleration Y-Axis Enabled
-                        LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;     
+                        LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
 
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
 
@@ -84,34 +82,33 @@ void LIS3DHTR<T>::begin(T &wire, uint8_t address)
 }
 
 template<class T>
-void LIS3DHTR<T>::begin(uint8_t sspin)
-{
+void LIS3DHTR<T>::begin(uint8_t sspin) {
     chipSelectPin = sspin;
     pinMode(chipSelectPin, OUTPUT);
-	digitalWrite(chipSelectPin, HIGH);
+    digitalWrite(chipSelectPin, HIGH);
     // start the SPI library:
     SPI.begin();
-	// Maximum SPI frequency is 10MHz, could divide by 2 here:
-	SPI.setClockDivider(SPI_CLOCK_DIV4);
-	// Data is read and written MSb first.
-	SPI.setBitOrder(MSBFIRST);
-	// Data is captured on rising edge of clock (CPHA = 0)
-	// Base value of the clock is HIGH (CPOL = 1)
-	// MODE3 for 328p operation
-	SPI.setDataMode(SPI_MODE3);
+    // Maximum SPI frequency is 10MHz, could divide by 2 here:
+    SPI.setClockDivider(SPI_CLOCK_DIV4);
+    // Data is read and written MSb first.
+    SPI.setBitOrder(MSBFIRST);
+    // Data is captured on rising edge of clock (CPHA = 0)
+    // Base value of the clock is HIGH (CPOL = 1)
+    // MODE3 for 328p operation
+    SPI.setDataMode(SPI_MODE3);
 
     delay(200);
 
-    uint8_t config5=LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
-                    LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
-                    
+    uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
+                      LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
+
     writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
     delay(LIS3DHTR_CONVERSIONDELAY);
 
     uint8_t config1 =   LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL        |   // Normal Mode
                         LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE        |   // Acceleration Z-Axis Enabled
                         LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE        |   // Acceleration Y-Axis Enabled
-                        LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;     
+                        LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
 
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
     delay(LIS3DHTR_CONVERSIONDELAY);
@@ -134,58 +131,52 @@ void LIS3DHTR<T>::begin(uint8_t sspin)
 
 
 template<class T>
-void LIS3DHTR<T>::openTemp()
-{
-    uint8_t config5=LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
-                    LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED;
-                    
+void LIS3DHTR<T>::openTemp() {
+    uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
+                      LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED;
+
     writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
     delay(LIS3DHTR_CONVERSIONDELAY);
 }
 
 template<class T>
-void LIS3DHTR<T>::closeTemp()
-{
-    uint8_t config5=LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
-                    LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
-                    
+void LIS3DHTR<T>::closeTemp() {
+    uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED    |
+                      LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
+
     writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
     delay(LIS3DHTR_CONVERSIONDELAY);
 }
 
 template<class T>
-int16_t LIS3DHTR<T>::getTemperature(void)
-{
+int16_t LIS3DHTR<T>::getTemperature(void) {
 
     int16_t result = ((int16_t) readRegisterInt16(0x0c)) / 256;
 
-    if(commInterface==I2C_MODE){
-        return result+25; 
-    }else if(commInterface==SPI_MODE){
-        return result+20;
+    if (commInterface == I2C_MODE) {
+        return result + 25;
+    } else if (commInterface == SPI_MODE) {
+        return result + 20;
     }
-	
+
 }
 
 template<class T>
-bool LIS3DHTR<T>::isConnection(void)
-{
+bool LIS3DHTR<T>::isConnection(void) {
     return (getDeviceID() == 0x33);
 }
 
 template<class T>
-uint8_t LIS3DHTR<T>::getDeviceID(void)
-{
+uint8_t LIS3DHTR<T>::getDeviceID(void) {
     return readRegister(LIS3DHTR_REG_ACCEL_WHO_AM_I);
 }
 
 template<class T>
-void LIS3DHTR<T>::setPoweMode(power_type_t mode)
-{   
+void LIS3DHTR<T>::setPoweMode(power_type_t mode) {
     uint8_t data = 0;
-    
+
     data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1);
-    
+
     data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_MASK;
     data |=  mode;
 
@@ -196,49 +187,46 @@ void LIS3DHTR<T>::setPoweMode(power_type_t mode)
 
 
 template<class T>
-void LIS3DHTR<T>::setFullScaleRange(scale_type_t range)
-{
+void LIS3DHTR<T>::setFullScaleRange(scale_type_t range) {
     uint8_t data = 0;
-    
-    
+
+
     data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4);
-    
+
     data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_MASK;
-    data |= range; 
+    data |= range;
 
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, data);
     delay(LIS3DHTR_CONVERSIONDELAY);
 
-    switch (range)
-    {
-    case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G:
-      accRange = 1280;
-      break;
-     case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G:
-      accRange = 3968;
-      break;
-     case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G:
-      accRange = 7282;
-      break;
-     case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G:
-      accRange = 16000;
-      break;
-    default:
-      break;
+    switch (range) {
+        case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G:
+            accRange = 1280;
+            break;
+        case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G:
+            accRange = 3968;
+            break;
+        case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G:
+            accRange = 7282;
+            break;
+        case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G:
+            accRange = 16000;
+            break;
+        default:
+            break;
     }
 
 }
 
 
 template<class T>
-void LIS3DHTR<T>::setOutputDataRate(odr_type_t odr)
-{
+void LIS3DHTR<T>::setOutputDataRate(odr_type_t odr) {
     uint8_t data = 0;
-    
+
     data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1);
 
     data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_MASK;
-    data |= odr; 
+    data |= odr;
 
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, data);
     delay(LIS3DHTR_CONVERSIONDELAY);
@@ -246,11 +234,10 @@ void LIS3DHTR<T>::setOutputDataRate(odr_type_t odr)
 
 
 template<class T>
-void LIS3DHTR<T>::getAcceleration(float* x, float* y, float* z)
-{
-   // Read the Accelerometer
+void LIS3DHTR<T>::getAcceleration(float* x, float* y, float* z) {
+    // Read the Accelerometer
     uint8_t xAccelLo, xAccelHi, yAccelLo, yAccelHi, zAccelLo, zAccelHi;
-    
+
     // Read the Data
     // Reading the Low X-Axis Acceleration Data Register
     xAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_L);
@@ -258,32 +245,31 @@ void LIS3DHTR<T>::getAcceleration(float* x, float* y, float* z)
     xAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_H);
     // Conversion of the result
     // 16-bit signed result for X-Axis Acceleration Data of LIS3DHTR
-    *x = (float)((int16_t)((xAccelHi << 8) | xAccelLo))/accRange;
-    
+    *x = (float)((int16_t)((xAccelHi << 8) | xAccelLo)) / accRange;
+
     // Reading the Low Y-Axis Acceleration Data Register
     yAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_L);
     // Reading the High Y-Axis Acceleration Data Register
     yAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_H);
     // Conversion of the result
     // 16-bit signed result for Y-Axis Acceleration Data of LIS3DHTR
-    *y = (float)((int16_t)((yAccelHi << 8) | yAccelLo))/accRange;
-    
+    *y = (float)((int16_t)((yAccelHi << 8) | yAccelLo)) / accRange;
+
     // Reading the Low Z-Axis Acceleration Data Register
     zAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_L);
     // Reading the High Z-Axis Acceleration Data Register
     zAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_H);
     // Conversion of the result
     // 16-bit signed result for Z-Axis Acceleration Data of LIS3DHTR
-    *z = (float)((int16_t)((zAccelHi << 8)) | zAccelLo)/accRange;
+    *z = (float)((int16_t)((zAccelHi << 8)) | zAccelLo) / accRange;
 }
 
 template<class T>
-float LIS3DHTR<T>::getAccelerationX(void)
-{
+float LIS3DHTR<T>::getAccelerationX(void) {
     // Read the Accelerometer
     uint8_t xAccelLo, xAccelHi;
     int16_t x;
-    
+
     // Read the Data
     // Reading the Low X-Axis Acceleration Data Register
     xAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_L);
@@ -292,17 +278,16 @@ float LIS3DHTR<T>::getAccelerationX(void)
     // Conversion of the result
     // 16-bit signed result for X-Axis Acceleration Data of LIS3DHTR
     x = (int16_t)((xAccelHi << 8) | xAccelLo);
-    
-    return (float)x/accRange;
+
+    return (float)x / accRange;
 }
 
 template<class T>
-float LIS3DHTR<T>::getAccelerationY(void)
-{
-   // Read the Accelerometer
+float LIS3DHTR<T>::getAccelerationY(void) {
+    // Read the Accelerometer
     uint8_t yAccelLo, yAccelHi;
     int16_t y;
-    
+
     // Reading the Low Y-Axis Acceleration Data Register
     yAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_L);
     // Reading the High Y-Axis Acceleration Data Register
@@ -310,14 +295,13 @@ float LIS3DHTR<T>::getAccelerationY(void)
     // Conversion of the result
     // 16-bit signed result for Y-Axis Acceleration Data of LIS3DHTR
     y = (int16_t)((yAccelHi << 8) | yAccelLo);
-   
-   return (float)y/accRange;
+
+    return (float)y / accRange;
 }
 
 template<class T>
-float LIS3DHTR<T>::getAccelerationZ(void)
-{
-   // Read the Accelerometer
+float LIS3DHTR<T>::getAccelerationZ(void) {
+    // Read the Accelerometer
     uint8_t zAccelLo, zAccelHi;
     int16_t z;
 
@@ -328,153 +312,145 @@ float LIS3DHTR<T>::getAccelerationZ(void)
     // Conversion of the result
     // 16-bit signed result for Z-Axis Acceleration Data of LIS3DHTR
     z = (int16_t)((zAccelHi << 8) | zAccelLo);
-  
-    return (float)z/accRange;
+
+    return (float)z / accRange;
 }
 
 template<class T>
-uint16_t LIS3DHTR<T>::readbitADC1( void )
-{
-    uint8_t adc1_l,adc1_h;
-	int16_t intTemp;
-	uint16_t uintTemp;
-    adc1_l=readRegister(0x08);
-    adc1_h=readRegister(0x09);
-
-    intTemp=(int16_t)(adc1_h<<8)|adc1_l;
-	intTemp = 0 - intTemp;
-	uintTemp = intTemp + 32768;
-	return uintTemp>>6;
+uint16_t LIS3DHTR<T>::readbitADC1(void) {
+    uint8_t adc1_l, adc1_h;
+    int16_t intTemp;
+    uint16_t uintTemp;
+    adc1_l = readRegister(0x08);
+    adc1_h = readRegister(0x09);
+
+    intTemp = (int16_t)(adc1_h << 8) | adc1_l;
+    intTemp = 0 - intTemp;
+    uintTemp = intTemp + 32768;
+    return uintTemp >> 6;
 }
 template<class T>
-uint16_t LIS3DHTR<T>::readbitADC2( void )
-{
-    uint8_t adc2_l,adc2_h;
-	int16_t intTemp;
-	uint16_t uintTemp;
-    adc2_l=readRegister(0x0A);
-    adc2_h=readRegister(0x0B);
-    intTemp=(int16_t)(adc2_h<<8)|adc2_l;
-	intTemp = 0 - intTemp;
-	uintTemp = intTemp + 32768;
-	return uintTemp>>6;
+uint16_t LIS3DHTR<T>::readbitADC2(void) {
+    uint8_t adc2_l, adc2_h;
+    int16_t intTemp;
+    uint16_t uintTemp;
+    adc2_l = readRegister(0x0A);
+    adc2_h = readRegister(0x0B);
+    intTemp = (int16_t)(adc2_h << 8) | adc2_l;
+    intTemp = 0 - intTemp;
+    uintTemp = intTemp + 32768;
+    return uintTemp >> 6;
 }
 
 template<class T>
-uint16_t LIS3DHTR<T>::readbitADC3( void )
-{
-    uint8_t adc3_l,adc3_h;
-	int16_t intTemp;
-	uint16_t uintTemp;
-    adc3_l=readRegister(0x0C);
-    adc3_h=readRegister(0x0D);
-
-    intTemp=(int16_t)(adc3_h<<8)|adc3_l;
-	intTemp = 0 - intTemp;
-	uintTemp = intTemp + 32768;
-	return uintTemp>>6;
+uint16_t LIS3DHTR<T>::readbitADC3(void) {
+    uint8_t adc3_l, adc3_h;
+    int16_t intTemp;
+    uint16_t uintTemp;
+    adc3_l = readRegister(0x0C);
+    adc3_h = readRegister(0x0D);
+
+    intTemp = (int16_t)(adc3_h << 8) | adc3_l;
+    intTemp = 0 - intTemp;
+    uintTemp = intTemp + 32768;
+    return uintTemp >> 6;
 }
 
 template<class T>
-void LIS3DHTR<T>::writeRegister(uint8_t reg, uint8_t val){
-	switch (commInterface) {
-	case I2C_MODE:
-		//Write the byte
-        _Wire->beginTransmission(devAddr);
-        _Wire->write(reg);
-        _Wire->write(val);
-        _Wire->endTransmission();
-		break;
-	case SPI_MODE:
-		digitalWrite(chipSelectPin, LOW);
-		SPI.transfer(reg);
-		SPI.transfer(val);
-		digitalWrite(chipSelectPin, HIGH);
-		break;
-	default:
-		break;
-	}
+void LIS3DHTR<T>::writeRegister(uint8_t reg, uint8_t val) {
+    switch (commInterface) {
+        case I2C_MODE:
+            //Write the byte
+            _Wire->beginTransmission(devAddr);
+            _Wire->write(reg);
+            _Wire->write(val);
+            _Wire->endTransmission();
+            break;
+        case SPI_MODE:
+            digitalWrite(chipSelectPin, LOW);
+            SPI.transfer(reg);
+            SPI.transfer(val);
+            digitalWrite(chipSelectPin, HIGH);
+            break;
+        default:
+            break;
+    }
 }
 
 template<class T>
-void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer , uint8_t reg, uint8_t length)
-{
-
-	//define pointer that will point to the external space
-	uint8_t i = 0;
-	uint8_t c = 0;
-	uint8_t tempFFCounter = 0;
-	switch (commInterface) {
-	case I2C_MODE:
-		_Wire->beginTransmission(devAddr);
-		reg |= 0x80; //turn auto-increment bit on, bit 7 for I2C
-		_Wire->write(reg);
-		_Wire->endTransmission();
-		_Wire->requestFrom(devAddr, length);
-
-		while ( (_Wire->available()) && (i < length))  // slave may send less than requested
-		{
-			c = _Wire->read(); // receive a byte as character
-			*outputPointer = c;
-			outputPointer++;
-			i++;
-		}
-		break;
-	case SPI_MODE:
-		digitalWrite(chipSelectPin, LOW);
-		SPI.transfer(reg | 0x80 | 0x40);  //Ored with "read request" bit and "auto increment" bit
-        while ( i < length ) // slave may send less than requested
-		{
-			c = SPI.transfer(0x00); // receive a byte as character
-			*outputPointer = c;
-			outputPointer++;
-			i++;
-		}
-		digitalWrite(chipSelectPin, HIGH);
-		break;
-	default:
-		break;
-	}
+void LIS3DHTR<T>::readRegisterRegion(uint8_t* outputPointer, uint8_t reg, uint8_t length) {
+
+    //define pointer that will point to the external space
+    uint8_t i = 0;
+    uint8_t c = 0;
+    uint8_t tempFFCounter = 0;
+    switch (commInterface) {
+        case I2C_MODE:
+            _Wire->beginTransmission(devAddr);
+            reg |= 0x80; //turn auto-increment bit on, bit 7 for I2C
+            _Wire->write(reg);
+            _Wire->endTransmission();
+            _Wire->requestFrom(devAddr, length);
+
+            while ((_Wire->available()) && (i < length)) { // slave may send less than requested
+                c = _Wire->read(); // receive a byte as character
+                *outputPointer = c;
+                outputPointer++;
+                i++;
+            }
+            break;
+        case SPI_MODE:
+            digitalWrite(chipSelectPin, LOW);
+            SPI.transfer(reg | 0x80 | 0x40);  //Ored with "read request" bit and "auto increment" bit
+            while (i < length) { // slave may send less than requested
+                c = SPI.transfer(0x00); // receive a byte as character
+                *outputPointer = c;
+                outputPointer++;
+                i++;
+            }
+            digitalWrite(chipSelectPin, HIGH);
+            break;
+        default:
+            break;
+    }
 }
 
 template<class T>
-uint16_t LIS3DHTR<T>::readRegisterInt16(uint8_t reg )
-{
-	{
-		uint8_t myBuffer[2];
-		readRegisterRegion(myBuffer, reg, 2); 
-		uint16_t output = myBuffer[0] | uint16_t(myBuffer[1] << 8);
-        
-		return output;
-	}
+uint16_t LIS3DHTR<T>::readRegisterInt16(uint8_t reg) {
+    {
+        uint8_t myBuffer[2];
+        readRegisterRegion(myBuffer, reg, 2);
+        uint16_t output = myBuffer[0] | uint16_t(myBuffer[1] << 8);
+
+        return output;
+    }
 
 }
 
 template<class T>
-uint8_t LIS3DHTR<T>::readRegister(uint8_t reg){
-	uint8_t result;
-	uint8_t numBytes = 1;
-	switch (commInterface) {
-	case I2C_MODE:
-        _Wire->beginTransmission(devAddr);
-        _Wire->write(reg);
-        _Wire->endTransmission();
-        _Wire->requestFrom((int16_t)devAddr, 1);
-        while(_Wire->available())
-        {
-            result = _Wire->read();
-        }
-		break;
-	case SPI_MODE:
-		digitalWrite(chipSelectPin, LOW);
-		SPI.transfer(reg | 0x80);  
-		result = SPI.transfer(0x00);
-		digitalWrite(chipSelectPin, HIGH);
-		break;
-	default:
-		break;
-	}
-	return result;
+uint8_t LIS3DHTR<T>::readRegister(uint8_t reg) {
+    uint8_t result;
+    uint8_t numBytes = 1;
+    switch (commInterface) {
+        case I2C_MODE:
+            _Wire->beginTransmission(devAddr);
+            _Wire->write(reg);
+            _Wire->endTransmission();
+            _Wire->requestFrom((int16_t)devAddr, 1);
+            while (_Wire->available()) {
+                result = _Wire->read();
+            }
+            break;
+        case SPI_MODE:
+            digitalWrite(chipSelectPin, LOW);
+            SPI.transfer(reg | 0x80);
+            result = SPI.transfer(0x00);
+            digitalWrite(chipSelectPin, HIGH);
+            break;
+        default:
+            break;
+    }
+    return result;
 }
 
 template<class T>
@@ -485,7 +461,7 @@ void LIS3DHTR<T>::click(uint8_t c, uint8_t click_thresh, uint8_t limit, uint8_t
         writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG3, r);
         writeRegister(LIS3DHTR_REG_ACCEL_CLICK_CFG, 0);
         return;
-  }
+    }
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG3, 0x80);
     writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG5, 0x08);
 
@@ -508,8 +484,7 @@ void LIS3DHTR<T>::click(uint8_t c, uint8_t click_thresh, uint8_t limit, uint8_t
 
 //Only supports IIC
 template<class T>
-void LIS3DHTR<T>::write8(uint8_t reg, uint8_t val)
-{
+void LIS3DHTR<T>::write8(uint8_t reg, uint8_t val) {
     _Wire->beginTransmission(devAddr);
     _Wire->write(reg);
     _Wire->write(val);
@@ -517,33 +492,29 @@ void LIS3DHTR<T>::write8(uint8_t reg, uint8_t val)
 }
 
 template<class T>
-uint8_t LIS3DHTR<T>::read8(uint8_t reg)
-{    
+uint8_t LIS3DHTR<T>::read8(uint8_t reg) {
     uint8_t data = 0;
     _Wire->beginTransmission(devAddr);
     _Wire->write(reg);
     _Wire->endTransmission();
     _Wire->requestFrom((int16_t)devAddr, 1);
-    while(_Wire->available())
-    {
+    while (_Wire->available()) {
         data = _Wire->read();
     }
-    
+
     return data;
 }
 
 template<class T>
-uint16_t LIS3DHTR<T>::read16(uint8_t reg)
-{
+uint16_t LIS3DHTR<T>::read16(uint8_t reg) {
     uint16_t msb = 0, lsb = 0;
-    
+
     _Wire->beginTransmission(devAddr);
     _Wire->write(reg);
     _Wire->endTransmission();
-    
+
     _Wire->requestFrom((int16_t)devAddr, 2);
-    while(_Wire->available())
-    {
+    while (_Wire->available()) {
         lsb = _Wire->read();
         msb = _Wire->read();
     }
@@ -552,17 +523,15 @@ uint16_t LIS3DHTR<T>::read16(uint8_t reg)
 }
 
 template<class T>
-uint32_t LIS3DHTR<T>::read24(uint8_t reg)
-{
+uint32_t LIS3DHTR<T>::read24(uint8_t reg) {
     uint32_t hsb = 0, msb = 0, lsb = 0;
-    
+
     _Wire->beginTransmission(devAddr);
     _Wire->write(reg);
     _Wire->endTransmission();
-    
+
     _Wire->requestFrom((int16_t)devAddr, 3);
-    while(_Wire->available())
-    {
+    while (_Wire->available()) {
         lsb = _Wire->read();
         msb = _Wire->read();
         hsb = _Wire->read();
@@ -572,27 +541,29 @@ uint32_t LIS3DHTR<T>::read24(uint8_t reg)
 }
 
 template<class T>
-void LIS3DHTR<T>::read(uint8_t reg, uint8_t *buf, uint16_t len)
-{
+void LIS3DHTR<T>::read(uint8_t reg, uint8_t* buf, uint16_t len) {
     _Wire->beginTransmission(devAddr);
     _Wire->write(reg);
     _Wire->endTransmission();
-    
+
     _Wire->requestFrom((int16_t)devAddr, len);
-    while(_Wire->available())
-    {
-        for(uint16_t i = 0; i < len; i ++) buf[i] = _Wire->read();
+    while (_Wire->available()) {
+        for (uint16_t i = 0; i < len; i ++) {
+            buf[i] = _Wire->read();
+        }
     }
 }
 
 
 
 template<class T>
-LIS3DHTR<T>::operator bool()  { return isConnection(); }
+LIS3DHTR<T>::operator bool()  {
+    return isConnection();
+}
 
 
 #ifdef SOFTWAREWIRE
-  template class LIS3DHTR<SoftwareWire>;
+    template class LIS3DHTR<SoftwareWire>;
 #else
-  template class LIS3DHTR<TwoWire>;
+    template class LIS3DHTR<TwoWire>;
 #endif

+ 180 - 184
src/LIS3DHTR.h

@@ -1,39 +1,39 @@
 /*
- * The MIT License (MIT)
- * 
- * Author: Hongtai Liu (lht856@foxmail.com)
- * 
- * Copyright (C) 2019  Seeed Technology Co.,Ltd. 
- * 
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- * 
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+    The MIT License (MIT)
+
+    Author: Hongtai Liu (lht856@foxmail.com)
+
+    Copyright (C) 2019  Seeed Technology Co.,Ltd.
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
 
 #if ARDUINO >= 100
-#include "Arduino.h"
+    #include "Arduino.h"
 #else
-#include "WProgram.h"
+    #include "WProgram.h"
 #endif
 // #define SOFTWAREWIRE
 #ifdef SOFTWAREWIRE
-  #include <SoftwareWire.h>
-#else   
-  #include <Wire.h>
+    #include <SoftwareWire.h>
+#else
+    #include <Wire.h>
 #endif
 
 
@@ -49,145 +49,142 @@
 /**************************************************************************
     I2C ADDRESS/BITS
 **************************************************************************/
-    #define LIS3DHTR_DEFAULT_ADDRESS                        (0x18)    // 3C >> 1 = 7-bit default
-    #define LIS3DHTR_ADDRESS_UPDATED                        (0x19)    // 
+#define LIS3DHTR_DEFAULT_ADDRESS                        (0x18)    // 3C >> 1 = 7-bit default
+#define LIS3DHTR_ADDRESS_UPDATED                        (0x19)    // 
 
 /**************************************************************************
     CONVERSION DELAY (in mS)
 **************************************************************************/
-    #define LIS3DHTR_CONVERSIONDELAY                        (100)
+#define LIS3DHTR_CONVERSIONDELAY                        (100)
 
 /**************************************************************************
     ACCELEROMETER REGISTERS
 **************************************************************************/
-    #define LIS3DHTR_REG_ACCEL_STATUS                       (0x07)      // Status Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC1_L                   (0x28)      // 1-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC1_H                   (0x29)      // 1-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC2_L                   (0x2A)      // 2-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC2_H                   (0x2B)      // 2-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC3_L                   (0x2C)      // 3-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_ADC3_H                   (0x2D)      // 3-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_WHO_AM_I                     (0x0F)      // Device identification Register
-    #define LIS3DHTR_REG_TEMP_CFG                           (0x1F)      // Temperature Sensor Register
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1                    (0x20)      // Accelerometer Control Register 1
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG2                    (0x21)      // Accelerometer Control Register 2
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG3                    (0x22)      // Accelerometer Control Register 3
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4                    (0x23)      // Accelerometer Control Register 4
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG5                    (0x24)      // Accelerometer Control Register 5
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG6                    (0x25)      // Accelerometer Control Register 6
-    #define LIS3DHTR_REG_ACCEL_REFERENCE                    (0x26)      // Reference/Datacapture Register
-    #define LIS3DHTR_REG_ACCEL_STATUS2                      (0x27)      // Status Register 2
-    #define LIS3DHTR_REG_ACCEL_OUT_X_L                      (0x28)      // X-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_X_H                      (0x29)      // X-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_OUT_Y_L                      (0x2A)      // Y-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_Y_H                      (0x2B)      // Y-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_OUT_Z_L                      (0x2C)      // Z-Axis Acceleration Data Low Register
-    #define LIS3DHTR_REG_ACCEL_OUT_Z_H                      (0x2D)      // Z-Axis Acceleration Data High Register
-    #define LIS3DHTR_REG_ACCEL_FIFO_CTRL                    (0x2E)      // FIFO Control Register
-    #define LIS3DHTR_REG_ACCEL_FIFO_SRC                     (0x2F)      // FIFO Source Register
-    #define LIS3DHTR_REG_ACCEL_INT1_CFG                     (0x30)      // Interrupt Configuration Register
-    #define LIS3DHTR_REG_ACCEL_INT1_SRC                     (0x31)      // Interrupt Source Register
-    #define LIS3DHTR_REG_ACCEL_INT1_THS                     (0x32)      // Interrupt Threshold Register
-    #define LIS3DHTR_REG_ACCEL_INT1_DURATION                (0x33)      // Interrupt Duration Register
-    #define LIS3DHTR_REG_ACCEL_CLICK_CFG                    (0x38)      // Interrupt Click Recognition Register
-    #define LIS3DHTR_REG_ACCEL_CLICK_SRC                    (0x39)      // Interrupt Click Source Register
-    #define LIS3DHTR_REG_ACCEL_CLICK_THS                    (0x3A)      // Interrupt Click Threshold Register
-    #define LIS3DHTR_REG_ACCEL_TIME_LIMIT                   (0x3B)      // Click Time Limit Register
-    #define LIS3DHTR_REG_ACCEL_TIME_LATENCY                 (0x3C)      // Click Time Latency Register
-    #define LIS3DHTR_REG_ACCEL_TIME_WINDOW                  (0x3D)      // Click Time Window Register
+#define LIS3DHTR_REG_ACCEL_STATUS                       (0x07)      // Status Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC1_L                   (0x28)      // 1-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC1_H                   (0x29)      // 1-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC2_L                   (0x2A)      // 2-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC2_H                   (0x2B)      // 2-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC3_L                   (0x2C)      // 3-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_ADC3_H                   (0x2D)      // 3-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_WHO_AM_I                     (0x0F)      // Device identification Register
+#define LIS3DHTR_REG_TEMP_CFG                           (0x1F)      // Temperature Sensor Register
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1                    (0x20)      // Accelerometer Control Register 1
+#define LIS3DHTR_REG_ACCEL_CTRL_REG2                    (0x21)      // Accelerometer Control Register 2
+#define LIS3DHTR_REG_ACCEL_CTRL_REG3                    (0x22)      // Accelerometer Control Register 3
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4                    (0x23)      // Accelerometer Control Register 4
+#define LIS3DHTR_REG_ACCEL_CTRL_REG5                    (0x24)      // Accelerometer Control Register 5
+#define LIS3DHTR_REG_ACCEL_CTRL_REG6                    (0x25)      // Accelerometer Control Register 6
+#define LIS3DHTR_REG_ACCEL_REFERENCE                    (0x26)      // Reference/Datacapture Register
+#define LIS3DHTR_REG_ACCEL_STATUS2                      (0x27)      // Status Register 2
+#define LIS3DHTR_REG_ACCEL_OUT_X_L                      (0x28)      // X-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_X_H                      (0x29)      // X-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_OUT_Y_L                      (0x2A)      // Y-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_Y_H                      (0x2B)      // Y-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_OUT_Z_L                      (0x2C)      // Z-Axis Acceleration Data Low Register
+#define LIS3DHTR_REG_ACCEL_OUT_Z_H                      (0x2D)      // Z-Axis Acceleration Data High Register
+#define LIS3DHTR_REG_ACCEL_FIFO_CTRL                    (0x2E)      // FIFO Control Register
+#define LIS3DHTR_REG_ACCEL_FIFO_SRC                     (0x2F)      // FIFO Source Register
+#define LIS3DHTR_REG_ACCEL_INT1_CFG                     (0x30)      // Interrupt Configuration Register
+#define LIS3DHTR_REG_ACCEL_INT1_SRC                     (0x31)      // Interrupt Source Register
+#define LIS3DHTR_REG_ACCEL_INT1_THS                     (0x32)      // Interrupt Threshold Register
+#define LIS3DHTR_REG_ACCEL_INT1_DURATION                (0x33)      // Interrupt Duration Register
+#define LIS3DHTR_REG_ACCEL_CLICK_CFG                    (0x38)      // Interrupt Click Recognition Register
+#define LIS3DHTR_REG_ACCEL_CLICK_SRC                    (0x39)      // Interrupt Click Source Register
+#define LIS3DHTR_REG_ACCEL_CLICK_THS                    (0x3A)      // Interrupt Click Threshold Register
+#define LIS3DHTR_REG_ACCEL_TIME_LIMIT                   (0x3B)      // Click Time Limit Register
+#define LIS3DHTR_REG_ACCEL_TIME_LATENCY                 (0x3C)      // Click Time Latency Register
+#define LIS3DHTR_REG_ACCEL_TIME_WINDOW                  (0x3D)      // Click Time Window Register
 
 
 /**************************************************************************
     TEMPERATURE REGISTER DESCRIPTION
 **************************************************************************/
-    #define LIS3DHTR_REG_TEMP_ADC_PD_MASK                   (0x80)      // ADC Power Enable Status
-    #define LIS3DHTR_REG_TEMP_ADC_PD_DISABLED               (0x00)      // ADC Disabled
-    #define LIS3DHTR_REG_TEMP_ADC_PD_ENABLED                (0x80)      // ADC Enabled
+#define LIS3DHTR_REG_TEMP_ADC_PD_MASK                   (0x80)      // ADC Power Enable Status
+#define LIS3DHTR_REG_TEMP_ADC_PD_DISABLED               (0x00)      // ADC Disabled
+#define LIS3DHTR_REG_TEMP_ADC_PD_ENABLED                (0x80)      // ADC Enabled
 
-    #define LIS3DHTR_REG_TEMP_TEMP_EN_MASK                  (0x40)      // Temperature Sensor (T) Enable Status
-    #define LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED              (0x00)      // Temperature Sensor (T) Disabled
-    #define LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED               (0x40)      // Temperature Sensor (T) Enabled
+#define LIS3DHTR_REG_TEMP_TEMP_EN_MASK                  (0x40)      // Temperature Sensor (T) Enable Status
+#define LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED              (0x00)      // Temperature Sensor (T) Disabled
+#define LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED               (0x40)      // Temperature Sensor (T) Enabled
 
 /**************************************************************************
     ACCELEROMETER CONTROL REGISTER 1 DESCRIPTION
 **************************************************************************/
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_MASK          (0xF0)      // Acceleration Data Rate Selection
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_PD            (0x00)      // Power-Down Mode
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1             (0x10)      // Normal / Low Power Mode (1 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_10            (0x20)      // Normal / Low Power Mode (10 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_25            (0x30)      // Normal / Low Power Mode (25 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_50            (0x40)      // Normal / Low Power Mode (50 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_100           (0x50)      // Normal / Low Power Mode (100 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_200           (0x60)      // Normal / Low Power Mode (200 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_400           (0x70)      // Normal / Low Power Mode (400 Hz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1_6K          (0x80)      // Low Power Mode (1.6 KHz)
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_5K            (0x90)      // Normal (1.25 KHz) / Low Power Mode (5 KHz)
-
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_MASK          (0x08)      // Low Power Mode Enable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL        (0x00)      // Normal Mode
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW           (0x08)      // Low Power Mode
-
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_MASK          (0x04)      // Acceleration Z-Axis Enable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_DISABLE       (0x00)      // Acceleration Z-Axis Disabled
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE        (0x04)      // Acceleration Z-Axis Enabled
-
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_MASK          (0x02)      // Acceleration Y-Axis Enable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_DISABLE       (0x00)      // Acceleration Y-Axis Disabled
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE        (0x02)      // Acceleration Y-Axis Enabled
-
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_MASK          (0x01)      // Acceleration X-Axis Enable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_DISABLE       (0x00)      // Acceleration X-Axis Disabled
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE        (0x01)      // Acceleration X-Axis Enabled
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_MASK          (0xF0)      // Acceleration Data Rate Selection
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_PD            (0x00)      // Power-Down Mode
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1             (0x10)      // Normal / Low Power Mode (1 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_10            (0x20)      // Normal / Low Power Mode (10 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_25            (0x30)      // Normal / Low Power Mode (25 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_50            (0x40)      // Normal / Low Power Mode (50 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_100           (0x50)      // Normal / Low Power Mode (100 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_200           (0x60)      // Normal / Low Power Mode (200 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_400           (0x70)      // Normal / Low Power Mode (400 Hz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1_6K          (0x80)      // Low Power Mode (1.6 KHz)
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_5K            (0x90)      // Normal (1.25 KHz) / Low Power Mode (5 KHz)
+
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_MASK          (0x08)      // Low Power Mode Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL        (0x00)      // Normal Mode
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW           (0x08)      // Low Power Mode
+
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_MASK          (0x04)      // Acceleration Z-Axis Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_DISABLE       (0x00)      // Acceleration Z-Axis Disabled
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE        (0x04)      // Acceleration Z-Axis Enabled
+
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_MASK          (0x02)      // Acceleration Y-Axis Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_DISABLE       (0x00)      // Acceleration Y-Axis Disabled
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE        (0x02)      // Acceleration Y-Axis Enabled
+
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_MASK          (0x01)      // Acceleration X-Axis Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_DISABLE       (0x00)      // Acceleration X-Axis Disabled
+#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE        (0x01)      // Acceleration X-Axis Enabled
 
 /**************************************************************************
     ACCELEROMETER CONTROL REGISTER 4 DESCRIPTION
 **************************************************************************/
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_MASK           (0x80)      // Block Data Update
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_CONTINUOUS     (0x00)      // Continuous Update
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED     (0x80)      // Output Registers Not Updated until MSB and LSB Read
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_MASK           (0x80)      // Block Data Update
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_CONTINUOUS     (0x00)      // Continuous Update
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED     (0x80)      // Output Registers Not Updated until MSB and LSB Read
 
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MASK           (0x40)      // Big/Little Endian Data Selection
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB            (0x00)      // Data LSB @ lower address
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MSB            (0x40)      // Data MSB @ lower address
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MASK           (0x40)      // Big/Little Endian Data Selection
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB            (0x00)      // Data LSB @ lower address
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MSB            (0x40)      // Data MSB @ lower address
 
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_MASK            (0x30)      // Full-Scale Selection
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G              (0x00)      // +/- 2G
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G              (0x10)      // +/- 4G
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G              (0x20)      // +/- 8G
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G             (0x30)      // +/- 16G
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_MASK            (0x30)      // Full-Scale Selection
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G              (0x00)      // +/- 2G
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G              (0x10)      // +/- 4G
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G              (0x20)      // +/- 8G
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G             (0x30)      // +/- 16G
 
 
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_MASK            (0x08)      // High Resolution Output Mode
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE         (0x00)      // High Resolution Disable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_ENABLE          (0x08)      // High Resolution Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_MASK            (0x08)      // High Resolution Output Mode
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE         (0x00)      // High Resolution Disable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_ENABLE          (0x08)      // High Resolution Enable
 
 
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_MASK            (0x06)      // Self-Test Enable
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL          (0x00)      // Normal Mode
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_0               (0x02)      // Self-Test 0
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_1               (0x04)      // Self-Test 1
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_MASK            (0x06)      // Self-Test Enable
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL          (0x00)      // Normal Mode
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_0               (0x02)      // Self-Test 0
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_1               (0x04)      // Self-Test 1
 
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_MASK           (0x01)      // SPI Serial Interface Mode Selection
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE          (0x00)      // 4-Wire Interface
-    #define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_3WIRE          (0x01)      // 3-Wire Interface
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_MASK           (0x01)      // SPI Serial Interface Mode Selection
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE          (0x00)      // 4-Wire Interface
+#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_3WIRE          (0x01)      // 3-Wire Interface
 
 
-enum power_type_t // power mode
-{
-  POWER_MODE_NORMAL = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL,
-  POWER_MODE_LOW = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW
+enum power_type_t { // power mode
+    POWER_MODE_NORMAL = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL,
+    POWER_MODE_LOW = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW
 };
 
-enum scale_type_t // measurement rage
-{
-  LIS3DHTR_RANGE_2G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G, // 
-  LIS3DHTR_RANGE_4G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G, // 
-  LIS3DHTR_RANGE_8G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G, // 
-  LIS3DHTR_RANGE_16G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G, // 
+enum scale_type_t { // measurement rage
+    LIS3DHTR_RANGE_2G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G, //
+    LIS3DHTR_RANGE_4G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G, //
+    LIS3DHTR_RANGE_8G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G, //
+    LIS3DHTR_RANGE_16G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G, //
 };
 
-enum odr_type_t // output data rate
-{
+enum odr_type_t { // output data rate
     LIS3DHTR_DATARATE_POWERDOWN        = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_PD,
     LIS3DHTR_DATARATE_1HZ              = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1,
     LIS3DHTR_DATARATE_10HZ             = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_10,
@@ -201,57 +198,56 @@ enum odr_type_t // output data rate
 };
 
 template <class T>
-class LIS3DHTR
-{
-    public:
-        LIS3DHTR(uint8_t busType);
-
-        bool isConnection(void);
-
-        void begin(T &wire = Wire, uint8_t address = LIS3DHTR_ADDRESS_UPDATED);//初始化
-
-        void begin(uint8_t sspin);
-
-        void setPoweMode(power_type_t mode);    
-        void setFullScaleRange(scale_type_t range);
-        void setOutputDataRate(odr_type_t odr);
-        
-        void getAcceleration(float* x, float* y, float* z);
-        float getAccelerationX(void);
-        float getAccelerationY(void);
-        float getAccelerationZ(void);
-        void click(uint8_t c, uint8_t click_thresh, uint8_t limit=10, uint8_t latency=20, uint8_t window=255) ;
-        
-        void openTemp();
-        void closeTemp();
-
-        uint16_t readbitADC1(void);
-        uint16_t readbitADC2(void);
-        uint16_t readbitADC3(void);
-        
-        int16_t getTemperature(void);
-        
-        uint8_t getDeviceID(void);
-        
-        void reset(void);
-        operator bool(); 
-    private:
-    
-        void write8(uint8_t reg, uint8_t val);
-        uint8_t read8(uint8_t reg);
-        uint16_t read16(uint8_t reg);
-        uint32_t read24(uint8_t reg);
-        void read(uint8_t reg, uint8_t *buf, uint16_t len);
-        void readRegisterRegion(uint8_t *outputPointer , uint8_t offset, uint8_t length);
-        void writeRegister(uint8_t reg, uint8_t val);
-        uint8_t readRegister(uint8_t reg);
-        uint16_t readRegisterInt16(uint8_t reg );
-        uint8_t devAddr;
-        int16_t accRange;
-        uint8_t commInterface;
-        uint8_t chipSelectPin;
-        T *_Wire;
-    
+class LIS3DHTR {
+  public:
+    LIS3DHTR(uint8_t busType);
+
+    bool isConnection(void);
+
+    void begin(T& wire = Wire, uint8_t address = LIS3DHTR_ADDRESS_UPDATED);//初始化
+
+    void begin(uint8_t sspin);
+
+    void setPoweMode(power_type_t mode);
+    void setFullScaleRange(scale_type_t range);
+    void setOutputDataRate(odr_type_t odr);
+
+    void getAcceleration(float* x, float* y, float* z);
+    float getAccelerationX(void);
+    float getAccelerationY(void);
+    float getAccelerationZ(void);
+    void click(uint8_t c, uint8_t click_thresh, uint8_t limit = 10, uint8_t latency = 20, uint8_t window = 255) ;
+
+    void openTemp();
+    void closeTemp();
+
+    uint16_t readbitADC1(void);
+    uint16_t readbitADC2(void);
+    uint16_t readbitADC3(void);
+
+    int16_t getTemperature(void);
+
+    uint8_t getDeviceID(void);
+
+    void reset(void);
+    operator bool();
+  private:
+
+    void write8(uint8_t reg, uint8_t val);
+    uint8_t read8(uint8_t reg);
+    uint16_t read16(uint8_t reg);
+    uint32_t read24(uint8_t reg);
+    void read(uint8_t reg, uint8_t* buf, uint16_t len);
+    void readRegisterRegion(uint8_t* outputPointer, uint8_t offset, uint8_t length);
+    void writeRegister(uint8_t reg, uint8_t val);
+    uint8_t readRegister(uint8_t reg);
+    uint16_t readRegisterInt16(uint8_t reg);
+    uint8_t devAddr;
+    int16_t accRange;
+    uint8_t commInterface;
+    uint8_t chipSelectPin;
+    T* _Wire;
+
 };
 
 #endif /*SEEED_LIS3DHTR_H*/