upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
tmp006.hpp
1 /*
2  * Author: Norbert Wesp <nwesp@phytec.de>
3  * Copyright (c) 2017 Phytec Messtechnik GmbH.
4  *
5  * based on: RIOT-driver tmp006 by Johann Fischer <j.fischer@phytec.de>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #pragma once
28 
29 #include <string>
30 #include <mraa/i2c.hpp>
31 #include <math.h>
32 
33 #define TMP006_NAME "TMP006"
34 #define TMP006_I2C_ADDRESS 0x41
35 #define TMP006_MANUFACTURER_ID 0x5449
36 #define TMP006_DEVICE_ID 0x0067
37 
38 #define TMP007_I2C_ADDRESS 0x40
39 // this should actually be split
40 #define TMP007_DEVICE_ID 0x0078
41 
42 #ifndef TMP006_CONVERSION_TIME
43 #define TMP006_CONVERSION_TIME 1E6
44 #endif
45 
46 /* TMP006 Register Map */
47 #define TMP006_SENSOR_VOLTAGE 0x00 /* Sensor voltage register */
48 #define TMP006_LOCAL_TEMPERATURE 0x01 /* Ambient temperature register */
49 #define TMP006_CONFIGURATION 0x02
50 #define TMP006_MANUFACTURER_ID_REG 0xFE
51 #define TMP006_DEVICE_ID_REG 0xFF
52 
53 /* TMP007 Register Map */
54 #define TMP007_DEVICE_ID_REG 0x1F
55 
56 /* TMP006 configuration register bitmap */
57 #define TMP006_RST_SOFT (1 << 15)
58 
59 #define TMP006_CONFIG_MOD_SHIFT 12
60 #define TMP006_CONFIG_MOD_MASK 0x7000
61 #define TMP006_CONFIG_MOD(x) (((uint16_t)(((uint16_t)(x))<<\
62  TMP006_CONFIG_MOD_SHIFT))\
63  &TMP006_CONFIG_MOD_MASK)
64 #define TMP006_CONFIG_MOD_CC 0x07
65 #define TMP006_CONFIG_MOD_OFF 0x00
66 
67 #define TMP006_CONFIG_CR_SHIFT 9
68 #define TMP006_CONFIG_CR_MASK 0x0E00
69 #define TMP006_CONFIG_CR(x) (((uint16_t)(((uint16_t)(x))<<\
70  TMP006_CONFIG_CR_SHIFT))\
71  &TMP006_CONFIG_CR_MASK)
72 #define TMP006_CONFIG_CR_AS1 0x00 /* Conversion Time 0.25 s, AVG Samples: 1 */
73 #define TMP006_CONFIG_CR_AS2 0x01 /* Conversion Time 0.5 s, AVG Samples: 2 */
74 #define TMP006_CONFIG_CR_AS4 0x02 /* Conversion Time 1 s, AVG Samples: 4 */
75 #define TMP006_CONFIG_CR_AS8 0x03 /* Conversion Time 2 s, AVG Samples: 8 */
76 #define TMP006_CONFIG_CR_AS16 0x04 /* Conversion Time 4 s, AVG Samples: 16 */
77 #define TMP006_CONFIG_CR_DEF TMP006_CONFIG_CR_AS4
79 #define TMP006_DRDY_EN (1 << 8)
80 #define TMP006_DRDY_DATA_RDY (1 << 7)
81 
82 /* constant values for data conversion */
83 #ifndef TMP006_CCONST_S0
84 #define TMP006_CCONST_S0 6.4E-14 /* Calibration Factor */
85 #endif
86 
87 #define TMP006_CCONST_A1 1.75E-3 /* Constant \f$a_{\mathrm{1}}\f$ */
88 #define TMP006_CCONST_A2 -1.678E-5 /* Constant \f$a_{\mathrm{2}}\f$ */
89 #define TMP006_CCONST_TREF 298.15 /* Constant \f$T_{\mathrm{REF}}\f$ */
90 #define TMP006_CCONST_B0 -2.94E-5 /* Constant \f$b_{\mathrm{0}}\f$ */
91 #define TMP006_CCONST_B1 -5.7E-7 /* Constant \f$b_{\mathrm{1}}\f$ */
92 #define TMP006_CCONST_B2 4.63E-9 /* Constant \f$b_{\mathrm{2}}\f$ */
93 #define TMP006_CCONST_C2 13.4 /* Constant \f$c_{\mathrm{2}}\f$ */
94 #define TMP006_CCONST_LSB_SIZE 156.25E-9 /* Sensor Voltage Register LSB Size */
95 
96 typedef enum {
97  TMP006_SEN,
98  TMP007_SEN } tmp_t;
99 
100 namespace upm {
101 
135 class TMP006 {
136  public:
145  TMP006 (int bus, uint8_t conv_rate=TMP006_CONFIG_CR_DEF,
146  int devAddr=TMP006_I2C_ADDRESS);
147 
154  int checkID(void);
155 
160  void resetSensor(void);
161 
165  void setActive(void);
166 
170  void setStandby(void);
171 
176  int sampleData(void);
177 
186  void convert_data(int16_t rawv,int16_t rawt, float *tamb, float *tobj);
187 
195  float getTemperature(int bSampleData = 0);
196 
200  uint16_t getConfig(void);
201 
202  private:
203 
204  std::string m_name;
205 
206  int m_controlAddr;
207  int m_bus;
208  mraa::I2c m_i2ControlCtx;
209  tmp_t sensorType;
210 
211  int32_t m_temperature;
212 };
213 
214 }
void resetSensor(void)
Definition: tmp006.cpp:133
TMP006(int bus, uint8_t conv_rate=TMP006_CONFIG_CR_DEF, int devAddr=TMP006_I2C_ADDRESS)
Definition: tmp006.cpp:39
int sampleData(void)
Definition: tmp006.cpp:189
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
float getTemperature(int bSampleData=0)
Definition: tmp006.cpp:256
int checkID(void)
Definition: tmp006.cpp:85
void setActive(void)
Definition: tmp006.cpp:149
API for the TMP006 IR-Thermopile Sensor.
Definition: tmp006.hpp:135
void setStandby(void)
Definition: tmp006.cpp:169
uint16_t getConfig(void)
Definition: tmp006.cpp:268
void convert_data(int16_t rawv, int16_t rawt, float *tamb, float *tobj)
Definition: tmp006.cpp:229