samples: sensor: tmp116: Add sample code for tmp117

Add sample code which demostrates the use of the offset
register offered in the TMP117.
Also add information about tmp117 in README.

Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
This commit is contained in:
Puranjay Mohan 2020-12-16 22:39:51 +05:30 committed by Anas Nashif
commit 4111cfd73c
2 changed files with 21 additions and 2 deletions

View file

@ -7,12 +7,13 @@ Description
***********
This sample application periodically takes temperature readings using the ti_tmp116
sensor driver. The result is written to the console.
sensor driver. The result is written to the console. This sample also included the code
to use the features provided by TMP117, which is a sensor similar to TMP116
Requirements
************
This sample needs a TI TMP116 sensor connected to the target board's I2C
This sample needs a TI TMP116 or TI TMP117 sensor connected to the target board's I2C
connector.

View file

@ -14,6 +14,11 @@ void main(void)
{
const struct device *dev;
struct sensor_value temp_value;
/* offset to be added to the temperature
* only supported by TMP117
*/
struct sensor_value offset_value;
int ret;
dev = device_get_binding(DT_LABEL(DT_INST(0, ti_tmp116)));
@ -21,6 +26,19 @@ void main(void)
printk("Device %s - %p is ready\n", dev->name, dev);
/*
* if an offset of 2.5 oC is to be added,
* set val1 = 2 and val2 = 500000.
* See struct sensor_value documentation for more details.
*/
offset_value.val1 = 0;
offset_value.val2 = 0;
ret = sensor_attr_set(dev, SENSOR_CHAN_AMBIENT_TEMP,
SENSOR_ATTR_OFFSET, &offset_value);
if (ret) {
printk("sensor_attr_set failed ret = %d\n", ret);
printk("SENSOR_ATTR_OFFSET is only supported by TMP117\n");
}
while (1) {
ret = sensor_sample_fetch(dev);
if (ret) {