Skip to content

Commit

Permalink
Implement comments from #37
Browse files Browse the repository at this point in the history
vcolella authored and winkj committed Nov 7, 2024
1 parent 8c77fea commit bcae2b6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions SHTSensor.cpp
Original file line number Diff line number Diff line change
@@ -179,25 +179,25 @@ class SHT2xSensor : public SHTI2cSensor
bool readSample() override
{
uint8_t data[EXPECTED_DATA_SIZE];
uint8_t cmd[mCmd_Size * 2];
uint8_t cmd[mCmd_Size];

// SHT2x sends T and RH in two separate commands (different to other sensors)
// so we have to spit the command into two bytes and
// have to read from I2C two times with EXPECTED_DATA_SIZE / 2

// read T from SHT2x Sensor
// Upper byte is T for SHT2x Sensors
cmd[0] = mI2cCommand >> 8;
// Lower byte is RH for SHT2x Sensors
cmd[1] = mI2cCommand & 0xff;

// read T from SHT2x Sensor
if (!readFromI2c(mWire, mI2cAddress, cmd, mCmd_Size, data,
EXPECTED_DATA_SIZE / 2, mDuration)) {
DEBUG_SHT("SHT2x readFromI2c(T) false\n");
return false;
}

// read RH from SHT2x Sensor
if (!readFromI2c(mWire, mI2cAddress, &cmd[1], mCmd_Size, &data[3],
// Lower byte is RH for SHT2x Sensors
cmd[0] = mI2cCommand & 0xff;
if (!readFromI2c(mWire, mI2cAddress, cmd, mCmd_Size, &data[3],
EXPECTED_DATA_SIZE / 2, mDuration)) {
DEBUG_SHT("SHT2x readFromI2c(RH) false\n");
return false;

0 comments on commit bcae2b6

Please sign in to comment.