mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
mlx90614: patched i2c reads from temperature registers
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
94de822499
commit
255d6139ee
@ -51,8 +51,8 @@ MLX90614::MLX90614 (int bus, int devAddr) : m_i2Ctx(bus) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
MLX90614::readObjectTempF(void) {
|
MLX90614::readObjectTempF(int objAddr) {
|
||||||
return (readTemperature(MLX90614_TOBJ1) * 9 / 5) + 32;
|
return (readTemperature(objAddr) * 9 / 5) + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
@ -61,8 +61,8 @@ MLX90614::readAmbientTempF(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
MLX90614::readObjectTempC(void) {
|
MLX90614::readObjectTempC(int objAddr) {
|
||||||
return readTemperature(MLX90614_TOBJ1);
|
return readTemperature(objAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
@ -75,42 +75,7 @@ MLX90614::readAmbientTempC(void) {
|
|||||||
* private area
|
* private area
|
||||||
* **************
|
* **************
|
||||||
*/
|
*/
|
||||||
uint16_t
|
|
||||||
MLX90614::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) {
|
|
||||||
int readByte = 0;
|
|
||||||
|
|
||||||
m_i2Ctx.address(m_i2cAddr);
|
|
||||||
m_i2Ctx.writeByte(reg);
|
|
||||||
|
|
||||||
readByte = m_i2Ctx.read(buffer, len);
|
|
||||||
return readByte;
|
|
||||||
}
|
|
||||||
|
|
||||||
mraa::Result
|
|
||||||
MLX90614::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) {
|
|
||||||
mraa::Result error = mraa::SUCCESS;
|
|
||||||
|
|
||||||
error = m_i2Ctx.address(m_i2cAddr);
|
|
||||||
error = m_i2Ctx.write(buffer, len);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
float
|
float
|
||||||
MLX90614::readTemperature (uint8_t address) {
|
MLX90614::readTemperature (uint8_t address) {
|
||||||
uint8_t buffer[3];
|
return m_i2Ctx.readWordReg(address) * 0.02 - 273.15;
|
||||||
float temperature = 0;
|
|
||||||
|
|
||||||
/* Reading temperature from sensor.
|
|
||||||
Answer contained of 3 bytes (TEMP_LSB | TEMP_MSB | PEC)
|
|
||||||
*/
|
|
||||||
if (i2cReadReg_N(address, 3, buffer) > 2) {
|
|
||||||
temperature = buffer[0];
|
|
||||||
temperature = buffer[1] << 8;
|
|
||||||
|
|
||||||
temperature *= .02;
|
|
||||||
temperature -= 273.15;
|
|
||||||
}
|
|
||||||
|
|
||||||
return temperature;
|
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,11 @@ class MLX90614 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the object temperature in Fahrenheit
|
* Reads the object temperature in Fahrenheit
|
||||||
|
*
|
||||||
|
* @param objAddr Object register for models with dual sensors
|
||||||
|
* Can be MLX90614_TOBJ1 (default) or MLX90614_TOBJ2
|
||||||
*/
|
*/
|
||||||
float readObjectTempF(void);
|
float readObjectTempF(int objAddr=MLX90614_TOBJ1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the ambient temperature in Fahrenheit
|
* Reads the ambient temperature in Fahrenheit
|
||||||
@ -94,8 +97,11 @@ class MLX90614 {
|
|||||||
float readAmbientTempF(void);
|
float readAmbientTempF(void);
|
||||||
/**
|
/**
|
||||||
* Reads the object temperature in Celsius
|
* Reads the object temperature in Celsius
|
||||||
|
*
|
||||||
|
* @param objAddr Object register for models with dual sensors
|
||||||
|
* Can be MLX90614_TOBJ1 (default) or MLX90614_TOBJ2
|
||||||
*/
|
*/
|
||||||
float readObjectTempC(void);
|
float readObjectTempC(int objAddr=MLX90614_TOBJ1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the ambient temperature in Celsius
|
* Reads the ambient temperature in Celsius
|
||||||
|
Loading…
x
Reference in New Issue
Block a user