diff --git a/examples/c++/tmp006.cxx b/examples/c++/tmp006.cxx index 7dfb3727..8bec1592 100644 --- a/examples/c++/tmp006.cxx +++ b/examples/c++/tmp006.cxx @@ -44,8 +44,13 @@ int main(int argc, char **argv) //! [Interesting] std::cout << "Initializing test-application..." << std::endl; + // please make sure that you have the right i2c address for your device + // the correct range of addresses is 0x40 - 0x47 // Instantiate an TMP006 instance on bus 1 - upm::TMP006 *mySensor = new upm::TMP006(1); + upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP006_I2C_ADDRESS); + + // you can also get basic tmp007 functionality by initializing it as follows + //upm::TMP006 *mySensor = new upm::TMP006(1, TMP006_CONFIG_CR_DEF, TMP007_I2C_ADDRESS); // activate periodic measurements mySensor->setActive(); diff --git a/src/tmp006/tmp006.cpp b/src/tmp006/tmp006.cpp index 4dbaf8c8..bae94568 100644 --- a/src/tmp006/tmp006.cpp +++ b/src/tmp006/tmp006.cpp @@ -42,9 +42,11 @@ TMP006::TMP006(int bus, uint8_t conv_rate, int devAddr) : m_i2ControlCtx(bus) { m_temperature = 0; - m_name = TMP006_NAME;; + m_name = TMP006_NAME; m_controlAddr = devAddr; + + sensorType = TMP006_SEN; m_bus = bus; if (conv_rate > TMP006_CONFIG_CR_AS16) { @@ -85,20 +87,46 @@ TMP006::checkID(void) uint8_t tmp[2]; uint16_t id; int re = 0; + int ret = 0; + tmp[0] = 0;tmp[1] = 0; + // Checking if TMP006 re = m_i2ControlCtx.readBytesReg(TMP006_DEVICE_ID_REG, tmp, 2); if (re != 2) { /* not enough bytes were read! */ - return -1; + //return -1; + ret = -1; } id = ((uint16_t)tmp[0] << 8) | tmp[1]; if (id != TMP006_DEVICE_ID) { - return -1; + //return -1; + ret = -1; + } else { + sensorType = TMP006_SEN; + return 0; } - return 0; + // Checking if TMP007 + re = m_i2ControlCtx.readBytesReg(TMP007_DEVICE_ID_REG, tmp, 2); + if (re != 2) { + /* not enough bytes were read! */ + //return -1; + ret = -1; + } + + id = ((uint16_t)tmp[0] << 8) | tmp[1]; + + if (id != TMP007_DEVICE_ID) { + //return -1; + ret = -1; + } else { + sensorType = TMP007_SEN; + return 0; + } + + return ret; } void @@ -174,9 +202,11 @@ TMP006::sampleData(void) *drdy = buf[0] & (TMP006_DRDY_DATA_RDY); - if(! (*drdy)) { - /* conversation in progress */ - return -1; + if(sensorType == TMP006_SEN) { + if(! (*drdy)) { + /* conversation in progress */ + return -1; + } } tmp = m_i2ControlCtx.readWordReg(TMP006_SENSOR_VOLTAGE); diff --git a/src/tmp006/tmp006.hpp b/src/tmp006/tmp006.hpp index fe57723e..2fff3eb9 100644 --- a/src/tmp006/tmp006.hpp +++ b/src/tmp006/tmp006.hpp @@ -35,6 +35,10 @@ #define TMP006_MANUFACTURER_ID 0x5449 #define TMP006_DEVICE_ID 0x0067 +#define TMP007_I2C_ADDRESS 0x40 +// this should actually be split +#define TMP007_DEVICE_ID 0x0078 + #ifndef TMP006_CONVERSION_TIME #define TMP006_CONVERSION_TIME 1E6 /**< Default Conversion Time in us */ #endif @@ -46,6 +50,9 @@ #define TMP006_MANUFACTURER_ID_REG 0xFE #define TMP006_DEVICE_ID_REG 0xFF +/* TMP007 Register Map */ +#define TMP007_DEVICE_ID_REG 0x1F + /* TMP006 configuration register bitmap */ #define TMP006_RST_SOFT (1 << 15) @@ -86,6 +93,10 @@ #define TMP006_CCONST_C2 13.4 /* Constant \f$c_{\mathrm{2}}\f$ */ #define TMP006_CCONST_LSB_SIZE 156.25E-9 /* Sensor Voltage Register LSB Size */ +typedef enum { + TMP006_SEN, + TMP007_SEN } tmp_t; + namespace upm { /** @@ -195,6 +206,7 @@ class TMP006 { int m_controlAddr; int m_bus; mraa::I2c m_i2ControlCtx; + tmp_t sensorType; int32_t m_temperature; };