Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (34 sloc) 836 Bytes
//
// Copyright (c) 2019 Blue Clover Devices
//
// SPDX-License-Identifier: Apache-2.0
//
/* app_sensor.c - Sensor interface */
#include <zephyr.h>
#include <device.h>
#include <sensor.h>
#include <stdio.h>
int app_sensor_setup(void)
{
struct sensor_value temp, hum;
struct device *dev = device_get_binding("SHT3XD");
int rc;
if (dev == NULL) {
printf("Could not get SHT3XD device\n");
return -1;
}
rc = sensor_sample_fetch(dev);
if (rc == 0) {
rc = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
}
if (rc == 0) {
rc = sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &hum);
}
if (rc != 0) {
printf("SHT3XD: failed: %d\n", rc);
return -1;
}
printf("SHT3XD: %.2f Cel ; %0.2f %%RH\n",
sensor_value_to_double(&temp), sensor_value_to_double(&hum));
return 0;
}
You can’t perform that action at this time.