Skip to content

Commit

Permalink
add readTemperatureForHumidity()
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsbyr committed Nov 26, 2023
1 parent 18cc6ce commit fa553a3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.4.2] - 2023-11-25
- add **readTemperatureForHumidity()** to async interface
- update readme.md

## [0.4.1] - 2023-11-25
- fix **reset()**: clear state of resolution, heater and error
- update readme.md
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ Timing in milliseconds.
#### 0.4.1
- fix reset(): clear state of resolution, heater and error

#### 0.4.2
- add readTemperatureForHumidity()

#### Should

- test test test
Expand Down
26 changes: 25 additions & 1 deletion SHT2x.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: SHT2x.cpp
// AUTHOR: Rob Tillaart, Viktor Balint, JensB
// VERSION: 0.4.1
// VERSION: 0.4.2
// DATE: 2023-11-25
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor
// URL: https://github.com/RobTillaart/SHT2x
Expand All @@ -12,6 +12,7 @@

// SUPPORTED COMMANDS
#define SHT2x_GET_TEMPERATURE_NO_HOLD 0xF3
#define SHT2x_GET_TEMPERATURE_FOR_HUMIDITY 0xE0
#define SHT2x_GET_HUMIDITY_NO_HOLD 0xF5
#define SHT2x_SOFT_RESET 0xFE
#define SHT2x_WRITE_USER_REGISTER 0xE6
Expand Down Expand Up @@ -229,6 +230,29 @@ bool SHT2x::readHumidity()
}


bool SHT2x::readTemperatureForHumidity()
{
if (_error == SHT2x_OK)
{
writeCmd(SHT2x_GET_TEMPERATURE_FOR_HUMIDITY);
uint8_t buffer[2];
if (readBytes(2, (uint8_t*) &buffer[0], 10) == false)
{
_error = SHT2x_ERR_READBYTES;
return false;
}
_rawTemperature = buffer[0] << 8;
_rawTemperature += buffer[1];
_rawTemperature &= 0xFFFC;
return true;
}
else
{
return false;
}
}


uint32_t SHT2x::lastRequest()
{
return _lastRequest;
Expand Down
5 changes: 3 additions & 2 deletions SHT2x.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: SHT2x.h
// AUTHOR: Rob Tillaart, Viktor Balint, JensB
// VERSION: 0.4.1
// VERSION: 0.4.2
// DATE: 2023-11-25
// PURPOSE: Arduino library for the SHT2x temperature and humidity sensor
// URL: https://github.com/RobTillaart/SHT2x
Expand All @@ -13,7 +13,7 @@
#include "Wire.h"


#define SHT2x_LIB_VERSION (F("0.4.1"))
#define SHT2x_LIB_VERSION (F("0.4.2"))


// fields getStatus
Expand Down Expand Up @@ -152,6 +152,7 @@ class SHT2x
bool requestReady();
bool readTemperature();
bool readHumidity();
bool readTemperatureForHumidity();
uint32_t lastRequest();
uint8_t getRequestType();

Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ reqHumReady KEYWORD2
requestReady KEYWORD2
readTemperature KEYWORD2
readHumidity KEYWORD2
readTemperatureForHumidity KEYWORD2
lastRequest KEYWORD2
getRequestType KEYWORD2

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/SHT2x.git"
},
"version": "0.4.1",
"version": "0.4.2",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SHT2x
version=0.4.1
version=0.4.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the I2C SHT20 SHT21 SHT25 series temperature and humidity sensor.
Expand Down

0 comments on commit fa553a3

Please sign in to comment.