Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver fixes #10

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/hacksterExample/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ monitor_speed = 115200
lib_deps =
Sensirion/Sensirion Core
Sensirion/Sensirion UPT Core
; Depends on version 0.1.0 (Newer versions have incompatible API)
Sensirion/Sensirion I2C SHT4x@0.1.0
Sensirion/Sensirion I2C SHT4x
Sensirion/Sensirion I2C SCD4x
Sensirion/Sensirion I2C SFA3x
Sensirion/Sensirion I2C SVM4x
Expand Down
3 changes: 1 addition & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ default_envs = basicUsage
lib_deps_external =
Sensirion/Sensirion Core
Sensirion/Sensirion UPT Core
; Newer versions of the SHT4X driver have an incompatible API
Sensirion/Sensirion I2C SHT4x@0.1.0
Sensirion/Sensirion I2C SHT4x
Sensirion/Sensirion I2C SCD4x
Sensirion/Sensirion I2C SFA3x
Sensirion/Sensirion I2C SVM4x
Expand Down
2 changes: 1 addition & 1 deletion src/SensorWrappers/Sht4x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Sht4x::Sht4x(TwoWire& wire) : _wire(wire) {
};

uint16_t Sht4x::start() {
_driver.begin(_wire);
_driver.begin(_wire, I2C_ADDRESS);
return HighLevelError::NoError;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SensorWrappers/Sht4x.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _SHT4X_H_

#include "ISensor.h"
#include "SensirionI2CSht4x.h"
#include "SensirionI2cSht4x.h"
#include "Sensirion_UPT_Core.h"

class Sht4x : public ISensor {
Expand All @@ -21,7 +21,7 @@ class Sht4x : public ISensor {

private:
TwoWire& _wire;
SensirionI2CSht4x _driver;
SensirionI2cSht4x _driver;
MetaData _metaData;
};

Expand Down
33 changes: 13 additions & 20 deletions src/SensorWrappers/Stc3x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,31 @@ Stc3x::Stc3x(TwoWire& wire) : _wire(wire) {
};

uint16_t Stc3x::start() {
_driver.begin(_wire);
_driver.begin(_wire, I2C_ADDRESS);
uint16_t error = _driver.setBinaryGas(0x0001);
return error;
}

uint16_t Stc3x::measureAndWrite(Measurement measurements[],
const unsigned long timeStamp) {
uint16_t gasTicks;
uint16_t temperatureTicks;
float gasValue;
float temperatureValue;

uint16_t error =
_driver.measureGasConcentration(gasTicks, temperatureTicks);
_driver.measureGasConcentration(gasValue, temperatureValue);
if (error) {
return error;
}

measurements[0].signalType =
SignalType::GAS_CONCENTRATION_VOLUME_PERCENTAGE;
measurements[0].dataPoint.t_offset = timeStamp;
measurements[0].dataPoint.value =
100 * (static_cast<float>(gasTicks) - 16384.0) / 32768.0;
measurements[0].dataPoint.value = gasValue;
measurements[0].metaData = _metaData;

measurements[1].signalType = SignalType::TEMPERATURE_DEGREES_CELSIUS;
measurements[1].dataPoint.t_offset = timeStamp;
measurements[1].dataPoint.value =
static_cast<float>(temperatureTicks) / 200.0;
measurements[1].dataPoint.value = temperatureValue;
measurements[1].metaData = _metaData;

return HighLevelError::NoError;
Expand All @@ -48,11 +46,12 @@ uint16_t Stc3x::initializationStep() {
}

uint32_t productNumber;
uint8_t serialNumberRaw[32];
uint8_t serialNumberSize = 32;
uint32_t serialNumberRawLow;
uint32_t serialNumberRawHigh;

error = _driver.readProductIdentifier(productNumber, serialNumberRawHigh,
serialNumberRawLow);

error = _driver.readProductIdentifier(productNumber, serialNumberRaw,
serialNumberSize);
if (error) {
return error;
}
Expand All @@ -72,14 +71,8 @@ uint16_t Stc3x::initializationStep() {

// Sensor Serial No
uint64_t sensorID = 0;
sensorID |= (uint64_t)serialNumberRaw[0] << 56 |
(uint64_t)serialNumberRaw[1] << 48 |
(uint64_t)serialNumberRaw[2] << 40 |
(uint64_t)serialNumberRaw[3] << 32 |
(uint64_t)serialNumberRaw[4] << 24 |
(uint64_t)serialNumberRaw[5] << 16 |
(uint64_t)serialNumberRaw[6] << 8 |
(uint64_t)serialNumberRaw[7];
sensorID |=
(uint64_t)serialNumberRawHigh << 32 | (uint64_t)serialNumberRawLow;
_metaData.deviceID = sensorID;

// Select gas mode
Expand Down
4 changes: 2 additions & 2 deletions src/SensorWrappers/Stc3x.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "ISensor.h"
#include "Sensirion_UPT_Core.h"
#include <SensirionI2CStc3x.h>
#include <SensirionI2cStc3x.h>

class Stc3x : public ISensor {
public:
Expand All @@ -21,7 +21,7 @@ class Stc3x : public ISensor {

private:
TwoWire& _wire;
SensirionI2CStc3x _driver;
SensirionI2cStc3x _driver;
MetaData _metaData;
};

Expand Down
Loading