Kaynağa Gözat

change int to short to fit 32bit system

reeedstudio 11 yıl önce
ebeveyn
işleme
064f63e12b
2 değiştirilmiş dosya ile 59 ekleme ve 42 silme
  1. 29 18
      Barometer.cpp
  2. 30 24
      Barometer.h

+ 29 - 18
Barometer.cpp

@@ -7,7 +7,9 @@
  * Author     : LG
  * Create Time:
  * Change Log :
- *
+ * 
+ * loovee 9-24-2014
+ * Change all int to short, all unsigned int to unsigned short to fit some 32bit system
  * The MIT License (MIT)
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -28,6 +30,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
 #include "Barometer.h"
 #include <Wire.h>
 #include <Arduino.h>
@@ -49,6 +52,7 @@ void Barometer::init(void)
     md = bmp085ReadInt(0xBE);
     Serial.print("Temperaturet2: ");
 }
+
 // Read 1 byte from the BMP085 at 'address'
 // Return: the read byte;
 char Barometer::bmp085Read(unsigned char address)
@@ -63,10 +67,11 @@ char Barometer::bmp085Read(unsigned char address)
     while(!Wire.available());
     return Wire.read();
 }
+
 // Read 2 bytes from the BMP085
 // First byte will be from 'address'
 // Second byte will be from 'address'+1
-int Barometer::bmp085ReadInt(unsigned char address)
+short Barometer::bmp085ReadInt(unsigned char address)
 {
     unsigned char msb, lsb;
     Wire.beginTransmission(BMP085_ADDRESS);
@@ -76,19 +81,20 @@ int Barometer::bmp085ReadInt(unsigned char address)
     while(Wire.available()<2);
     msb = Wire.read();
     lsb = Wire.read();
-    return (int) msb<<8 | lsb;
+    return (short) msb<<8 | lsb;
 }
+
 // Read the uncompensated temperature value
-unsigned int Barometer::bmp085ReadUT()
+unsigned short Barometer::bmp085ReadUT()
 {
-  unsigned int ut;
-  Wire.beginTransmission(BMP085_ADDRESS);
-  Wire.write(0xF4);
-  Wire.write(0x2E);
-  Wire.endTransmission();
-  delay(5);
-  ut = bmp085ReadInt(0xF6);
-  return ut;
+    unsigned short ut;
+    Wire.beginTransmission(BMP085_ADDRESS);
+    Wire.write(0xF4);
+    Wire.write(0x2E);
+    Wire.endTransmission();
+    delay(5);
+    ut = bmp085ReadInt(0xF6);
+    return ut;
 }
 // Read the uncompensated pressure value
 unsigned long Barometer::bmp085ReadUP()
@@ -108,16 +114,18 @@ unsigned long Barometer::bmp085ReadUP()
     up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
     return up;
 }
-void Barometer::writeRegister(int deviceAddress, byte address, byte val)
+
+void Barometer::writeRegister(short deviceAddress, byte address, byte val)
 {
     Wire.beginTransmission(deviceAddress); // start transmission to device
     Wire.write(address);       // send register address
     Wire.write(val);         // send value to write
     Wire.endTransmission();     // end transmission
 }
-int Barometer::readRegister(int deviceAddress, byte address)
+
+short Barometer::readRegister(short deviceAddress, byte address)
 {
-    int v;
+    short v;
     Wire.beginTransmission(deviceAddress);
     Wire.write(address); // register to read
     Wire.endTransmission();
@@ -125,12 +133,13 @@ int Barometer::readRegister(int deviceAddress, byte address)
     Wire.requestFrom(deviceAddress, 1); // read a byte
 
     while(!Wire.available()) {
-    // waiting
+        // waiting
     }
 
     v = Wire.read();
     return v;
 }
+
 float Barometer::calcAltitude(float pressure)
 {
     float A = pressure/101325;
@@ -140,7 +149,8 @@ float Barometer::calcAltitude(float pressure)
     C = C /0.0000225577;
     return C;
 }
-float Barometer::bmp085GetTemperature(unsigned int ut)
+
+float Barometer::bmp085GetTemperature(unsigned short ut)
 {
     long x1, x2;
 
@@ -153,6 +163,7 @@ float Barometer::bmp085GetTemperature(unsigned int ut)
 
     return temp;
 }
+
 long Barometer::bmp085GetPressure(unsigned long up)
 {
     long x1, x2, x3, b3, b6, p;
@@ -182,4 +193,4 @@ long Barometer::bmp085GetPressure(unsigned long up)
 
     long temp = p;
     return temp;
-}
+}

+ 30 - 24
Barometer.h

@@ -8,8 +8,12 @@
  * Create Time:
  * Change Log :
  *
+ * loovee 9-24-2014
+ * Change all int to short, all unsigned int to unsigned short to fit some 32bit system
+ *
  * 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
@@ -36,33 +40,35 @@
 
 const unsigned char OSS = 0;
 #define BMP085_ADDRESS 0x77
+
 class Barometer
 {
-public:
-  void init(void);
-  long PressureCompensate;
-  float bmp085GetTemperature(unsigned int ut);
-  long bmp085GetPressure(unsigned long up);
-  float calcAltitude(float pressure);
-  unsigned int bmp085ReadUT(void);
-  unsigned long bmp085ReadUP(void);
+    public:
+    void init(void);
+    long PressureCompensate;
+    float bmp085GetTemperature(unsigned short ut);
+    long bmp085GetPressure(unsigned long up);
+    float calcAltitude(float pressure);
+    unsigned short bmp085ReadUT(void);
+    unsigned long bmp085ReadUP(void);
+
+    private:
 
-private:
-  int ac1;
-  int ac2;
-  int ac3;
-  unsigned int ac4;
-  unsigned int ac5;
-  unsigned int ac6;
-  int b1;
-  int b2;
-  int mb;
-  int mc;
-  int md;
-  char bmp085Read(unsigned char address);
-  int bmp085ReadInt(unsigned char address);
-  void writeRegister(int deviceAddress, byte address, byte val);
-  int readRegister(int deviceAddress, byte address);
+    short ac1;
+    short ac2;
+    short ac3;
+    unsigned short ac4;
+    unsigned short ac5;
+    unsigned short ac6;
+    short b1;
+    short b2;
+    short mb;
+    short mc;
+    short md;
+    char bmp085Read(unsigned char address);
+    short bmp085ReadInt(unsigned char address);
+    void writeRegister(short deviceAddress, byte address, byte val);
+    short readRegister(short deviceAddress, byte address);
 };
 
 #endif