2017-10-26 10:21:12 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 HAW Hamburg
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-02-25 17:17:11 +01:00
|
|
|
* @ingroup drivers_shtcx
|
2017-10-26 10:21:12 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2022-02-25 17:17:11 +01:00
|
|
|
* @brief SHTCX adaption to the RIOT actuator/sensor interface
|
2017-10-26 10:21:12 +02:00
|
|
|
*
|
|
|
|
* @author Michel Gerlach <michel.gerlach@haw-hamburg.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "saul.h"
|
2022-02-25 17:17:11 +01:00
|
|
|
#include "shtcx.h"
|
2017-10-26 10:21:12 +02:00
|
|
|
|
|
|
|
static int read_temperature(const void *dev, phydat_t *res)
|
|
|
|
{
|
2022-02-25 17:17:11 +01:00
|
|
|
if (shtcx_read((shtcx_t *)dev, NULL, &res->val[0]) != SHTCX_OK) {
|
2017-10-26 10:21:12 +02:00
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
res->unit = UNIT_TEMP_C;
|
|
|
|
res->scale = -2;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_relative_humidity(const void *dev, phydat_t *res)
|
|
|
|
{
|
2022-02-25 17:17:11 +01:00
|
|
|
if (shtcx_read((shtcx_t *)dev, (uint16_t *)&res->val[0], NULL) != SHTCX_OK) {
|
2017-10-26 10:21:12 +02:00
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
res->unit = UNIT_PERCENT;
|
|
|
|
res->scale = -2;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-02-25 17:17:11 +01:00
|
|
|
const saul_driver_t shtcx_temperature_saul_driver = {
|
2017-10-26 10:21:12 +02:00
|
|
|
.read = read_temperature,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-10-26 10:21:12 +02:00
|
|
|
.type = SAUL_SENSE_TEMP,
|
|
|
|
};
|
|
|
|
|
2022-02-25 17:17:11 +01:00
|
|
|
const saul_driver_t shtcx_relative_humidity_saul_driver = {
|
2017-10-26 10:21:12 +02:00
|
|
|
.read = read_relative_humidity,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-10-26 10:21:12 +02:00
|
|
|
.type = SAUL_SENSE_HUM,
|
|
|
|
};
|