Merge pull request #986 from g-oikonomou/cc26xx-hdc-sensor
Replace STH21 with HDC1000 for the CC2650 SensorTag
This commit is contained in:
commit
b50ae639b3
|
@ -143,11 +143,11 @@ AUTOSTART_PROCESSES(&cc26xx_demo_process);
|
||||||
#define SENSOR_READING_PERIOD (CLOCK_SECOND * 20)
|
#define SENSOR_READING_PERIOD (CLOCK_SECOND * 20)
|
||||||
#define SENSOR_READING_RANDOM (CLOCK_SECOND << 4)
|
#define SENSOR_READING_RANDOM (CLOCK_SECOND << 4)
|
||||||
|
|
||||||
static struct ctimer bmp_timer, opt_timer, sht_timer, tmp_timer, mpu_timer;
|
static struct ctimer bmp_timer, opt_timer, hdc_timer, tmp_timer, mpu_timer;
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void init_bmp_reading(void *not_used);
|
static void init_bmp_reading(void *not_used);
|
||||||
static void init_opt_reading(void *not_used);
|
static void init_opt_reading(void *not_used);
|
||||||
static void init_sht_reading(void *not_used);
|
static void init_hdc_reading(void *not_used);
|
||||||
static void init_tmp_reading(void *not_used);
|
static void init_tmp_reading(void *not_used);
|
||||||
static void init_mpu_reading(void *not_used);
|
static void init_mpu_reading(void *not_used);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -214,27 +214,27 @@ get_tmp_reading()
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
get_sht_reading()
|
get_hdc_reading()
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
clock_time_t next = SENSOR_READING_PERIOD +
|
clock_time_t next = SENSOR_READING_PERIOD +
|
||||||
(random_rand() % SENSOR_READING_RANDOM);
|
(random_rand() % SENSOR_READING_RANDOM);
|
||||||
|
|
||||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_TEMP);
|
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP);
|
||||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||||
printf("SHT: Temp=%d.%02d C\n", value / 100, value % 100);
|
printf("HDC: Temp=%d.%02d C\n", value / 100, value % 100);
|
||||||
} else {
|
} else {
|
||||||
printf("SHT: Temp Read Error\n");
|
printf("HDC: Temp Read Error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_HUMIDITY);
|
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY);
|
||||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||||
printf("SHT: Humidity=%d.%02d %%RH\n", value / 100, value % 100);
|
printf("HDC: Humidity=%d.%02d %%RH\n", value / 100, value % 100);
|
||||||
} else {
|
} else {
|
||||||
printf("SHT: Humidity Read Error\n");
|
printf("HDC: Humidity Read Error\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctimer_set(&sht_timer, next, init_sht_reading, NULL);
|
ctimer_set(&hdc_timer, next, init_hdc_reading, NULL);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -311,9 +311,9 @@ init_opt_reading(void *not_used)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
init_sht_reading(void *not_used)
|
init_hdc_reading(void *not_used)
|
||||||
{
|
{
|
||||||
SENSORS_ACTIVATE(sht_21_sensor);
|
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -360,7 +360,7 @@ static void
|
||||||
init_sensor_readings(void)
|
init_sensor_readings(void)
|
||||||
{
|
{
|
||||||
#if BOARD_SENSORTAG
|
#if BOARD_SENSORTAG
|
||||||
SENSORS_ACTIVATE(sht_21_sensor);
|
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||||
SENSORS_ACTIVATE(tmp_007_sensor);
|
SENSORS_ACTIVATE(tmp_007_sensor);
|
||||||
SENSORS_ACTIVATE(opt_3001_sensor);
|
SENSORS_ACTIVATE(opt_3001_sensor);
|
||||||
SENSORS_ACTIVATE(bmp_280_sensor);
|
SENSORS_ACTIVATE(bmp_280_sensor);
|
||||||
|
@ -450,8 +450,8 @@ PROCESS_THREAD(cc26xx_demo_process, ev, data)
|
||||||
get_bmp_reading();
|
get_bmp_reading();
|
||||||
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
||||||
get_light_reading();
|
get_light_reading();
|
||||||
} else if(ev == sensors_event && data == &sht_21_sensor) {
|
} else if(ev == sensors_event && data == &hdc_1000_sensor) {
|
||||||
get_sht_reading();
|
get_hdc_reading();
|
||||||
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
||||||
get_tmp_reading();
|
get_tmp_reading();
|
||||||
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ PROCESS(cc26xx_web_demo_process, "CC26XX Web Demo");
|
||||||
struct ctimer batmon_timer;
|
struct ctimer batmon_timer;
|
||||||
|
|
||||||
#if BOARD_SENSORTAG
|
#if BOARD_SENSORTAG
|
||||||
struct ctimer bmp_timer, sht_timer, tmp_timer, opt_timer, mpu_timer;
|
struct ctimer bmp_timer, hdc_timer, tmp_timer, opt_timer, mpu_timer;
|
||||||
#endif
|
#endif
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Provide visible feedback via LEDS while searching for a network */
|
/* Provide visible feedback via LEDS while searching for a network */
|
||||||
|
@ -111,11 +111,11 @@ DEMO_SENSOR(bmp_pres, CC26XX_WEB_DEMO_SENSOR_BMP_PRES,
|
||||||
DEMO_SENSOR(bmp_temp, CC26XX_WEB_DEMO_SENSOR_BMP_TEMP,
|
DEMO_SENSOR(bmp_temp, CC26XX_WEB_DEMO_SENSOR_BMP_TEMP,
|
||||||
"Air Temp", "air-temp", "bmp_temp",
|
"Air Temp", "air-temp", "bmp_temp",
|
||||||
CC26XX_WEB_DEMO_UNIT_TEMP);
|
CC26XX_WEB_DEMO_UNIT_TEMP);
|
||||||
DEMO_SENSOR(sht_temp, CC26XX_WEB_DEMO_SENSOR_SHT_TEMP,
|
DEMO_SENSOR(hdc_temp, CC26XX_WEB_DEMO_SENSOR_HDC_TEMP,
|
||||||
"SHT Temp", "sht-temp", "sht_temp",
|
"HDC Temp", "hdc-temp", "hdc_temp",
|
||||||
CC26XX_WEB_DEMO_UNIT_TEMP);
|
CC26XX_WEB_DEMO_UNIT_TEMP);
|
||||||
DEMO_SENSOR(sht_hum, CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY,
|
DEMO_SENSOR(hdc_hum, CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY,
|
||||||
"SHT Humidity", "sht-humidity", "sht_hum",
|
"HDC Humidity", "hdc-humidity", "hdc_hum",
|
||||||
CC26XX_WEB_DEMO_UNIT_HUMIDITY);
|
CC26XX_WEB_DEMO_UNIT_HUMIDITY);
|
||||||
DEMO_SENSOR(tmp_amb, CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT,
|
DEMO_SENSOR(tmp_amb, CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT,
|
||||||
"Ambient Temp", "ambient-temp", "tmp_amb",
|
"Ambient Temp", "ambient-temp", "tmp_amb",
|
||||||
|
@ -152,7 +152,7 @@ DEMO_SENSOR(mpu_gyro_z, CC26XX_WEB_DEMO_SENSOR_MPU_GYRO_Z,
|
||||||
#if BOARD_SENSORTAG
|
#if BOARD_SENSORTAG
|
||||||
static void init_bmp_reading(void *data);
|
static void init_bmp_reading(void *data);
|
||||||
static void init_light_reading(void *data);
|
static void init_light_reading(void *data);
|
||||||
static void init_sht_reading(void *data);
|
static void init_hdc_reading(void *data);
|
||||||
static void init_tmp_reading(void *data);
|
static void init_tmp_reading(void *data);
|
||||||
static void init_mpu_reading(void *data);
|
static void init_mpu_reading(void *data);
|
||||||
#endif
|
#endif
|
||||||
|
@ -526,42 +526,42 @@ get_tmp_reading()
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
get_sht_reading()
|
get_hdc_reading()
|
||||||
{
|
{
|
||||||
int value;
|
int value;
|
||||||
char *buf;
|
char *buf;
|
||||||
clock_time_t next = SENSOR_READING_PERIOD +
|
clock_time_t next = SENSOR_READING_PERIOD +
|
||||||
(random_rand() % SENSOR_READING_RANDOM);
|
(random_rand() % SENSOR_READING_RANDOM);
|
||||||
|
|
||||||
if(sht_temp_reading.publish) {
|
if(hdc_temp_reading.publish) {
|
||||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_TEMP);
|
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_TEMP);
|
||||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||||
sht_temp_reading.raw = value;
|
hdc_temp_reading.raw = value;
|
||||||
|
|
||||||
compare_and_update(&sht_temp_reading);
|
compare_and_update(&hdc_temp_reading);
|
||||||
|
|
||||||
buf = sht_temp_reading.converted;
|
buf = hdc_temp_reading.converted;
|
||||||
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
||||||
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
||||||
value % 100);
|
value % 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sht_hum_reading.publish) {
|
if(hdc_hum_reading.publish) {
|
||||||
value = sht_21_sensor.value(SHT_21_SENSOR_TYPE_HUMIDITY);
|
value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY);
|
||||||
if(value != CC26XX_SENSOR_READING_ERROR) {
|
if(value != CC26XX_SENSOR_READING_ERROR) {
|
||||||
sht_hum_reading.raw = value;
|
hdc_hum_reading.raw = value;
|
||||||
|
|
||||||
compare_and_update(&sht_hum_reading);
|
compare_and_update(&hdc_hum_reading);
|
||||||
|
|
||||||
buf = sht_hum_reading.converted;
|
buf = hdc_hum_reading.converted;
|
||||||
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
memset(buf, 0, CC26XX_WEB_DEMO_CONVERTED_LEN);
|
||||||
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d.%02d", value / 100,
|
||||||
value % 100);
|
value % 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctimer_set(&sht_timer, next, init_sht_reading, NULL);
|
ctimer_set(&hdc_timer, next, init_hdc_reading, NULL);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -702,12 +702,12 @@ init_bmp_reading(void *data)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
init_sht_reading(void *data)
|
init_hdc_reading(void *data)
|
||||||
{
|
{
|
||||||
if(sht_hum_reading.publish || sht_temp_reading.publish) {
|
if(hdc_hum_reading.publish || hdc_temp_reading.publish) {
|
||||||
SENSORS_ACTIVATE(sht_21_sensor);
|
SENSORS_ACTIVATE(hdc_1000_sensor);
|
||||||
} else {
|
} else {
|
||||||
ctimer_set(&sht_timer, CLOCK_SECOND, init_sht_reading, NULL);
|
ctimer_set(&hdc_timer, CLOCK_SECOND, init_hdc_reading, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -756,7 +756,7 @@ init_sensor_readings(void)
|
||||||
#if BOARD_SENSORTAG
|
#if BOARD_SENSORTAG
|
||||||
init_bmp_reading(NULL);
|
init_bmp_reading(NULL);
|
||||||
init_light_reading(NULL);
|
init_light_reading(NULL);
|
||||||
init_sht_reading(NULL);
|
init_hdc_reading(NULL);
|
||||||
init_tmp_reading(NULL);
|
init_tmp_reading(NULL);
|
||||||
init_mpu_reading(NULL);
|
init_mpu_reading(NULL);
|
||||||
#endif /* BOARD_SENSORTAG */
|
#endif /* BOARD_SENSORTAG */
|
||||||
|
@ -781,8 +781,8 @@ init_sensors(void)
|
||||||
|
|
||||||
list_add(sensor_list, &opt_reading);
|
list_add(sensor_list, &opt_reading);
|
||||||
|
|
||||||
list_add(sensor_list, &sht_hum_reading);
|
list_add(sensor_list, &hdc_hum_reading);
|
||||||
list_add(sensor_list, &sht_temp_reading);
|
list_add(sensor_list, &hdc_temp_reading);
|
||||||
|
|
||||||
list_add(sensor_list, &mpu_acc_x_reading);
|
list_add(sensor_list, &mpu_acc_x_reading);
|
||||||
list_add(sensor_list, &mpu_acc_y_reading);
|
list_add(sensor_list, &mpu_acc_y_reading);
|
||||||
|
@ -873,8 +873,8 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
|
||||||
get_bmp_reading();
|
get_bmp_reading();
|
||||||
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
||||||
get_light_reading();
|
get_light_reading();
|
||||||
} else if(ev == sensors_event && data == &sht_21_sensor) {
|
} else if(ev == sensors_event && data == &hdc_1000_sensor) {
|
||||||
get_sht_reading();
|
get_hdc_reading();
|
||||||
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
||||||
get_tmp_reading();
|
get_tmp_reading();
|
||||||
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
||||||
|
|
|
@ -121,8 +121,8 @@
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_BMP_TEMP 3
|
#define CC26XX_WEB_DEMO_SENSOR_BMP_TEMP 3
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT 4
|
#define CC26XX_WEB_DEMO_SENSOR_TMP_AMBIENT 4
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_TMP_OBJECT 5
|
#define CC26XX_WEB_DEMO_SENSOR_TMP_OBJECT 5
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_SHT_TEMP 6
|
#define CC26XX_WEB_DEMO_SENSOR_HDC_TEMP 6
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY 7
|
#define CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY 7
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_OPT_LIGHT 8
|
#define CC26XX_WEB_DEMO_SENSOR_OPT_LIGHT 8
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_X 9
|
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_X 9
|
||||||
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_Y 10
|
#define CC26XX_WEB_DEMO_SENSOR_MPU_ACC_Y 10
|
||||||
|
|
|
@ -66,8 +66,8 @@ extern resource_t res_bmp280_temp;
|
||||||
extern resource_t res_bmp280_press;
|
extern resource_t res_bmp280_press;
|
||||||
extern resource_t res_tmp007_amb;
|
extern resource_t res_tmp007_amb;
|
||||||
extern resource_t res_tmp007_obj;
|
extern resource_t res_tmp007_obj;
|
||||||
extern resource_t res_sht21_temp;
|
extern resource_t res_hdc1000_temp;
|
||||||
extern resource_t res_sht21_hum;
|
extern resource_t res_hdc1000_hum;
|
||||||
extern resource_t res_opt3001_light;
|
extern resource_t res_opt3001_light;
|
||||||
extern resource_t res_mpu_acc_x;
|
extern resource_t res_mpu_acc_x;
|
||||||
extern resource_t res_mpu_acc_y;
|
extern resource_t res_mpu_acc_y;
|
||||||
|
@ -98,8 +98,8 @@ start_board_resources(void)
|
||||||
rest_activate_resource(&res_bmp280_press, "sen/bar/pres");
|
rest_activate_resource(&res_bmp280_press, "sen/bar/pres");
|
||||||
rest_activate_resource(&res_tmp007_amb, "sen/tmp/amb");
|
rest_activate_resource(&res_tmp007_amb, "sen/tmp/amb");
|
||||||
rest_activate_resource(&res_tmp007_obj, "sen/tmp/obj");
|
rest_activate_resource(&res_tmp007_obj, "sen/tmp/obj");
|
||||||
rest_activate_resource(&res_sht21_temp, "sen/sht/t");
|
rest_activate_resource(&res_hdc1000_temp, "sen/hdc/t");
|
||||||
rest_activate_resource(&res_sht21_hum, "sen/sht/h");
|
rest_activate_resource(&res_hdc1000_hum, "sen/hdc/h");
|
||||||
rest_activate_resource(&res_opt3001_light, "sen/opt/light");
|
rest_activate_resource(&res_opt3001_light, "sen/opt/light");
|
||||||
rest_activate_resource(&res_mpu_acc_x, "sen/mpu/acc/x");
|
rest_activate_resource(&res_mpu_acc_x, "sen/mpu/acc/x");
|
||||||
rest_activate_resource(&res_mpu_acc_y, "sen/mpu/acc/y");
|
rest_activate_resource(&res_mpu_acc_y, "sen/mpu/acc/y");
|
||||||
|
|
|
@ -229,28 +229,28 @@ RESOURCE(res_bmp280_press,
|
||||||
"title=\"Barometer (Pressure)\";rt=\"hPa (hectopascal / millibar)\"",
|
"title=\"Barometer (Pressure)\";rt=\"hPa (hectopascal / millibar)\"",
|
||||||
res_get_handler_bmp_press, NULL, NULL, NULL);
|
res_get_handler_bmp_press, NULL, NULL, NULL);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* SHT21 sensor resources and handler: Temperature, Pressure */
|
/* HDC1000 sensor resources and handler: Temperature, Pressure */
|
||||||
static void
|
static void
|
||||||
res_get_handler_sht_temp(void *request, void *response, uint8_t *buffer,
|
res_get_handler_hdc_temp(void *request, void *response, uint8_t *buffer,
|
||||||
uint16_t preferred_size, int32_t *offset)
|
uint16_t preferred_size, int32_t *offset)
|
||||||
{
|
{
|
||||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_SHT_TEMP, request, response,
|
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_HDC_TEMP, request, response,
|
||||||
buffer, preferred_size, offset);
|
buffer, preferred_size, offset);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
res_get_handler_sht_humidity(void *request, void *response, uint8_t *buffer,
|
res_get_handler_hdc_humidity(void *request, void *response, uint8_t *buffer,
|
||||||
uint16_t preferred_size, int32_t *offset)
|
uint16_t preferred_size, int32_t *offset)
|
||||||
{
|
{
|
||||||
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_SHT_HUMIDITY, request, response,
|
res_get_handler_all(CC26XX_WEB_DEMO_SENSOR_HDC_HUMIDITY, request, response,
|
||||||
buffer, preferred_size, offset);
|
buffer, preferred_size, offset);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
RESOURCE(res_sht21_temp, "title=\"Temperature\";rt=\"C\"",
|
RESOURCE(res_hdc1000_temp, "title=\"Temperature\";rt=\"C\"",
|
||||||
res_get_handler_sht_temp, NULL, NULL, NULL);
|
res_get_handler_hdc_temp, NULL, NULL, NULL);
|
||||||
|
|
||||||
RESOURCE(res_sht21_hum, "title=\"Humidity\";rt=\"%RH\"",
|
RESOURCE(res_hdc1000_hum, "title=\"Humidity\";rt=\"%RH\"",
|
||||||
res_get_handler_sht_humidity, NULL, NULL, NULL);
|
res_get_handler_hdc_humidity, NULL, NULL, NULL);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Illuminance resources and handler */
|
/* Illuminance resources and handler */
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -39,7 +39,7 @@ In terms of hardware support, the following drivers have been implemented:
|
||||||
* Motion Processing Unit (MPU9250 - Accelerometer, Gyro)
|
* Motion Processing Unit (MPU9250 - Accelerometer, Gyro)
|
||||||
* BMP280 sensor
|
* BMP280 sensor
|
||||||
* TMP007 sensor
|
* TMP007 sensor
|
||||||
* SHT21 sensor
|
* HDC1000 sensor
|
||||||
* OPT3001 sensor
|
* OPT3001 sensor
|
||||||
* Buzzer
|
* Buzzer
|
||||||
* External SPI flash
|
* External SPI flash
|
||||||
|
|
|
@ -3,6 +3,6 @@ CFLAGS += -DBACKDOOR_IOID=0x00000000
|
||||||
|
|
||||||
BOARD_SOURCEFILES += leds-arch.c sensortag-sensors.c sensor-common.c
|
BOARD_SOURCEFILES += leds-arch.c sensortag-sensors.c sensor-common.c
|
||||||
BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c
|
BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c
|
||||||
BOARD_SOURCEFILES += sht-21-sensor.c mpu-9250-sensor.c button-sensor.c
|
BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c button-sensor.c
|
||||||
BOARD_SOURCEFILES += reed-relay.c ext-flash.c buzzer.c
|
BOARD_SOURCEFILES += reed-relay.c ext-flash.c buzzer.c
|
||||||
BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c
|
BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
#include "bmp-280-sensor.h"
|
#include "bmp-280-sensor.h"
|
||||||
#include "tmp-007-sensor.h"
|
#include "tmp-007-sensor.h"
|
||||||
#include "opt-3001-sensor.h"
|
#include "opt-3001-sensor.h"
|
||||||
#include "sht-21-sensor.h"
|
#include "hdc-1000-sensor.h"
|
||||||
#include "mpu-9250-sensor.h"
|
#include "mpu-9250-sensor.h"
|
||||||
#include "reed-relay.h"
|
#include "reed-relay.h"
|
||||||
#include "buzzer.h"
|
#include "buzzer.h"
|
||||||
|
|
|
@ -76,7 +76,7 @@ shutdown_handler(uint8_t mode)
|
||||||
SENSORS_DEACTIVATE(bmp_280_sensor);
|
SENSORS_DEACTIVATE(bmp_280_sensor);
|
||||||
SENSORS_DEACTIVATE(opt_3001_sensor);
|
SENSORS_DEACTIVATE(opt_3001_sensor);
|
||||||
SENSORS_DEACTIVATE(tmp_007_sensor);
|
SENSORS_DEACTIVATE(tmp_007_sensor);
|
||||||
SENSORS_DEACTIVATE(sht_21_sensor);
|
SENSORS_DEACTIVATE(hdc_1000_sensor);
|
||||||
mpu_9250_sensor.configure(MPU_9250_SENSOR_SHUTDOWN, 0);
|
mpu_9250_sensor.configure(MPU_9250_SENSOR_SHUTDOWN, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
304
platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c
Normal file
304
platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c
Normal file
|
@ -0,0 +1,304 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \addtogroup sensortag-cc26xx-hdc-sensor
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \file
|
||||||
|
* Driver for the Sensortag-CC26xx HDC sensor
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#include "contiki-conf.h"
|
||||||
|
#include "sys/ctimer.h"
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "hdc-1000-sensor.h"
|
||||||
|
#include "sensor-common.h"
|
||||||
|
#include "board-i2c.h"
|
||||||
|
|
||||||
|
#include "ti-lib.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define DEBUG 0
|
||||||
|
#if DEBUG
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PRINTF(...)
|
||||||
|
#endif
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Sensor I2C address */
|
||||||
|
#define SENSOR_I2C_ADDRESS 0x43
|
||||||
|
|
||||||
|
/* Registers */
|
||||||
|
#define HDC1000_REG_TEMP 0x00 /* Temperature */
|
||||||
|
#define HDC1000_REG_HUM 0x01 /* Humidity */
|
||||||
|
#define HDC1000_REG_CONFIG 0x02 /* Configuration */
|
||||||
|
#define HDC1000_REG_SERID_H 0xFB /* Serial ID high */
|
||||||
|
#define HDC1000_REG_SERID_M 0xFC /* Serial ID middle */
|
||||||
|
#define HDC1000_REG_SERID_L 0xFD /* Serial ID low */
|
||||||
|
#define HDC1000_REG_MANF_ID 0xFE /* Manufacturer ID */
|
||||||
|
#define HDC1000_REG_DEV_ID 0xFF /* Device ID */
|
||||||
|
|
||||||
|
/* Fixed values */
|
||||||
|
#define HDC1000_VAL_MANF_ID 0x5449
|
||||||
|
#define HDC1000_VAL_DEV_ID 0x1000
|
||||||
|
#define HDC1000_VAL_CONFIG 0x1000 /* 14 bit, acquired in sequence */
|
||||||
|
|
||||||
|
/* Sensor selection/deselection */
|
||||||
|
#define SENSOR_SELECT() board_i2c_select(BOARD_I2C_INTERFACE_0, SENSOR_I2C_ADDRESS)
|
||||||
|
#define SENSOR_DESELECT() board_i2c_deselect()
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Byte swap of 16-bit register value */
|
||||||
|
#define HI_UINT16(a) (((a) >> 8) & 0xFF)
|
||||||
|
#define LO_UINT16(a) ((a) & 0xFF)
|
||||||
|
|
||||||
|
#define SWAP(v) ((LO_UINT16(v) << 8) | HI_UINT16(v))
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/* Raw data as returned from the sensor (Big Endian) */
|
||||||
|
typedef struct sensor_data {
|
||||||
|
uint16_t temp;
|
||||||
|
uint16_t hum;
|
||||||
|
} sensor_data_t;
|
||||||
|
|
||||||
|
/* Raw data, little endian */
|
||||||
|
static uint16_t raw_temp;
|
||||||
|
static uint16_t raw_hum;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static bool success;
|
||||||
|
static sensor_data_t data;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int enabled = HDC_1000_SENSOR_STATUS_DISABLED;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* Maximum measurement durations in clock ticks. We use 14bit resolution, thus:
|
||||||
|
* - Tmp: 6.35ms
|
||||||
|
* - RH: 6.5ms
|
||||||
|
*/
|
||||||
|
#define MEASUREMENT_DURATION 2
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait SENSOR_STARTUP_DELAY clock ticks between activation and triggering a
|
||||||
|
* reading (max 15ms)
|
||||||
|
*/
|
||||||
|
#define SENSOR_STARTUP_DELAY 3
|
||||||
|
|
||||||
|
static struct ctimer startup_timer;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Initialise the humidity sensor driver
|
||||||
|
* \return True if I2C operation successful
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
sensor_init(void)
|
||||||
|
{
|
||||||
|
uint16_t val;
|
||||||
|
|
||||||
|
SENSOR_SELECT();
|
||||||
|
|
||||||
|
/* Enable reading data in one operation */
|
||||||
|
val = SWAP(HDC1000_VAL_CONFIG);
|
||||||
|
success = sensor_common_write_reg(HDC1000_REG_CONFIG, (uint8_t *)&val, 2);
|
||||||
|
|
||||||
|
SENSOR_DESELECT();
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Start measurement
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
start(void)
|
||||||
|
{
|
||||||
|
if(success) {
|
||||||
|
SENSOR_SELECT();
|
||||||
|
|
||||||
|
success = board_i2c_write_single(HDC1000_REG_TEMP);
|
||||||
|
SENSOR_DESELECT();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Take readings from the sensor
|
||||||
|
* \return true of I2C operations successful
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
read_data()
|
||||||
|
{
|
||||||
|
bool valid;
|
||||||
|
|
||||||
|
if(success) {
|
||||||
|
SENSOR_SELECT();
|
||||||
|
|
||||||
|
success = board_i2c_read((uint8_t *)&data, sizeof(data));
|
||||||
|
SENSOR_DESELECT();
|
||||||
|
|
||||||
|
/* Store temperature */
|
||||||
|
raw_temp = SWAP(data.temp);
|
||||||
|
|
||||||
|
/* Store humidity */
|
||||||
|
raw_hum = SWAP(data.hum);
|
||||||
|
}
|
||||||
|
|
||||||
|
valid = success;
|
||||||
|
success = true;
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Convert raw data to temperature and humidity
|
||||||
|
* \param temp - converted temperature
|
||||||
|
* \param hum - converted humidity
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
convert(float *temp, float *hum)
|
||||||
|
{
|
||||||
|
/* Convert temperature to degrees C */
|
||||||
|
*temp = ((double)(int16_t)raw_temp / 65536) * 165 - 40;
|
||||||
|
|
||||||
|
/* Convert relative humidity to a %RH value */
|
||||||
|
*hum = ((double)raw_hum / 65536) * 100;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
notify_ready(void *not_used)
|
||||||
|
{
|
||||||
|
enabled = HDC_1000_SENSOR_STATUS_READINGS_READY;
|
||||||
|
|
||||||
|
/* Latch readings */
|
||||||
|
read_data();
|
||||||
|
|
||||||
|
sensors_changed(&hdc_1000_sensor);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Returns a reading from the sensor
|
||||||
|
* \param type HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMIDITY
|
||||||
|
* \return Temperature (centi degrees C) or Humidity (centi %RH)
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
float temp;
|
||||||
|
float hum;
|
||||||
|
|
||||||
|
if(enabled != HDC_1000_SENSOR_STATUS_READINGS_READY) {
|
||||||
|
PRINTF("Sensor disabled or starting up (%d)\n", enabled);
|
||||||
|
return CC26XX_SENSOR_READING_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((type != HDC_1000_SENSOR_TYPE_TEMP) &&
|
||||||
|
type != HDC_1000_SENSOR_TYPE_HUMIDITY) {
|
||||||
|
PRINTF("Invalid type\n");
|
||||||
|
return CC26XX_SENSOR_READING_ERROR;
|
||||||
|
} else {
|
||||||
|
convert(&temp, &hum);
|
||||||
|
PRINTF("HDC: %04X %04X t=%d h=%d\n", raw_temp, raw_hum,
|
||||||
|
(int)(temp * 100), (int)(hum * 100));
|
||||||
|
|
||||||
|
if(type == HDC_1000_SENSOR_TYPE_TEMP) {
|
||||||
|
rv = (int)(temp * 100);
|
||||||
|
} else if(type == HDC_1000_SENSOR_TYPE_HUMIDITY) {
|
||||||
|
rv = (int)(hum * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Configuration function for the HDC1000 sensor.
|
||||||
|
*
|
||||||
|
* \param type Activate, enable or disable the sensor. See below
|
||||||
|
* \param enable
|
||||||
|
*
|
||||||
|
* When type == SENSORS_HW_INIT we turn on the hardware
|
||||||
|
* When type == SENSORS_ACTIVE and enable==1 we enable the sensor
|
||||||
|
* When type == SENSORS_ACTIVE and enable==0 we disable the sensor
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
configure(int type, int enable)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_HW_INIT:
|
||||||
|
raw_temp = 0;
|
||||||
|
raw_hum = 0;
|
||||||
|
memset(&data, 0, sizeof(data));
|
||||||
|
|
||||||
|
sensor_init();
|
||||||
|
enabled = HDC_1000_SENSOR_STATUS_INITIALISED;
|
||||||
|
break;
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
/* Must be initialised first */
|
||||||
|
if(enabled == HDC_1000_SENSOR_STATUS_DISABLED) {
|
||||||
|
return HDC_1000_SENSOR_STATUS_DISABLED;
|
||||||
|
}
|
||||||
|
if(enable) {
|
||||||
|
start();
|
||||||
|
ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
|
||||||
|
enabled = HDC_1000_SENSOR_STATUS_TAKING_READINGS;
|
||||||
|
} else {
|
||||||
|
ctimer_stop(&startup_timer);
|
||||||
|
enabled = HDC_1000_SENSOR_STATUS_INITIALISED;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \brief Returns the status of the sensor
|
||||||
|
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||||
|
* \return One of the SENSOR_STATUS_xyz defines
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return HDC_1000_SENSOR_STATUS_DISABLED;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
SENSORS_SENSOR(hdc_1000_sensor, "HDC1000", value, configure, status);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/** @} */
|
116
platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h
Executable file
116
platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h
Executable file
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the copyright holder nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||||
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \addtogroup sensortag-cc26xx-peripherals
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \defgroup sensortag-cc26xx-hdc-sensor SensorTag 2.0 TI HDC1000 Sensor
|
||||||
|
*
|
||||||
|
* Due to the time required for the sensor to startup, this driver is meant to
|
||||||
|
* be used in an asynchronous fashion. The caller must first activate the
|
||||||
|
* sensor by calling SENSORS_ACTIVATE(). This will trigger the sensor's startup
|
||||||
|
* sequence, but the call will not wait for it to complete so that the CPU can
|
||||||
|
* perform other tasks or drop to a low power mode. Once the sensor has taken
|
||||||
|
* readings, it will automatically go back to low power mode.
|
||||||
|
*
|
||||||
|
* Once the sensor is stable, the driver will retrieve readings from the sensor
|
||||||
|
* and latch them. It will then generate a sensors_changed event.
|
||||||
|
*
|
||||||
|
* The user can then retrieve readings by calling .value() and by passing
|
||||||
|
* either HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMIDITY as the
|
||||||
|
* argument. Multiple calls to value() will not trigger new readings, they will
|
||||||
|
* simply return the most recent latched values.
|
||||||
|
*
|
||||||
|
* The user can query the sensor's status by calling .status()
|
||||||
|
*
|
||||||
|
* To get a fresh reading, the user must trigger a new reading cycle by calling
|
||||||
|
* SENSORS_ACTIVATE().
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* \file
|
||||||
|
* Header file for the Sensortag-CC26ss TI HDC1000 sensor
|
||||||
|
*/
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#ifndef HDC_1000_SENSOR_H
|
||||||
|
#define HDC_1000_SENSOR_H
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#define HDC_1000_SENSOR_TYPE_TEMP 1
|
||||||
|
#define HDC_1000_SENSOR_TYPE_HUMIDITY 2
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* \name HDC1000 driver states
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HDC_1000_SENSOR_STATUS_DISABLED 0 /**< Not initialised */
|
||||||
|
#define HDC_1000_SENSOR_STATUS_INITIALISED 1 /**< Initialised but idle */
|
||||||
|
#define HDC_1000_SENSOR_STATUS_TAKING_READINGS 2 /**< Readings in progress */
|
||||||
|
#define HDC_1000_SENSOR_STATUS_READINGS_READY 3 /**< Both readings ready */
|
||||||
|
/** @} */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
extern const struct sensors_sensor hdc_1000_sensor;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#endif /* HDC_1000_SENSOR_H */
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
|
@ -41,7 +41,7 @@
|
||||||
#include "sensortag/bmp-280-sensor.h"
|
#include "sensortag/bmp-280-sensor.h"
|
||||||
#include "sensortag/tmp-007-sensor.h"
|
#include "sensortag/tmp-007-sensor.h"
|
||||||
#include "sensortag/opt-3001-sensor.h"
|
#include "sensortag/opt-3001-sensor.h"
|
||||||
#include "sensortag/sht-21-sensor.h"
|
#include "sensortag/hdc-1000-sensor.h"
|
||||||
#include "sensortag/mpu-9250-sensor.h"
|
#include "sensortag/mpu-9250-sensor.h"
|
||||||
#include "sensortag/reed-relay.h"
|
#include "sensortag/reed-relay.h"
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \brief Exports a global symbol to be used by the sensor API */
|
/** \brief Exports a global symbol to be used by the sensor API */
|
||||||
SENSORS(&button_left_sensor, &button_right_sensor,
|
SENSORS(&button_left_sensor, &button_right_sensor,
|
||||||
&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &sht_21_sensor,
|
&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor,
|
||||||
&mpu_9250_sensor, &reed_relay_sensor);
|
&mpu_9250_sensor, &reed_relay_sensor);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -1,386 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \addtogroup sensortag-cc26xx-sht-sensor
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* Driver for the Sensortag-CC26xx Sensirion SHT21 Humidity sensor
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#include "contiki-conf.h"
|
|
||||||
#include "sys/ctimer.h"
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "sht-21-sensor.h"
|
|
||||||
#include "sensor-common.h"
|
|
||||||
#include "board-i2c.h"
|
|
||||||
|
|
||||||
#include "ti-lib.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define DEBUG 0
|
|
||||||
#if DEBUG
|
|
||||||
#define PRINTF(...) printf(__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define PRINTF(...)
|
|
||||||
#endif
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Sensor I2C address */
|
|
||||||
#define HAL_SHT21_I2C_ADDRESS 0x40
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define S_REG_LEN 2
|
|
||||||
#define DATA_LEN 3
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Internal commands */
|
|
||||||
#define SHT21_CMD_TEMP_T_NH 0xF3 /* command trig. temp meas. no hold master */
|
|
||||||
#define SHT21_CMD_HUMI_T_NH 0xF5 /* command trig. humidity meas. no hold master */
|
|
||||||
#define SHT21_CMD_WRITE_U_R 0xE6 /* command write user register */
|
|
||||||
#define SHT21_CMD_READ_U_R 0xE7 /* command read user register */
|
|
||||||
#define SHT21_CMD_SOFT_RST 0xFE /* command soft reset */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define HUMIDITY 0x00
|
|
||||||
#define TEMPERATURE 0x01
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define USR_REG_MASK 0x38 /* Mask off reserved bits (3,4,5) */
|
|
||||||
#define USR_REG_DEFAULT 0x02 /* Disable OTP reload */
|
|
||||||
#define USR_REG_RES_MASK 0x7E /* Only change bits 0 and 7 (meas. res.) */
|
|
||||||
#define USR_REG_11BITRES 0x81 /* 11-bit resolution */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define USR_REG_TEST_VAL 0x83
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define DATA_SIZE 6
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static uint8_t usr; /* User register value */
|
|
||||||
static uint8_t buf[DATA_SIZE]; /* Data buffer */
|
|
||||||
static bool success;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int enabled = SHT_21_SENSOR_STATUS_DISABLED;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/*
|
|
||||||
* Maximum measurement durations in clock ticks. We use 11bit resolution, thus:
|
|
||||||
* - Tmp: 11ms
|
|
||||||
* - RH: 15ms
|
|
||||||
*/
|
|
||||||
#define MEASUREMENT_DURATION 3
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Wait SENSOR_STARTUP_DELAY clock ticks between activation and triggering a
|
|
||||||
* reading
|
|
||||||
*/
|
|
||||||
#define SENSOR_STARTUP_DELAY 4
|
|
||||||
|
|
||||||
static struct ctimer startup_timer;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Select the SHT sensor on the I2C-bus
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
select(void)
|
|
||||||
{
|
|
||||||
/* Select the SHT21 address */
|
|
||||||
board_i2c_select(BOARD_I2C_INTERFACE_0, HAL_SHT21_I2C_ADDRESS);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Write a command over I2C
|
|
||||||
* \param cmd The command to send
|
|
||||||
* \return TRUE if the command was sent successfully
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
write_cmd(uint8_t cmd)
|
|
||||||
{
|
|
||||||
/* Send command */
|
|
||||||
return board_i2c_write_single(cmd);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/*
|
|
||||||
* \brief Read data from the SHT over I2C
|
|
||||||
* \param buf Pointer to buffer where data will be stored
|
|
||||||
* \param len Number of bytes to read
|
|
||||||
* \return TRUE if the required number of bytes were received
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
read_data(uint8_t *buf, uint8_t len)
|
|
||||||
{
|
|
||||||
/* Read data */
|
|
||||||
return board_i2c_read(buf, len);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* @brief Initialise the SHT21 sensor
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
sensor_init(void)
|
|
||||||
{
|
|
||||||
select();
|
|
||||||
|
|
||||||
/* Set 11 bit resolution */
|
|
||||||
sensor_common_read_reg(SHT21_CMD_READ_U_R, &usr, 1);
|
|
||||||
usr &= USR_REG_RES_MASK;
|
|
||||||
usr |= USR_REG_11BITRES;
|
|
||||||
sensor_common_write_reg(SHT21_CMD_WRITE_U_R, &usr, 1);
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Start a temperature measurement
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
start_temp(void)
|
|
||||||
{
|
|
||||||
if(success) {
|
|
||||||
select();
|
|
||||||
success = write_cmd(SHT21_CMD_TEMP_T_NH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Latch the last temperature measurement
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
latch_temp(void)
|
|
||||||
{
|
|
||||||
if(success) {
|
|
||||||
select();
|
|
||||||
success = read_data(buf, DATA_LEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Start a humidity measurement
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
start_humidity(void)
|
|
||||||
{
|
|
||||||
if(success) {
|
|
||||||
select();
|
|
||||||
success = write_cmd(SHT21_CMD_HUMI_T_NH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Latch the last humidity measurement
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
latch_humidity(void)
|
|
||||||
{
|
|
||||||
if(success) {
|
|
||||||
select();
|
|
||||||
success = read_data(buf + DATA_LEN, DATA_LEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Retrieve latched raw readings from buffer and store in variables
|
|
||||||
* \param raw_temp Pointer to a buffer where the temperature reading will be
|
|
||||||
* stored
|
|
||||||
* \param raw_hum Pointer to a buffer where the humidity reading will be
|
|
||||||
* stored
|
|
||||||
* \return TRUE on success
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
get_readings(uint16_t *raw_temp, uint16_t *raw_hum)
|
|
||||||
{
|
|
||||||
bool valid;
|
|
||||||
|
|
||||||
valid = success;
|
|
||||||
if(!success) {
|
|
||||||
sensor_common_set_error_data(buf, DATA_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Store temperature */
|
|
||||||
*raw_temp = buf[0] << 8 | buf[1];
|
|
||||||
|
|
||||||
/* [2] We ignore the CRC */
|
|
||||||
|
|
||||||
/* Store humidity */
|
|
||||||
*raw_hum = buf[3] << 8 | buf[4];
|
|
||||||
|
|
||||||
/* [5] We ignore the CRC */
|
|
||||||
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Convert raw data to temperature (degrees C) and rel. humidity (%RH)
|
|
||||||
* \param raw_temp Raw temperature data (little endian)
|
|
||||||
* \param raw_hum Raw humidity data (little endian)
|
|
||||||
* \param temp Converted temperature value
|
|
||||||
* \param hum Converted humidity value
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
convert(uint16_t raw_temp, uint16_t raw_hum, float *temp, float *hum)
|
|
||||||
{
|
|
||||||
/* Convert temperature to degrees C */
|
|
||||||
raw_temp &= ~0x0003; /* clear bits [1..0] (status bits) */
|
|
||||||
*temp = -46.85 + 175.72 / 65536 * (double)(int16_t)raw_temp;
|
|
||||||
|
|
||||||
/* Convert relative humidity to a %RH value */
|
|
||||||
raw_hum &= ~0x0003; /* clear bits [1..0] (status bits) */
|
|
||||||
|
|
||||||
/* RH= -6 + 125 * SRH / 2^16 */
|
|
||||||
*hum = -6.0 + 125.0 / 65536 * (double)raw_hum;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void
|
|
||||||
state_machine(void *not_used)
|
|
||||||
{
|
|
||||||
switch(enabled) {
|
|
||||||
case SHT_21_SENSOR_STATUS_INITIALISED:
|
|
||||||
start_temp();
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_READING_TEMP;
|
|
||||||
break;
|
|
||||||
case SHT_21_SENSOR_STATUS_READING_TEMP:
|
|
||||||
latch_temp();
|
|
||||||
start_humidity();
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_READING_HUMIDITY;
|
|
||||||
break;
|
|
||||||
case SHT_21_SENSOR_STATUS_READING_HUMIDITY:
|
|
||||||
latch_humidity();
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_READINGS_READY;
|
|
||||||
sensors_changed(&sht_21_sensor);
|
|
||||||
return;
|
|
||||||
case SHT_21_SENSOR_STATUS_READINGS_READY:
|
|
||||||
case SHT_21_SENSOR_STATUS_DISABLED:
|
|
||||||
default:
|
|
||||||
ctimer_stop(&startup_timer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctimer_set(&startup_timer, MEASUREMENT_DURATION, state_machine, NULL);
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Returns a reading from the sensor
|
|
||||||
* \param type SHT_21_SENSOR_TYPE_TEMP or SHT_21_SENSOR_TYPE_HUMIDITY
|
|
||||||
* \return Temperature (centi degrees C) or Humidity (centi %RH)
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
value(int type)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
uint16_t raw_temp;
|
|
||||||
uint16_t raw_hum;
|
|
||||||
float temp;
|
|
||||||
float hum;
|
|
||||||
|
|
||||||
if(enabled != SHT_21_SENSOR_STATUS_READINGS_READY) {
|
|
||||||
PRINTF("Sensor disabled or starting up (%d)\n", enabled);
|
|
||||||
return CC26XX_SENSOR_READING_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((type != SHT_21_SENSOR_TYPE_TEMP) && type != SHT_21_SENSOR_TYPE_HUMIDITY) {
|
|
||||||
PRINTF("Invalid type\n");
|
|
||||||
return CC26XX_SENSOR_READING_ERROR;
|
|
||||||
} else {
|
|
||||||
rv = get_readings(&raw_temp, &raw_hum);
|
|
||||||
|
|
||||||
if(rv == 0) {
|
|
||||||
return CC26XX_SENSOR_READING_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
convert(raw_temp, raw_hum, &temp, &hum);
|
|
||||||
PRINTF("SHT: %04X %04X t=%d h=%d\n", raw_temp, raw_hum,
|
|
||||||
(int)(temp * 100), (int)(hum * 100));
|
|
||||||
|
|
||||||
if(type == SHT_21_SENSOR_TYPE_TEMP) {
|
|
||||||
rv = (int)(temp * 100);
|
|
||||||
} else if(type == SHT_21_SENSOR_TYPE_HUMIDITY) {
|
|
||||||
rv = (int)(hum * 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Configuration function for the SHT21 sensor.
|
|
||||||
*
|
|
||||||
* \param type Activate, enable or disable the sensor. See below
|
|
||||||
* \param enable
|
|
||||||
*
|
|
||||||
* When type == SENSORS_HW_INIT we turn on the hardware
|
|
||||||
* When type == SENSORS_ACTIVE and enable==1 we enable the sensor
|
|
||||||
* When type == SENSORS_ACTIVE and enable==0 we disable the sensor
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
configure(int type, int enable)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case SENSORS_HW_INIT:
|
|
||||||
sensor_init();
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_INITIALISED;
|
|
||||||
break;
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
/* Must be initialised first */
|
|
||||||
if(enabled == SHT_21_SENSOR_STATUS_DISABLED) {
|
|
||||||
return SHT_21_SENSOR_STATUS_DISABLED;
|
|
||||||
}
|
|
||||||
if(enable) {
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_INITIALISED;
|
|
||||||
ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, state_machine, NULL);
|
|
||||||
} else {
|
|
||||||
ctimer_stop(&startup_timer);
|
|
||||||
enabled = SHT_21_SENSOR_STATUS_INITIALISED;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \brief Returns the status of the sensor
|
|
||||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
|
||||||
* \return One of the SENSOR_STATUS_xyz defines
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
status(int type)
|
|
||||||
{
|
|
||||||
switch(type) {
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return enabled;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return SHT_21_SENSOR_STATUS_DISABLED;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
SENSORS_SENSOR(sht_21_sensor, "SHT21", value, configure, status);
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/** @} */
|
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of the copyright holder nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived
|
|
||||||
* from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
||||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
||||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \addtogroup sensortag-cc26xx-peripherals
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \defgroup sensortag-cc26xx-sht-sensor SensorTag 2.0 Humidity Sensor
|
|
||||||
*
|
|
||||||
* Due to the time required between triggering a reading and the reading
|
|
||||||
* becoming available, this driver is meant to be used in an asynchronous
|
|
||||||
* fashion. The caller must first activate the sensor by calling
|
|
||||||
* SENSORS_ACTIVATE(). This will trigger a cycle which will read both
|
|
||||||
* temperature and humidity, but the call will not wait for the cycle to
|
|
||||||
* complete so that the CPU can perform other tasks or drop to a low power
|
|
||||||
* mode.
|
|
||||||
*
|
|
||||||
* Once readings are available, the driver will generate a sensors_changed
|
|
||||||
* event.
|
|
||||||
*
|
|
||||||
* Calls to .status() will return the driver's state which could indicate that
|
|
||||||
* a measurement is in progress (different return values for each) or that
|
|
||||||
* readings are ready.
|
|
||||||
*
|
|
||||||
* Multiple calls to value() will simply return the reading that was latched
|
|
||||||
* after the last cycle. In order to obtain fresh readings, a new cycle must be
|
|
||||||
* started by a new call to SENSORS_ACTIVATE.
|
|
||||||
* @{
|
|
||||||
*
|
|
||||||
* \file
|
|
||||||
* Header file for the Sensortag-CC26ss Sensirion SHT21 Humidity sensor
|
|
||||||
*/
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#ifndef SHT_21_SENSOR_H_
|
|
||||||
#define SHT_21_SENSOR_H_
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#define SHT_21_SENSOR_TYPE_TEMP 1
|
|
||||||
#define SHT_21_SENSOR_TYPE_HUMIDITY 2
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* \name SHT21 driver states
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#define SHT_21_SENSOR_STATUS_DISABLED 0 /**< Not initialised */
|
|
||||||
#define SHT_21_SENSOR_STATUS_INITIALISED 1 /**< Initialised but idle */
|
|
||||||
#define SHT_21_SENSOR_STATUS_READING_TEMP 2 /**< Temp reading in progress */
|
|
||||||
#define SHT_21_SENSOR_STATUS_READING_HUMIDITY 3 /**< Humidity reading in progress */
|
|
||||||
#define SHT_21_SENSOR_STATUS_READINGS_READY 4 /**< Both readings ready */
|
|
||||||
/** @} */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
extern const struct sensors_sensor sht_21_sensor;
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
#endif /* SHT_21_SENSOR_H_ */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
* @}
|
|
||||||
*/
|
|
Loading…
Reference in a new issue