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 )
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+
0 commit comments