forked from joaobarroca93/MLX90615
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLX90615.h
100 lines (80 loc) · 3.12 KB
/
MLX90615.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
MLX90615.h - Library for reading MLX90615 sensor.
*/
#ifndef MLX90615_h
#define MLX90615_h
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h>
//#include "Property.h"
#include "Crc8.h"
#define MLX90615_I2CDEFAULTADDR 0x5B /**< Device default slave address */
#define MLX90615_BROADCASTADDR 0 /**< Device broadcast slave address */
#define MLX90615_CRC8POLY 7 /**< CRC polynomial = X8+X2+X1+1 */
#define MLX90615_XDLY 25 /**< Experimentally determined delay to prevent read
errors after calling Wire.endTransmission()
<em>(possibly due to incompatibility between Wire
library and SMBus protocol)</em>. */
// EEPROM ADRESSES
#define MLX90615_EEPROMADDR 0x10
#define MLX90615_ADDR 0x00
#define MLX90615_PWM_T_MIN 0x00
#define MLX90615_PWM_T_RANGE 0x01
#define MLX90615_CONFIG 0x02
#define MLX90615_EMISSIVITY 0x03
#define MLX90615_ID_1 0x0E
#define MLX90615_ID_2 0x0F
// RAM ADRESSES
#define MLX90615_RAMADDR 0x20
#define MLX90615_RAW_IR_DATA 0x05
#define MLX90615_T_AMBIENT 0x06
#define MLX90615_T_OBJECT 0x07
// COMMANDS
#define MLX90615_SLEEP_MODE 0xC6
// R/W Error flags - bitmask
#define MLX90615_NORWERROR 0 // R/W error bitmask - No Errors
#define MLX90615_RXCRC 0x10 // R/W error bitmask - Receiver CRC mismatch
#define MLX90615_INVALIDATA 0x20 // R/W error bitmask - RX/TX Data fails selection criteria
#define MLX90615_EECORRUPT 0x40 // R/W error bitmask - The EEProm is ikely to be corrupted
class MLX90615
{
public:
MLX90615(uint8_t i2caddr = MLX90615_I2CDEFAULTADDR);
boolean begin(void);
boolean sleep(void);
boolean wakeUp(void);
float getEmissivity(void);
uint8_t getIIR(void);
void setEmissivity(float emissivity = 1.0);
void setIIR(uint8_t csb = 1);
void writeEEprom(uint8_t, uint16_t);
uint16_t readEEprom(uint8_t);
uint16_t readRAM(uint8_t);
/** Enumerations for temperature units. */
enum tempUnit_t {MLX90615_TK, /**< degrees Kelvin */
MLX90615_TC, /**< degrees Centigrade */
MLX90615_TF /**< degrees Fahrenheit */
};
/** Enumerations for temperature measurement source. */
enum tempSrc_t {MLX90615_SRCA, /**< Chip (ambient) sensor */
MLX90615_SRCO, /**< IR source */
};
double readTemp(tempSrc_t = MLX90615_SRCO, tempUnit_t = MLX90615_TC);
double kelvin2celcius(double);
double celcius2farenheit(double);
private:
boolean _ready;
boolean _sleep;
uint8_t _addr; // Slave Adress
uint8_t _rwError; // R/W error flags
uint8_t _crc8; // 8 bit CRC
uint8_t _pec; // PEC
uint16_t read16(uint8_t);
void write16(uint8_t, uint16_t);
uint8_t getAddr(void);
void setAddr(uint8_t);
};
#endif