From 3bbbf2ae4a6b98cee37069d408e4844de2e9c731 Mon Sep 17 00:00:00 2001 From: Evgenii Meshcheriakov Date: Mon, 17 Oct 2022 17:24:42 +0300 Subject: [PATCH] PressureWrapper: add getPressure() --- .../src/I2C.cpp | 2 +- .../inc => esp-vent-main/src}/I2C.h | 0 .../src/PressureWrapper.cpp | 21 +++++++++++++++---- .../src}/PressureWrapper.h | 21 ++++++++++++------- 4 files changed, 31 insertions(+), 13 deletions(-) rename {PressureWrapper => esp-vent-main}/src/I2C.cpp (99%) rename {PressureWrapper/inc => esp-vent-main/src}/I2C.h (100%) rename {PressureWrapper => esp-vent-main}/src/PressureWrapper.cpp (62%) rename {PressureWrapper/inc => esp-vent-main/src}/PressureWrapper.h (68%) diff --git a/PressureWrapper/src/I2C.cpp b/esp-vent-main/src/I2C.cpp similarity index 99% rename from PressureWrapper/src/I2C.cpp rename to esp-vent-main/src/I2C.cpp index 8536719..938f126 100644 --- a/PressureWrapper/src/I2C.cpp +++ b/esp-vent-main/src/I2C.cpp @@ -37,7 +37,7 @@ * this code. */ -#include "../inc/I2C.h" +#include "I2C.h" I2C::I2C(const I2C_config &cfg): device(nullptr) { diff --git a/PressureWrapper/inc/I2C.h b/esp-vent-main/src/I2C.h similarity index 100% rename from PressureWrapper/inc/I2C.h rename to esp-vent-main/src/I2C.h diff --git a/PressureWrapper/src/PressureWrapper.cpp b/esp-vent-main/src/PressureWrapper.cpp similarity index 62% rename from PressureWrapper/src/PressureWrapper.cpp rename to esp-vent-main/src/PressureWrapper.cpp index 3dcf978..f7a0d90 100644 --- a/PressureWrapper/src/PressureWrapper.cpp +++ b/esp-vent-main/src/PressureWrapper.cpp @@ -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)); } diff --git a/PressureWrapper/inc/PressureWrapper.h b/esp-vent-main/src/PressureWrapper.h similarity index 68% rename from PressureWrapper/inc/PressureWrapper.h rename to esp-vent-main/src/PressureWrapper.h index 2bd73cd..6ee2936 100644 --- a/PressureWrapper/inc/PressureWrapper.h +++ b/esp-vent-main/src/PressureWrapper.h @@ -12,8 +12,12 @@ #include #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_ */