-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADT7420.h
More file actions
74 lines (62 loc) · 1.32 KB
/
Copy pathADT7420.h
File metadata and controls
74 lines (62 loc) · 1.32 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* ADT7420.h
*
* Created on: Jan. 22nd, 2016
* Author: KuangQi
*/
#ifndef ADT7420_H_
#define ADT7420_H_
#include "mbed.h"
class ADT7420 {
public:
enum I2CAddress
{
ADDRESS0 = (0x48 << 1),
ADDRESS1 = (0x49 << 1),
ADDRESS2 = (0x4A << 1),
ADDRESS3 = (0x4B << 1)
};
enum Resolution
{
RES_13BIT = (0 << 7),
RES_16BIT = (1 << 7)
};
enum ConvertMode
{
MODE_CONT = (0 << 5),
MODE_ONE_SHOT = (1 << 5),
MODE_1SPS = (2 << 5),
MODE_SHUTDOWN = (3 << 5)
};
ADT7420(PinName sda, PinName scl, I2CAddress addr = ADDRESS0, int freq = 100000);
bool isOK();
bool dataAvailable();
int getID();
void setResolution(Resolution resolution);
void setConvertMode(ConvertMode mode);
float temperature();
#ifdef MBED_OPERATORS
/** A shorthand for temperature()
*
* @returns The current temperature measurement in degree C.
*/
operator float();
#endif
private:
enum Register {
REG_TEMPH = 0x00,
REG_TEMPL = 0x01,
REG_STATUS = 0x02,
REG_CONFIG = 0x03,
REG_THYST = 0x0A,
REG_ID = 0x0B
};
I2C sensor;
Resolution res;
uint8_t i2c_addr;
uint8_t reg_config = 0;
const uint8_t READY_BIT = (1 << 7);
const uint8_t RESOL_BIT = (1 << 7);
const uint8_t MODE_BIT = (3 << 5);
};
#endif /* ADT7420_H_ */