mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-06-10 18:16:00 +00:00
updated for adler
This commit is contained in:
parent
3a0d38bf7a
commit
22180ab7af
@ -1,8 +1,9 @@
|
|||||||
#ifndef STA_SENSORS_MS5607_HPP
|
#ifndef STA_SENSORS_MS5607_HPP
|
||||||
#define STA_SENSORS_MS5607_HPP
|
#define STA_SENSORS_MS5607_HPP
|
||||||
|
|
||||||
#include <sta/bus/spi/device.hpp>
|
//#include <sta/bus/spi/device.hpp>
|
||||||
#include <sta/bus/i2c/device.hpp>
|
//#include <sta/bus/i2c/device.hpp>
|
||||||
|
#include <sta/devices/stm32/bus/spi.hpp>
|
||||||
#include <sta/time.hpp>
|
#include <sta/time.hpp>
|
||||||
|
|
||||||
#include <sta/endian.hpp>
|
#include <sta/endian.hpp>
|
||||||
@ -28,6 +29,11 @@ namespace sta
|
|||||||
* @brief Driver class for communicating with the MS56xx pressure sensor via SPI.
|
* @brief Driver class for communicating with the MS56xx pressure sensor via SPI.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
struct MSData {
|
||||||
|
float pressure;
|
||||||
|
float temperature;
|
||||||
|
};
|
||||||
|
|
||||||
class MS56xx {
|
class MS56xx {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -123,7 +129,7 @@ namespace sta
|
|||||||
*
|
*
|
||||||
* @note Set PS pin to high for I2C. Chip select pin represents LSB of address.
|
* @note Set PS pin to high for I2C. Chip select pin represents LSB of address.
|
||||||
*/
|
*/
|
||||||
MS56xx(I2CDevice * device, Version version, DelayUsFunc delay, OsrLevel osr = OsrLevel::_1024);
|
//MS56xx(I2CDevice * device, Version version, DelayUsFunc delay, OsrLevel osr = OsrLevel::_1024);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize the driver. Computes the pressure value at altitude 0.
|
* @brief Initialize the driver. Computes the pressure value at altitude 0.
|
||||||
@ -145,7 +151,7 @@ namespace sta
|
|||||||
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
||||||
* @return float The measured value in the specified unit.
|
* @return float The measured value in the specified unit.
|
||||||
*/
|
*/
|
||||||
float getPressure(Unit unit = Unit::hPa);
|
MSData getPressure(Unit unit = Unit::hPa);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reads the current temperature value from the sensor.
|
* @brief Reads the current temperature value from the sensor.
|
||||||
|
@ -20,7 +20,7 @@ namespace sta
|
|||||||
STA_ASSERT(device != nullptr);
|
STA_ASSERT(device != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
MS56xx::MS56xx(I2CDevice * device, Version version, DelayUsFunc delay, OsrLevel osr /* = OsrLevel::_1024 */)
|
/*MS56xx::MS56xx(I2CDevice * device, Version version, DelayUsFunc delay, OsrLevel osr = OsrLevel::_1024)
|
||||||
: device_{device},
|
: device_{device},
|
||||||
version_{version},
|
version_{version},
|
||||||
delay_{delay},
|
delay_{delay},
|
||||||
@ -29,7 +29,7 @@ namespace sta
|
|||||||
C_{}
|
C_{}
|
||||||
{
|
{
|
||||||
STA_ASSERT(device != nullptr);
|
STA_ASSERT(device != nullptr);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
bool MS56xx::init()
|
bool MS56xx::init()
|
||||||
{
|
{
|
||||||
@ -65,7 +65,7 @@ namespace sta
|
|||||||
delay_(osrDelay());
|
delay_(osrDelay());
|
||||||
}
|
}
|
||||||
|
|
||||||
float MS56xx::getPressure(Unit unit /* = Unit::hPa */)
|
MSData MS56xx::getPressure(Unit unit /* = Unit::hPa */)
|
||||||
{
|
{
|
||||||
requestData(TEMPERATURE);
|
requestData(TEMPERATURE);
|
||||||
uint8_t buffer[3] = { 0x00, 0x00, 0x00 };
|
uint8_t buffer[3] = { 0x00, 0x00, 0x00 };
|
||||||
@ -86,8 +86,9 @@ namespace sta
|
|||||||
|
|
||||||
// Convert to desired unit.
|
// Convert to desired unit.
|
||||||
pressure = convertPressure(pressure, unit);
|
pressure = convertPressure(pressure, unit);
|
||||||
|
float temperature = (2000 + dT_ * C_[6]) * 0.01;
|
||||||
|
|
||||||
return pressure;
|
return MSData{pressure, temperature};
|
||||||
}
|
}
|
||||||
|
|
||||||
float MS56xx::getTemperature()
|
float MS56xx::getTemperature()
|
||||||
@ -111,7 +112,7 @@ namespace sta
|
|||||||
|
|
||||||
float MS56xx::getAltitudeEstimate()
|
float MS56xx::getAltitudeEstimate()
|
||||||
{
|
{
|
||||||
float pressure = getPressure(Unit::hPa);
|
float pressure = getPressure(Unit::hPa).pressure;
|
||||||
|
|
||||||
// Taken from: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf, page 16
|
// Taken from: https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf, page 16
|
||||||
float altitude = 44330 * (1 - std::pow(pressure / sealevel_, 1 / 5.255));
|
float altitude = 44330 * (1 - std::pow(pressure / sealevel_, 1 / 5.255));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user