39 #include "contiki-conf.h"
41 #include "lib/sensors.h"
55 #define PRINTF(...) printf(__VA_ARGS__)
61 #define SENSOR_I2C_ADDRESS 0x43
64 #define HDC1000_REG_TEMP 0x00
65 #define HDC1000_REG_HUM 0x01
66 #define HDC1000_REG_CONFIG 0x02
67 #define HDC1000_REG_SERID_H 0xFB
68 #define HDC1000_REG_SERID_M 0xFC
69 #define HDC1000_REG_SERID_L 0xFD
70 #define HDC1000_REG_MANF_ID 0xFE
71 #define HDC1000_REG_DEV_ID 0xFF
74 #define HDC1000_VAL_MANF_ID 0x5449
75 #define HDC1000_VAL_DEV_ID 0x1000
76 #define HDC1000_VAL_CONFIG 0x1000
79 #define SENSOR_SELECT() board_i2c_select(BOARD_I2C_INTERFACE_0, SENSOR_I2C_ADDRESS)
80 #define SENSOR_DESELECT() board_i2c_deselect()
83 #define HI_UINT16(a) (((a) >> 8) & 0xFF)
84 #define LO_UINT16(a) ((a) & 0xFF)
86 #define SWAP(v) ((LO_UINT16(v) << 8) | HI_UINT16(v))
89 typedef struct sensor_data {
95 static uint16_t raw_temp;
96 static uint16_t raw_hum;
99 static sensor_data_t data;
108 #define MEASUREMENT_DURATION 2
114 #define SENSOR_STARTUP_DELAY 3
116 static struct ctimer startup_timer;
130 val = SWAP(HDC1000_VAL_CONFIG);
168 raw_temp = SWAP(data.temp);
171 raw_hum = SWAP(data.hum);
189 *temp = ((double)(int16_t)raw_temp / 65536) * 165 - 40;
192 *hum = ((double)raw_hum / 65536) * 100;
196 notify_ready(
void *not_used)
203 sensors_changed(&hdc_1000_sensor);
219 PRINTF(
"Sensor disabled or starting up (%d)\n", enabled);
220 return CC26XX_SENSOR_READING_ERROR;
223 if((type != HDC_1000_SENSOR_TYPE_TEMP) &&
224 type != HDC_1000_SENSOR_TYPE_HUMIDITY) {
225 PRINTF(
"Invalid type\n");
226 return CC26XX_SENSOR_READING_ERROR;
229 PRINTF(
"HDC: %04X %04X t=%d h=%d\n", raw_temp, raw_hum,
230 (
int)(temp * 100), (
int)(hum * 100));
232 if(type == HDC_1000_SENSOR_TYPE_TEMP) {
233 rv = (int)(temp * 100);
234 }
else if(type == HDC_1000_SENSOR_TYPE_HUMIDITY) {
235 rv = (int)(hum * 100);
255 case SENSORS_HW_INIT:
258 memset(&data, 0,
sizeof(data));
270 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready,
NULL);
static void start(void)
Start measurement.
Header file with macros which rename TI CC26xxware functions.
static bool read_data()
Take readings from the sensor.
static int status(int type)
Returns the status of the sensor.
bool board_i2c_write_single(uint8_t data)
Single write to an I2C device.
bool board_i2c_read(uint8_t *data, uint8_t len)
Burst read from an I2C device.
Header file for the Sensortag-CC26ss TI HDC1000 sensor.
Header file for the callback timer
#define NULL
The null pointer.
#define HDC_1000_SENSOR_STATUS_INITIALISED
Initialised but idle.
Header file for the Sensortag-CC26xx Common sensor utilities.
Header file for the Sensortag-CC26xx I2C Driver.
#define HDC_1000_SENSOR_STATUS_DISABLED
Not initialised.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
#define HDC_1000_SENSOR_STATUS_TAKING_READINGS
Readings in progress.
static int value(int type)
Returns a reading from the sensor.
bool sensor_common_write_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Write to a sensor's register over I2C.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
static void convert(float *temp, float *hum)
Convert raw data to temperature and humidity.
#define HDC_1000_SENSOR_STATUS_READINGS_READY
Both readings ready.
static int configure(int type, int enable)
Configuration function for the HDC1000 sensor.
static bool sensor_init(void)
Initialise the humidity sensor driver.