From 98ae07bc18013fddbdb4f219d29b90d4c6362f46 Mon Sep 17 00:00:00 2001 From: Evgenii Meshcheriakov Date: Mon, 17 Oct 2022 10:40:14 +0300 Subject: [PATCH] pressure-wrapper: add structure for pressure_data --- PressureWrapper/inc/PressureWrapper.h | 10 ++++++++-- PressureWrapper/src/PressureWrapper.cpp | 17 +++++++++++++++-- esp-vent-main/.cproject | 10 ++++++++++ esp-vent-main/.project | 1 + esp-vent-main/src/esp-vent-main.cpp | 13 +++++++++++-- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/PressureWrapper/inc/PressureWrapper.h b/PressureWrapper/inc/PressureWrapper.h index 54aec80..77c5e84 100644 --- a/PressureWrapper/inc/PressureWrapper.h +++ b/PressureWrapper/inc/PressureWrapper.h @@ -15,10 +15,15 @@ #define READADD 0x81 #define WRITEADD 0x80 +typedef struct _PRESSURE{ + uint8_t rBuffer[2]; + uint8_t crc; +}PRESSURE_DATA; + class PressureWrapper { public: - PressureWrapper (); + PressureWrapper (I2C *i2c); /** * @brief Get the Status object * @@ -26,12 +31,13 @@ public: * @return false */ bool getStatus (); - int16_t getPressure (); + PRESSURE_DATA* getPressure (); virtual ~PressureWrapper (); private: I2C *i2c; + PRESSURE_DATA data = {{0, 0}, 0}; }; #endif /* PRESSUREWRAPPER_H_ */ diff --git a/PressureWrapper/src/PressureWrapper.cpp b/PressureWrapper/src/PressureWrapper.cpp index 48288a9..5f92992 100644 --- a/PressureWrapper/src/PressureWrapper.cpp +++ b/PressureWrapper/src/PressureWrapper.cpp @@ -7,12 +7,25 @@ #include -PressureWrapper::PressureWrapper () +PressureWrapper::PressureWrapper (I2C *i2c) : i2c(i2c) { - // TODO Auto-generated constructor stub + } PressureWrapper::~PressureWrapper () { // TODO Auto-generated destructor stub } + +bool PressureWrapper::getStatus() { + uint8_t control_register = 0x01; + uint8_t status = 0; + i2c->transaction(ADDRESS, &control_register, 1, &status, 1); +} + +PRESSURE_DATA* PressureWrapper::getPressure () { + uint8_t getMeasurementComm = 0xF1; + i2c->transaction(ADDRESS, &getMeasurementComm, 1, data.rBuffer, 3); + //i2c->transaction(ADDRESS, &getMeasurementComm, 1, data.crc, 1); + return &data; +} diff --git a/esp-vent-main/.cproject b/esp-vent-main/.cproject index 521b9f6..208bd18 100644 --- a/esp-vent-main/.cproject +++ b/esp-vent-main/.cproject @@ -46,6 +46,7 @@ + @@ -126,6 +129,7 @@ + @@ -280,6 +288,7 @@ +