Drivber for Ti's TMP007 Infrared Thermopile Sensor with Integrated Math Engine
Diff: src/TMP007.cpp
- Revision:
- 1:93710a3abf0a
- Parent:
- 0:a1ed9ce625d4
--- a/src/TMP007.cpp Sun Jun 05 19:38:48 2016 +0000 +++ b/src/TMP007.cpp Sun Jun 05 19:53:43 2016 +0000 @@ -40,7 +40,7 @@ //-------------------------------------------------------------------------------- uint16_t TMP007::readConfig() { - uint16_t res = readWord(TMP007_CONFIG); + uint16_t res = readWord(TMP007_CONFIG); return res; } @@ -50,6 +50,12 @@ return readWord(TMP007_STATUS); } +//-------------------------------------------------------------------------------- +void TMP007::writeStatusMask(const uint16_t value) +{ + writeWord(TMP007_STATUS_MASK, value); +} + //-------------------------------------------------------------------------------- /** TMP007 Config method. * Used for configuring the sensor with desired samples. @@ -70,14 +76,7 @@ */ uint16_t TMP007::readRawLocalTemperature() { - int16_t raw = 0; - char reg = TMP007_LOCAL_TEMP; - char data[2]; - - _i2cPort.write(_addr, ®, 1); - _i2cPort.read(_addr, data, 2); - - raw = (data[0] << 8) | data[1] ; + uint16_t raw = readWord(TMP007_LOCAL_TEMP); raw >>= 2; return raw; @@ -89,15 +88,7 @@ */ uint16_t TMP007::readRawSensorVoltage() { - char reg=TMP007_SENSOR_VOLT; - char data[2]; - - _i2cPort.write(_addr, ®, 1); - _i2cPort.read(_addr, data, 2); - - int16_t raw = (data[0] << 8) | data[1] ; - - return raw; + return readWord(TMP007_SENSOR_VOLT); } //-------------------------------------------------------------------------------- @@ -115,8 +106,7 @@ // Equations for calculating temperature found in section 7.3.4 in the user guide double tdie_tref = Tdie - TMP007_TREF; - double S = (1 + TMP007_A1*tdie_tref + - TMP007_A2*tdie_tref*tdie_tref); + double S = (1 + TMP007_A1*tdie_tref + TMP007_A2*tdie_tref*tdie_tref); S *= TMP007_S0; S /= 10000000; S /= 10000000;