-
Notifications
You must be signed in to change notification settings - Fork 1
/
SHT1x.h
56 lines (52 loc) · 1.43 KB
/
SHT1x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* SHT1x Library
*
* Copyright 2020 Chih-Yu Hsiang <[email protected]>
* Based on previous work by:
* Jonathan Oxer <[email protected]> / <www.practicalarduino.com>
* Maurice Ribble: <www.glacialwanderer.com/hobbyrobotics/?p=5>
* Wayne ?: <ragingreality.blogspot.com/2008/01/ardunio-and-sht15.html>
*
* Manages communication with SHT1x series (SHT10, SHT11, SHT15)
* temperature / humidity sensors from Sensirion (www.sensirion.com).
*/
#ifndef SHT1x_h
#define SHT1x_h
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
enum class TempUnit : uint8_t{
C,
F
};
class SHT1x
{
public:
SHT1x(int dataPin, int clockPin):_dataPin(dataPin), _clockPin(clockPin){
pinMode(_clockPin, OUTPUT);
}
void init() {
connectionReset();
readStatusReg(true);
}
float readHumidity(const bool checkSum=true);
float readTemperature(const TempUnit unit,const bool checkSum=true);
void connectionReset();
void softReset();
uint8_t readStatusReg(const bool checkSum=true);
void writeStatusReg(const uint8_t value);
private:
int _dataPin;
int _clockPin;
uint8_t crc_init;
int shiftIn(const int _numBits);
void transStart();
void writeByte(const uint8_t data);
int readByte(const bool ack);
void waitForResult();
uint8_t crc8(const unsigned int data, const int size, const uint8_t init=0);
uint8_t reverseByte(const uint8_t data);
};
#endif