Skip to content

Commit ac8fdd4

Browse files
authored
Prepare for derived SHT31_SW (#37)
- prepare for derived class SHT31_SW - update readme.md - update GitHub actions - update license 2023 - minor edits
1 parent 0208447 commit ac8fdd4

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.3.8] - 2023-03-23
10+
- prepare for derived class SHT31_SW
11+
- update readme.md
12+
- update GitHub actions
13+
- update license 2023
14+
- minor edits
15+
16+
917
## [0.3.7] - 2022-11-24
1018
- Add RP2040 support to build-CI.
1119
- Add CHANGELOG.md
1220
- update readme.md
1321

14-
1522
## [0.3.6] - 2022-01-18
1623
- sync with SHT85 lib
1724

SHT31.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: SHT31.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.3.7
4+
// VERSION: 0.3.8
55
// DATE: 2019-02-08
66
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
77
// https://www.adafruit.com/product/2857
@@ -28,6 +28,7 @@
2828

2929
SHT31::SHT31()
3030
{
31+
_wire = NULL;
3132
_address = 0;
3233
_lastRead = 0;
3334
_rawTemperature = 0;

SHT31.h

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
//
33
// FILE: SHT31.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.3.7
5+
// VERSION: 0.3.8
66
// DATE: 2019-02-08
77
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
88
// https://www.adafruit.com/product/2857
99
// URL: https://github.com/RobTillaart/SHT31
1010

1111

1212
#include "Arduino.h"
13-
#include "Wire.h"
13+
#include "Wire.h"
1414

1515

16-
#define SHT31_LIB_VERSION (F("0.3.7"))
16+
#define SHT31_LIB_VERSION (F("0.3.8"))
1717

1818
#ifndef SHT_DEFAULT_ADDRESS
1919
#define SHT_DEFAULT_ADDRESS 0x44
2020
#endif
2121

22-
// fields readStatus
22+
// fields readStatus
2323
#define SHT31_STATUS_ALERT_PENDING (1 << 15)
2424
#define SHT31_STATUS_HEATER_ON (1 << 13)
2525
#define SHT31_STATUS_HUM_TRACK_ALERT (1 << 11)
@@ -28,7 +28,7 @@
2828
#define SHT31_STATUS_COMMAND_STATUS (1 << 1)
2929
#define SHT31_STATUS_WRITE_CRC_STATUS (1 << 0)
3030

31-
// error codes
31+
// error codes
3232
#define SHT31_OK 0x00
3333
#define SHT31_ERR_WRITECMD 0x81
3434
#define SHT31_ERR_READBYTES 0x82
@@ -48,30 +48,30 @@ class SHT31
4848

4949
#if defined(ESP8266) || defined(ESP32)
5050
bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
51-
// use SHT_DEFAULT_ADDRESS
51+
// use SHT_DEFAULT_ADDRESS
5252
bool begin(const uint8_t dataPin, const uint8_t clockPin);
5353
#endif
5454
bool begin(const uint8_t address, TwoWire *wire = &Wire);
55-
// use SHT_DEFAULT_ADDRESS
55+
// use SHT_DEFAULT_ADDRESS
5656
bool begin(TwoWire *wire = &Wire);
5757

58-
// blocks 15 milliseconds + actual read + math
58+
// blocks 15 milliseconds + actual read + math
5959
bool read(bool fast = true);
6060

61-
// check sensor is reachable over I2C
62-
bool isConnected();
61+
// check sensor is reachable over I2C
62+
virtual bool isConnected();
6363

64-
// details see datasheet; summary in SHT31.cpp file
64+
// details see datasheet; summary in SHT31.cpp file
6565
uint16_t readStatus();
6666

67-
// lastRead is in milliSeconds since start
67+
// lastRead is in milliSeconds since start
6868
uint32_t lastRead() { return _lastRead; };
6969

7070
bool reset(bool hard = false);
7171

72-
// do not use heater for long periods,
73-
// use it for max 3 minutes to heat up
74-
// and let it cool down at least 3 minutes.
72+
// do not use heater for long periods,
73+
// use it for max 3 minutes to heat up
74+
// and let it cool down at least 3 minutes.
7575
void setHeatTimeout(uint8_t seconds);
7676
uint8_t getHeatTimeout() { return _heatTimeout; };
7777
bool heatOn();
@@ -91,18 +91,13 @@ class SHT31
9191
bool dataReady();
9292
bool readData(bool fast = true);
9393

94-
int getError(); // clears error flag
95-
96-
private:
97-
uint8_t crc8(const uint8_t *data, uint8_t len);
98-
bool writeCmd(uint16_t cmd);
99-
bool readBytes(uint8_t n, uint8_t *val);
100-
TwoWire* _wire;
94+
int getError(); // clears error flag
10195

96+
protected:
10297
uint8_t _address;
103-
uint8_t _heatTimeout; // seconds
98+
uint8_t _heatTimeout; // seconds
10499
uint32_t _lastRead;
105-
uint32_t _lastRequest; // for async interface
100+
uint32_t _lastRequest; // for async interface
106101
uint32_t _heaterStart;
107102
uint32_t _heaterStop;
108103
bool _heaterOn;
@@ -111,6 +106,15 @@ class SHT31
111106
uint16_t _rawTemperature;
112107

113108
uint8_t _error;
109+
110+
private:
111+
uint8_t crc8(const uint8_t *data, uint8_t len);
112+
virtual bool writeCmd(uint16_t cmd);
113+
virtual bool readBytes(uint8_t n, uint8_t *val);
114+
TwoWire* _wire;
114115
};
115116

116-
// -- END OF FILE --
117+
118+
// -- END OF FILE --
119+
120+

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/SHT31"
1717
},
18-
"version": "0.3.7",
18+
"version": "0.3.8",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SHT31
2-
version=0.3.7
2+
version=0.3.8
33
author=Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
55
sentence=Arduino library for the SHT31 temperature and humidity sensor

0 commit comments

Comments
 (0)