diff --git a/include/sta/drivers/MS56xx.hpp b/include/sta/drivers/MS56xx.hpp index e02521c..e34662e 100644 --- a/include/sta/drivers/MS56xx.hpp +++ b/include/sta/drivers/MS56xx.hpp @@ -71,7 +71,8 @@ namespace sta * @brief All possible commands to send to the sensor * */ - enum Operations { + enum Operations + { RESET = 0x1E, READ_PROM = 0xA0, D1_CONVERSION = 0x40, @@ -79,6 +80,12 @@ namespace sta ADC_RESULT = 0x00 }; + enum DataType + { + PRESSURE, + TEMPERATURE + }; + /** * @brief SPI driver for the MS56xx pressure sensor series. * diff --git a/src/MS56xx.cpp b/src/MS56xx.cpp index d65ccae..b8fccc2 100644 --- a/src/MS56xx.cpp +++ b/src/MS56xx.cpp @@ -42,6 +42,16 @@ namespace sta return true; } + void MS56xx::requestData() + { + + } + + bool MS56xx::hasData() + { + + } + void MS56xx::setOsr(OsrLevel osr) { osr_ = osr; @@ -53,28 +63,32 @@ namespace sta delay_(MS56xx::RESET_DELAY); } + void MS56xx::requestData(DataType type, bool blocking = false) + { + Operations op = type == DataType::PRESSURE ? D1_CONVERSION : D2_CONVERSION; + + // Request the ADC to read new data. + busCommand(op + 2*this->osr_); + + if (blocking) + { + delay_(osrDelay()); + } + } + float MS56xx::getPressure(Unit unit /* = Unit::hPa */) { - // Request the ADC to read temperature values. - busCommand(MS56xx::Operations::D1_CONVERSION + 2*this->osr_); - - // 8.22 ms conversion according to the datasheet. - delay_(osrDelay()); + // Request the ADC to read pressure values. + requestData(PRESSURE, true); uint8_t buffer[3] = { 0x00, 0x00, 0x00 }; busRead(MS56xx::Operations::ADC_RESULT, buffer, 3); - - // Difference between actual and reference temperature. uint32_t D1 = buffer[0] << 16 | buffer[1] << 8 | buffer[2]; - // Request the ADC to read pressure values. - busCommand(MS56xx::Operations::D2_CONVERSION + 2*this->osr_); - - // 8.22 ms conversion according to the datasheet. - delay_(osrDelay()); + // Request the ADC to read temperature values. + requestData(PRESSURE, true); busRead(MS56xx::Operations::ADC_RESULT, buffer, 3); - uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2]; float dT = D2 - C_[5];