Contiki-NG
Files | Functions

Humidity Sensor. More...

Files

 
 

Functions

static bool i2c_write_read (void *wbuf, size_t wcount, void *rbuf, size_t rcount)
 Setup and peform an I2C transaction. More...
 
static bool i2c_write (void *wbuf, size_t wcount)
 Peform a write only I2C transaction. More...
 
static bool i2c_read (void *rbuf, size_t rcount)
 Peform a read only I2C transaction. More...
 
static bool sensor_init (void)
 Initialize the HDC-1000 sensor driver. More...
 
static bool start (void)
 Start measurement. More...
 
static void convert (int32_t *temp, int32_t *hum)
 Convert raw data to temperature and humidity. More...
 
static void notify_ready (void *unused)
 Callback when sensor is ready to read data from.
 
static int value (int type)
 Returns a reading from the sensor. More...
 
static int configure (int type, int enable)
 Configuration function for the HDC1000 sensor. More...
 
static int status (int type)
 Returns the status of the sensor. More...
 

HDC1000 driver states

enum  HDC_1000_SENSOR_STATUS {
  HDC_1000_SENSOR_STATUS_DISABLED, HDC_1000_SENSOR_STATUS_INITIALISED, HDC_1000_SENSOR_STATUS_TAKING_READINGS, HDC_1000_SENSOR_STATUS_I2C_ERROR,
  HDC_1000_SENSOR_STATUS_READINGS_READY
}
 

Detailed Description

Humidity 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_HUMID 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().

Enumeration Type Documentation

◆ HDC_1000_SENSOR_STATUS

Enumerator
HDC_1000_SENSOR_STATUS_DISABLED 

Not initialised.

HDC_1000_SENSOR_STATUS_INITIALISED 

Initialised but idle.

HDC_1000_SENSOR_STATUS_TAKING_READINGS 

Readings in progress.

HDC_1000_SENSOR_STATUS_I2C_ERROR 

I2C transaction failed.

HDC_1000_SENSOR_STATUS_READINGS_READY 

Both readings ready.

Definition at line 87 of file hdc-1000-sensor.h.

Function Documentation

◆ configure()

static int configure ( int  type,
int  enable 
)
static

Configuration function for the HDC1000 sensor.

Parameters
typeActivate, enable or disable the sensor. See below.
enableEither enable or disable the sensor. 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.

Definition at line 294 of file hdc-1000-sensor.c.

◆ convert()

static void convert ( int32_t *  temp,
int32_t *  hum 
)
static

Convert raw data to temperature and humidity.

Parameters
tempOutput variable to store converted temperature.
humOutput variable to store converted humidity.

Definition at line 219 of file hdc-1000-sensor.c.

◆ i2c_read()

static bool i2c_read ( void *  rbuf,
size_t  rcount 
)
inlinestatic

Peform a read only I2C transaction.

Parameters
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 168 of file hdc-1000-sensor.c.

References i2c_write_read().

Referenced by notify_ready().

◆ i2c_write()

static bool i2c_write ( void *  wbuf,
size_t  wcount 
)
inlinestatic

Peform a write only I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 156 of file hdc-1000-sensor.c.

References i2c_write_read().

◆ i2c_write_read()

static bool i2c_write_read ( void *  wbuf,
size_t  wcount,
void *  rbuf,
size_t  rcount 
)
static

Setup and peform an I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 136 of file hdc-1000-sensor.c.

Referenced by i2c_read(), and i2c_write().

◆ sensor_init()

static bool sensor_init ( void  )
static

Initialize the HDC-1000 sensor driver.

Returns
true if I2C operation successful; else, return false.

Definition at line 178 of file hdc-1000-sensor.c.

◆ start()

static bool start ( void  )
static

Start measurement.

Returns
true if I2C operation successful; else, return false.

Definition at line 206 of file hdc-1000-sensor.c.

◆ status()

static int status ( int  type)
static

Returns the status of the sensor.

Parameters
typeSENSORS_ACTIVE or SENSORS_READY.
Returns
One of the SENSOR_STATUS_xyz defines.

Definition at line 338 of file hdc-1000-sensor.c.

◆ value()

static int value ( int  type)
static

Returns a reading from the sensor.

Parameters
typeHDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMID.
Returns
Temperature (centi degrees C) or Humidity (centi RH).

Definition at line 255 of file hdc-1000-sensor.c.