forked from tinkertanker/microDriver_SHT2x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver_sht2x.h
58 lines (46 loc) · 1.39 KB
/
driver_sht2x.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
57
58
#ifndef DRIVER_SHT2X_H
#define DRIVER_SHT2X_H
#define DRIVER_SHT2X_H
#include <stddef.h>
#include "pxt.h"
#define DEBUG 1
/* DEBUG PRINT */
#ifdef DEBUG
#undef printf
#define dprint(msg) uBit.serial.printf("DEBUG: %d: %s: %s\r\n",__LINE__,__func__,msg)
#define dprintf(...) uBit.serial.printf("DEBUG: " __VA_ARGS__)
#else
#define dprint(msg)
#define dprintf(...)
// ^^ Empty Define ^^
#endif /* DEBUG PRINT */
/* Address for talking to i2c */
#define SHT2X_I2C_ADDR_DEFAULT 0x40
#define SHT2X_PANIC_CODE 80
/* Macros for converting data from the sensor to human readable measurements */
#define SHT_CONV_TEMP(val) (-46.85 + (175.72 / 65536.0 * (double) val))
#define SHT_CONV_HUMID(val) (-6.0 + (125.0 / 65536.0 * (double) val))
namespace SHT2xDriver
{
/*
* Commands for the SHT2x sensor
* see spec.txt or the SHT2x Datasheet
*/
typedef enum sht_command_t
{
sht_command_temperature_hold = 0xE3,
sht_command_humidity_hold = 0xE5,
sht_command_temperature = 0xF3,
sht_command_humidity = 0xF5
}SHTCommand;
/* Read humidity level from the sensor in %Relative Humidity*/
//%
int read_humidity();
/* Read temperature from the sensor in degree's celcius*/
//%
int read_temperature();
/* Set the i2c address for the SHT2x sensor */
//%
void set_i2c_address(int address);
}
#endif /* ifndef DRIVER_SHT2X_H */