PressureWrapper: add getPressure()
This commit is contained in:
parent
db4c4efb1a
commit
3bbbf2ae4a
@ -37,7 +37,7 @@
|
||||
* this code.
|
||||
*/
|
||||
|
||||
#include "../inc/I2C.h"
|
||||
#include "I2C.h"
|
||||
|
||||
|
||||
I2C::I2C(const I2C_config &cfg): device(nullptr) {
|
||||
@ -35,13 +35,26 @@ PressureWrapper::~PressureWrapper ()
|
||||
}
|
||||
|
||||
int PressureWrapper::getPressure() {
|
||||
|
||||
int16_t pressure = 0;
|
||||
if(!getRawPressure ()) {
|
||||
unsigned int i = 0;
|
||||
while(i<7200000) i++;
|
||||
getRawPressure ();
|
||||
i = 0;
|
||||
}
|
||||
// do {
|
||||
// getRawPressure ();
|
||||
// } while (crc8(data.rBuffer, 2) != data.crc);
|
||||
pressure = data.rBuffer[0];
|
||||
pressure = pressure << 8;
|
||||
pressure |= data.rBuffer[1];
|
||||
float result = (float) pressure * 0.95 / 240;
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
PRESSURE_DATA* PressureWrapper::getRawPressure () {
|
||||
bool PressureWrapper::getRawPressure () {
|
||||
uint8_t getMeasurementComm = 0xF1;
|
||||
i2c->transaction(0x40, &getMeasurementComm, 1, data.rBuffer, 3);
|
||||
return &data;
|
||||
return (i2c->transaction(ADDRESS, &getMeasurementComm, 1, data.rBuffer, 3));
|
||||
}
|
||||
|
||||
|
||||
@ -12,8 +12,12 @@
|
||||
#include <cstdio>
|
||||
|
||||
#define ADDRESS 0x40
|
||||
#define READADD 0x81
|
||||
#define WRITEADD 0x80
|
||||
|
||||
|
||||
/**
|
||||
* @brief structure to hold a raw data from
|
||||
* the pressure sensor
|
||||
*/
|
||||
|
||||
typedef struct _PRESSURE{
|
||||
uint8_t rBuffer[2];
|
||||
@ -24,11 +28,8 @@ class PressureWrapper
|
||||
{
|
||||
public:
|
||||
PressureWrapper ();
|
||||
/**
|
||||
* @brief Get the Status object
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
/*
|
||||
* @return pressure in Pascal
|
||||
*/
|
||||
int getPressure ();
|
||||
|
||||
@ -37,7 +38,11 @@ public:
|
||||
private:
|
||||
I2C *i2c;
|
||||
PRESSURE_DATA data = {{0, 0}, 0};
|
||||
PRESSURE_DATA* getRawPressure ();
|
||||
/*
|
||||
* @return struct with pressure data in
|
||||
* rBuffer and CRC check in crc
|
||||
*/
|
||||
bool getRawPressure ();
|
||||
};
|
||||
|
||||
#endif /* PRESSUREWRAPPER_H_ */
|
||||
Loading…
x
Reference in New Issue
Block a user