+ refactored (not stable version)

This commit is contained in:
rob tillaart 2014-10-19 12:55:45 +02:00
parent 920d72b5f4
commit 8d24e1bef7
2 changed files with 11 additions and 9 deletions

View File

@ -1,11 +1,12 @@
//
// FILE: MS5611.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// VERSION: 0.1.01
// PURPOSE: MS5611 Temperature & Humidity library for Arduino
// URL:
//
// HISTORY:
// 0.1.01 small refactoring
// 0.1.00 added temperature and Pressure code
// 0.0.00 initial version by Rob Tillaart (15-okt-2014)
//
@ -24,7 +25,6 @@ MS5611::MS5611(uint8_t address)
{
_address = address;
Wire.begin();
// TWBR = 12; // 400KHz
}
void MS5611::init()
@ -41,12 +41,16 @@ int MS5611::read(uint8_t bits)
{
convertD1(bits);
if (_result) return _result;
delay(10);
int32_t D1 = readADC();
if (_result) return _result;
delay(10);
convertD2(8);
if (_result) return _result;
delay(10);
int32_t D2 = readADC();
if (_result) return _result;
delay(10);
// PAGE 7/20 of the datasheet
int32_t dT = D2 - C[5] * 256L;
@ -106,16 +110,14 @@ uint16_t MS5611::readProm(uint8_t reg)
int32_t MS5611::readADC()
{
Wire.beginTransmission(_address);
Wire.write(0x00);
_result = Wire.endTransmission();
command(0x00);
if (_result == 0)
{
int nr = Wire.requestFrom(_address, (uint8_t)3);
if (nr >= 3)
{
uint32_t val = Wire.read() * 65536L;
val += Wire.read() * 256;
val += Wire.read() * 256L;
val += Wire.read();
return val;
}

View File

@ -1,7 +1,7 @@
//
// FILE: MS5611.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// VERSION: 0.1.01
// PURPOSE: MS5611 Temperature & Pressure library for Arduino
// URL:
//
@ -18,7 +18,7 @@
#include <Arduino.h>
#endif
#define MS5611_LIB_VERSION "0.1.00"
#define MS5611_LIB_VERSION "0.1.01"
class MS5611
{
@ -26,7 +26,7 @@ public:
MS5611(uint8_t address);
void init();
int read();
int read(uint8_t bits = 8);
int32_t temperature;
int32_t pressure;
int getLastResult();