Fix #8 by switching to bit shifts and refactor redundant code.

This commit is contained in:
Tony DiCola
2014-06-12 14:48:47 -07:00
parent 6bcf1efe16
commit 4466c2651c
2 changed files with 11 additions and 10 deletions
+10 -10
View File
@@ -64,6 +64,12 @@ boolean Adafruit_BMP085::begin(uint8_t mode) {
return true;
}
int32_t Adafruit_BMP085::computeB5(int32_t UT) {
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
return X1 + X2;
}
uint16_t Adafruit_BMP085::readRawTemperature(void) {
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
_delay_ms(5);
@@ -132,10 +138,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
oversampling = 0;
#endif
// do temperature calculations
X1=(UT-(int32_t)(ac6))*((int32_t)(ac5))/pow(2,15);
X2=((int32_t)mc*pow(2,11))/(X1+(int32_t)md);
B5=X1 + X2;
B5 = computeB5(UT);
#if BMP085_DEBUG == 1
Serial.print("X1 = "); Serial.println(X1);
@@ -194,7 +197,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
float Adafruit_BMP085::readTemperature(void) {
int32_t UT, X1, X2, B5; // following ds convention
int32_t UT, B5; // following ds convention
float temp;
UT = readRawTemperature();
@@ -208,11 +211,8 @@ float Adafruit_BMP085::readTemperature(void) {
md = 2868;
#endif
// step 1
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2,15);
X2 = ((int32_t)mc * pow(2,11)) / (X1+(int32_t)md);
B5 = X1 + X2;
temp = (B5+8)/pow(2,4);
B5 = computeB5(UT);
temp = (B5+8) >> 4;
temp /= 10;
return temp;
+1
View File
@@ -63,6 +63,7 @@ class Adafruit_BMP085 {
uint32_t readRawPressure(void);
private:
int32_t computeB5(int32_t UT);
uint8_t read8(uint8_t addr);
uint16_t read16(uint8_t addr);
void write8(uint8_t addr, uint8_t data);