1 #ifndef LIBPROPELLER_MS5611_H_
2 #define LIBPROPELLER_MS5611_H_
58 if (status_ ==
false) {
62 static const char kPROMRead [] = {
79 for (
int i = 0; i < 6; i++) {
81 bus_->
Put(device_address, kPROMRead[i + 1]);
82 bus_->
Get(device_address, data, 2);
83 C[i] = data[0] << 8 | data[1];
86 SetC(C[0], C[1], C[2], C[3], C[4], C[5]);
88 convertingTemperature_ =
true;
89 bus_->
Put(device_address, kConvertD2OSR4096);
120 bus_->
Put(device_address, kADCRead);
122 bus_->
Get(device_address, data, 3);
123 int reading = ExpandReading(data);
129 if (convertingTemperature_) {
132 bus_->
Put(device_address, kConvertD1OSR4096);
134 convertingTemperature_ =
false;
139 bus_->
Put(device_address, kConvertD2OSR4096);
141 convertingTemperature_ =
true;
161 void Get(
int & tPressure,
int & tTemperature,
162 const bool calibrationCalculation =
true) {
164 if (calibrationCalculation ==
true) {
168 tPressure = pressure_;
169 tTemperature = temperature_;
184 status_ = bus_->
Ping(device_address);
195 return bus_->
Put(device_address, kReset);
208 void SetC(
const int newC1,
const int newC2,
const int newC3,
209 const int newC4,
const int newC5,
const int newC6) {
210 C1_ = ((int64_t) newC1) << 15;
211 C2_ = ((int64_t) newC2) << 16;
212 C3_ = (int64_t) newC3;
213 C4_ = (int64_t) newC4;
228 void GetC(
int & oldC1,
int & oldC2,
int & oldC3,
229 int & oldC4,
int & oldC5,
int & oldC6) {
230 oldC1 = (int) (C1_ >> 15);
231 oldC2 = (int) (C2_ >> 16);
243 void TEST_SetD(
const int newD1,
const int newD2) {
249 void Calculate(
void) {
252 temperature_ = 2000 + ((dT * C6_) >> 23);
258 if (temperature_ < 2000) {
262 T2 = (dT64 * dT64) >> 31;
263 OFF2 = (5 * (temperature_ - 2000) * (temperature_ - 2000)) >> 1;
266 if (temperature_ < -1500) {
267 OFF2 = OFF2 + (7 * (temperature_ + 1500) * (temperature_ + 1500));
268 SENS2 = SENS2 + ((11 * (temperature_ + 1500) * (temperature_ + 1500)) >> 1);
273 int64_t OFF = C2_ + ((C4_ * dT) >> 7);
274 int64_t SENS = C1_ + ((C3_ * dT) >> 8);
276 temperature_ = temperature_ -
T2;
280 pressure_ = (int) ((((((int64_t) D1_) * SENS) >> 21) - OFF) >> 15);
283 int ExpandReading(
const char data[])
const {
285 return data[0] << 16 | data[1] << 8 | data[2];
292 int64_t C1_, C2_, C3_, C4_;
296 int temperature_, pressure_;
299 bool convertingTemperature_;
305 const static char kConvertD1OSR4096 = 0x48;
306 const static char kConvertD2OSR4096 = 0x58;
307 const static char kADCRead = 0x00;
308 const static char kReset = 0b00011110;
310 unsigned char device_address;
313 if (address ==
LSB_0) {
314 device_address = 0b11101100;
315 }
else if (address ==
LSB_1) {
316 device_address = 0b11101110;
322 friend class UnityTests;
326 #endif // LIBPROPELLER_MS5611_H_