2015-02-12 18:06:34 +01:00
|
|
|
/*
|
2013-06-22 05:11:53 +02:00
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
2014-07-31 19:45:27 +02:00
|
|
|
* 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.
|
2015-02-12 18:06:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup sys_shell_commands
|
2013-06-22 05:11:53 +02:00
|
|
|
* @{
|
2015-02-12 18:06:34 +01:00
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Provides shell commands to poll sht11 sensor
|
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
*
|
2013-06-22 05:11:53 +02:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
2012-11-06 00:55:05 +01:00
|
|
|
#include <stdlib.h>
|
2010-11-07 23:18:41 +01:00
|
|
|
#include <string.h>
|
2013-12-16 17:54:58 +01:00
|
|
|
#include "sht11.h"
|
2010-11-07 23:18:41 +01:00
|
|
|
|
2010-12-03 22:22:58 +01:00
|
|
|
#ifdef MODULE_SHT11
|
|
|
|
|
2010-11-07 23:18:41 +01:00
|
|
|
extern float sht11_temperature_offset;
|
2010-11-04 18:16:39 +01:00
|
|
|
|
2015-03-20 08:51:45 +01:00
|
|
|
int _get_humidity_handler(int argc, char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-02-21 19:10:24 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
uint8_t success;
|
|
|
|
sht11_val_t sht11_val;
|
2013-06-22 05:11:53 +02:00
|
|
|
success = sht11_read_sensor(&sht11_val, HUMIDITY | TEMPERATURE);
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (!success) {
|
2010-11-04 18:16:39 +01:00
|
|
|
printf("Error reading SHT11\n");
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 1;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%%\n",
|
2013-06-22 05:11:53 +02:00
|
|
|
(double) sht11_val.relhum, (double) sht11_val.relhum_temp);
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 0;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-21 16:24:47 +01:00
|
|
|
|
2015-03-20 08:51:45 +01:00
|
|
|
int _get_temperature_handler(int argc, char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-02-21 19:10:24 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
uint8_t success;
|
|
|
|
sht11_val_t sht11_val;
|
|
|
|
success = sht11_read_sensor(&sht11_val, TEMPERATURE);
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (!success) {
|
2010-11-04 18:16:39 +01:00
|
|
|
printf("Error reading SHT11\n");
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 1;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-11-06 00:55:05 +01:00
|
|
|
printf("Temperature: %-6.2f°C\n", (double) sht11_val.temperature);
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 0;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-21 16:24:47 +01:00
|
|
|
|
2015-03-20 08:51:45 +01:00
|
|
|
int _get_weather_handler(int argc, char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-02-21 19:10:24 +01:00
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
|
2010-11-04 18:16:39 +01:00
|
|
|
uint8_t success;
|
|
|
|
sht11_val_t sht11_val;
|
2013-06-22 05:11:53 +02:00
|
|
|
success = sht11_read_sensor(&sht11_val, HUMIDITY | TEMPERATURE);
|
|
|
|
|
2013-06-24 22:37:35 +02:00
|
|
|
if (!success) {
|
2010-11-04 18:16:39 +01:00
|
|
|
printf("Error reading SHT11\n");
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 1;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("Relative humidity: %5.2f%% / Temperature compensated humidity; %5.2f%% ",
|
2013-06-22 05:11:53 +02:00
|
|
|
(double) sht11_val.relhum, (double) sht11_val.relhum_temp);
|
2012-11-06 00:55:05 +01:00
|
|
|
printf("Temperature: %-6.2f°C\n", (double) sht11_val.temperature);
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 0;
|
2010-11-04 18:16:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 08:51:45 +01:00
|
|
|
int _set_offset_handler(int argc, char **argv)
|
2013-06-22 05:11:53 +02:00
|
|
|
{
|
2014-02-21 19:10:24 +01:00
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s <OFFSET>\n", argv[0]);
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 1;
|
2013-06-22 05:11:53 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-02-21 19:10:24 +01:00
|
|
|
sht11_temperature_offset = atoi(argv[1]);
|
2013-06-22 05:11:53 +02:00
|
|
|
printf("Temperature offset set to %f\n", (double) sht11_temperature_offset);
|
2015-03-20 08:51:45 +01:00
|
|
|
|
|
|
|
return 0;
|
2013-06-22 05:11:53 +02:00
|
|
|
}
|
2010-11-07 23:18:41 +01:00
|
|
|
}
|
2010-12-03 22:22:58 +01:00
|
|
|
|
|
|
|
#endif
|