mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-08-06 13:27:34 +00:00
Added altitude calculation and more compact API
This commit is contained in:
@@ -39,11 +39,11 @@ namespace sta
|
||||
*
|
||||
*/
|
||||
enum OsrLevel {
|
||||
_256 = 0,
|
||||
_512 = 1,
|
||||
_1024 = 2,
|
||||
_2048 = 3,
|
||||
_4096 = 4
|
||||
_256 = 0,
|
||||
_512 = 1,
|
||||
_1024 = 2,
|
||||
_2048 = 3,
|
||||
_4096 = 4
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -57,6 +57,16 @@ namespace sta
|
||||
mbar
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The types of physical interfaces used for communication with the sensor.
|
||||
*
|
||||
*/
|
||||
enum Intf
|
||||
{
|
||||
SPI,
|
||||
I2C
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief All possible commands to send to the sensor
|
||||
*
|
||||
@@ -105,22 +115,13 @@ namespace sta
|
||||
*/
|
||||
void setOsr(OsrLevel osr);
|
||||
|
||||
/**
|
||||
* @brief Reads the current pressure value from the sensor.
|
||||
*
|
||||
* @param temperature The temperature in Celsius * 100 (e.g. 20.3 deg. C -> 2030)
|
||||
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
||||
* @return uint32_t The measured value in the specified unit.
|
||||
*/
|
||||
int32_t getPressure(int32_t temperature, Unit unit = Unit::hPa);
|
||||
|
||||
/**
|
||||
* @brief Reads the current pressure value from the sensor. Obtains the temperature value from the interal sensor.
|
||||
*
|
||||
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
||||
* @return int32_t The measured value in the specified unit.
|
||||
*/
|
||||
int32_t getPressure(Unit unit = Unit::hPa);
|
||||
float getPressure(Unit unit = Unit::hPa);
|
||||
|
||||
/**
|
||||
* @brief Reads the current temperature value from the sensor.
|
||||
@@ -130,13 +131,6 @@ namespace sta
|
||||
*/
|
||||
int32_t getTemperature();
|
||||
|
||||
/**
|
||||
* @brief Set the Pressure Reference object
|
||||
*
|
||||
* @param pressRef The reference pressure value measured at a reference altitude.
|
||||
* @param altRef The reference altitude for the reference pressure.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Provide a reference pressure value at a reference altitude in order to estimate the sealevel pressure.
|
||||
*
|
||||
@@ -146,14 +140,6 @@ namespace sta
|
||||
*/
|
||||
void setPressureReference(float pressRef, float altRef, Unit unit = Unit::hPa);
|
||||
|
||||
/**
|
||||
* @brief Estimate the current altitude based on the pressure readings.
|
||||
*
|
||||
* @param temperature A temperature measurement from an external source.
|
||||
* @return float The altitude estimate in meters.
|
||||
*/
|
||||
float getAltitudeEstimate(int32_t temperature);
|
||||
|
||||
/**
|
||||
* @brief Estimate the current altitude based on the pressure readings.
|
||||
*
|
||||
@@ -174,79 +160,78 @@ namespace sta
|
||||
void readPROM();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @brief Convert the pressure value given in Pa to a different unit.
|
||||
*
|
||||
* @param ms
|
||||
* @param pressure A pressure value in Pa.
|
||||
* @param unit The desired unit.
|
||||
* @return float Returns the converted value.
|
||||
*/
|
||||
void pulseCS(uint32_t ms=1);
|
||||
float convertPressure(float pressure, Unit unit);
|
||||
|
||||
/**
|
||||
* @brief Compute the pressure values from the ADC output.
|
||||
* @brief Small helper function for converting a uint8_t buffer to a single uint16_t.
|
||||
*
|
||||
* @param d1
|
||||
* @param dT
|
||||
* @param unit The unit to return the pressure values in.
|
||||
* @return int32_t
|
||||
* @param buffer A uint8_t of size 2. More bytes will be ignored.
|
||||
* @return uint16_t A single uint16_t containing the first buffer value as MSB and the second as LSB.
|
||||
*/
|
||||
int32_t calculatePressure(uint32_t d1, int32_t dT, Unit unit);
|
||||
|
||||
/**
|
||||
* @brief Compute the temperature values from the ADC output
|
||||
*
|
||||
* @param d2
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t calculateTemperature(uint32_t d2);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param temp
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t reverseTempCalc(int32_t temp);
|
||||
|
||||
uint16_t uint_8BufferTouint16_t(uint8_t* buffer);
|
||||
|
||||
/**
|
||||
* @brief Function to get the delay times needed for different OSR Levels
|
||||
*
|
||||
* @param level The oversampling rate chosen
|
||||
* @return uint32_t Returs the delay time in uS.
|
||||
*/
|
||||
uint32_t osrDelay();
|
||||
private:
|
||||
/**
|
||||
* @brief Send a command to the sensor via the bus.
|
||||
*
|
||||
* @param command The command to send.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool busCommand(uint8_t command);
|
||||
|
||||
/**
|
||||
* @brief Read data from one of the sensor's registers.
|
||||
*
|
||||
* @param reg The register to read from.
|
||||
* @param buffer The buffer to write the received data to.
|
||||
* @param length The number of bytes to read from the register.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool busRead(uint8_t reg, uint8_t * buffer, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Write data to one of the sensor's registers.
|
||||
*
|
||||
* @param reg The register to write to.
|
||||
* @param buffer The buffer of data to write to the register.
|
||||
* @param length The number of bytes to write.
|
||||
* @return true if successful, false otherwise.
|
||||
*/
|
||||
bool busWrite(uint8_t reg, uint8_t * buffer, size_t length);
|
||||
private:
|
||||
// STA internal object for SPi abstraction
|
||||
Device * device_;
|
||||
DelayUsFunc delay_;
|
||||
OsrLevel osr_;
|
||||
Intf intf_;
|
||||
|
||||
// Pressure at sealevel.
|
||||
int32_t sealevel_;
|
||||
// Pressure at sealevel. Use the standard atmosphere per default.
|
||||
float sealevel_ = 1013.25;
|
||||
|
||||
// 6 Different constants; Includes Offsets, references etc.
|
||||
uint16_t sens, off, tcs, tco, t_ref, tempsens;
|
||||
uint16_t sensibility_;
|
||||
uint16_t offset_;
|
||||
uint16_t tempSensCoeff_;
|
||||
uint16_t tempOffsetCoeff_;
|
||||
uint16_t refTemp_;
|
||||
uint16_t tempCoeff_;
|
||||
|
||||
// Constants for waiting
|
||||
const uint32_t RESET_DELAY = 2800; // in uS
|
||||
|
||||
// Function to get the delay times needed for different OSR Levels
|
||||
// Values not found in datasheet (facepalm)
|
||||
// Thus partly googled, partly tested out
|
||||
static uint8_t delayTimes(OsrLevel level) {
|
||||
switch (level) {
|
||||
case _256:
|
||||
return 1;
|
||||
case _512:
|
||||
return 2;
|
||||
case _1024:
|
||||
return 3;
|
||||
case _2048:
|
||||
return 5;
|
||||
case _4096:
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ifndef STA_SENSORS_MS5607_HPP
|
Reference in New Issue
Block a user