mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-09-28 22:37:33 +00:00
Reverted a few changes but fixed a few issues
This commit is contained in:
@@ -9,18 +9,20 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
MS56xx::MS56xx(SPIDevice * device, DelayUsFunc delay, OsrLevel level /* = OsrLevel::_1024 */)
|
||||
MS56xx::MS56xx(SPIDevice * device, Version version, DelayUsFunc delay, OsrLevel osr = OsrLevel::_1024)
|
||||
: device_{device},
|
||||
version_{version},
|
||||
delay_{delay},
|
||||
osr_{level},
|
||||
osr_{osr},
|
||||
intf_{Intf::SPI},
|
||||
C_{}
|
||||
{
|
||||
STA_ASSERT(device != nullptr);
|
||||
}
|
||||
|
||||
MS56xx::MS56xx(I2CDevice * device, DelayUsFunc delay, OsrLevel osr /* = OsrLevel::_1024 */)
|
||||
MS56xx::MS56xx(I2CDevice * device, Version version, DelayUsFunc delay, OsrLevel osr /* = OsrLevel::_1024 */)
|
||||
: device_{device},
|
||||
version_{version},
|
||||
delay_{delay},
|
||||
osr_{osr},
|
||||
intf_{Intf::I2C},
|
||||
@@ -64,21 +66,20 @@ namespace sta
|
||||
|
||||
// Request the ADC to read new data.
|
||||
busCommand(op + 2*this->osr_);
|
||||
}
|
||||
|
||||
void MS56xx::requestPressure()
|
||||
{
|
||||
requestData(PRESSURE);
|
||||
}
|
||||
|
||||
void MS56xx::requestTemperature()
|
||||
{
|
||||
requestData(TEMPERATURE);
|
||||
delay_(osrDelay());
|
||||
}
|
||||
|
||||
float MS56xx::getPressure(Unit unit /* = Unit::hPa */)
|
||||
{
|
||||
requestData(TEMPERATURE);
|
||||
uint8_t buffer[3] = { 0x00, 0x00, 0x00 };
|
||||
busRead(MS56xx::Operations::ADC_RESULT, buffer, 3);
|
||||
|
||||
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||
dT_ = D2 - C_[5];
|
||||
|
||||
requestData(PRESSURE);
|
||||
busRead(MS56xx::Operations::ADC_RESULT, buffer, 3);
|
||||
uint32_t D1 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||
|
||||
@@ -86,8 +87,10 @@ namespace sta
|
||||
float sens = C_[1] + dT_ * C_[3];
|
||||
|
||||
// The pressure in Pa.
|
||||
float pressure = (D1 * sens * 4.76837158205E-7 - offset) * 3.051757813E-5 * 0.01;
|
||||
// TODO: conversion
|
||||
float pressure = (D1 * sens * 4.76837158205E-7 - offset) * 3.051757813E-5;
|
||||
|
||||
// Convert to desired unit.
|
||||
pressure = convertPressure(pressure, unit);
|
||||
|
||||
return pressure;
|
||||
}
|
||||
@@ -100,7 +103,7 @@ namespace sta
|
||||
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||
|
||||
dT_ = D2 - C_[5];
|
||||
return 2000 + dT_ * C_[6] * 0.01;
|
||||
return (2000 + dT_ * C_[6]) * 0.01;
|
||||
}
|
||||
|
||||
void MS56xx::setPressureReference(float pressRef, float altRef, Unit unit /* = Unit::hPa */)
|
||||
@@ -133,12 +136,28 @@ namespace sta
|
||||
void MS56xx::initConstants()
|
||||
{
|
||||
C_[0] = 1;
|
||||
C_[1] = 65536L;
|
||||
C_[2] = 131072;
|
||||
C_[3] = 7.8125E-3;
|
||||
C_[4] = 0.015625;
|
||||
C_[5] = 256;
|
||||
C_[6] = 1.1920928955E-7;
|
||||
|
||||
switch (version_)
|
||||
{
|
||||
case _MS5607:
|
||||
C_[1] = 65536L;
|
||||
C_[2] = 131072;
|
||||
C_[3] = 7.8125E-3;
|
||||
C_[4] = 0.015625;
|
||||
C_[5] = 256;
|
||||
C_[6] = 1.1920928955E-7;
|
||||
|
||||
break;
|
||||
case _MS5611:
|
||||
C_[1] = 32768L;
|
||||
C_[2] = 65536L;
|
||||
C_[3] = 3.90625E-3;
|
||||
C_[4] = 7.8125E-3;
|
||||
C_[5] = 256;
|
||||
C_[6] = 1.1920928955E-7;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline float MS56xx::convertPressure(float pressure, Unit unit)
|
||||
|
Reference in New Issue
Block a user