zephyr/samples/sensor/tmp112/src/main.c
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00

67 lines
1.3 KiB
C

/*
* Copyright (c) 2016 Firmwave
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <misc/printk.h>
#include <misc/__assert.h>
static void do_main(struct device *dev)
{
int ret;
struct sensor_value temp_value;
struct sensor_value attr;
attr.val1 = 150;
attr.val2 = 0;
ret = sensor_attr_set(dev, SENSOR_CHAN_TEMP,
SENSOR_ATTR_FULL_SCALE, &attr);
if (ret) {
printk("sensor_attr_set failed ret %d\n", ret);
return;
}
attr.val1 = 8;
attr.val2 = 0;
ret = sensor_attr_set(dev, SENSOR_CHAN_TEMP,
SENSOR_ATTR_SAMPLING_FREQUENCY, &attr);
if (ret) {
printk("sensor_attr_set failed ret %d\n", ret);
return;
}
while (1) {
ret = sensor_sample_fetch(dev);
if (ret) {
printk("sensor_sample_fetch failed ret %d\n", ret);
return;
}
ret = sensor_channel_get(dev, SENSOR_CHAN_TEMP, &temp_value);
if (ret) {
printk("sensor_channel_get failed ret %d\n", ret);
return;
}
printk("temp is %d (%d micro)\n", temp_value.val1,
temp_value.val2);
k_sleep(1000);
}
}
void main(void)
{
struct device *dev;
dev = device_get_binding("TMP112");
__ASSERT(dev != NULL, "Failed to get device binding");
printk("device is %p, name is %s\n", dev, dev->config->name);
do_main(dev);
}