Contiki-NG
Loading...
Searching...
No Matches

Humidity Sensor More...

Files

 
 

Functions

static bool sensor_init (void)
 Initialize the HDC-1000 sensor driver.
 
static bool start (void)
 Start measurement.
 
static void convert (int32_t *temp, int32_t *hum)
 Convert raw data to temperature and humidity.
 
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.
 
static int configure (int type, int enable)
 Configuration function for the HDC1000 sensor.
 
static int status (int type)
 Returns the status of the sensor.
 

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 302 of file hdc-1000-sensor.c.

References configure(), ctimer_set(), ctimer_stop(), HDC_1000_SENSOR_STATUS_DISABLED, HDC_1000_SENSOR_STATUS_I2C_ERROR, HDC_1000_SENSOR_STATUS_INITIALISED, HDC_1000_SENSOR_STATUS_TAKING_READINGS, notify_ready(), sensor_init(), and start().

Referenced by configure().

◆ 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 207 of file hdc-1000-sensor.c.

References value().

◆ 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 147 of file hdc-1000-sensor.c.

References i2c_arch_acquire(), i2c_arch_release(), i2c_arch_write(), and value().

◆ start()

static bool start ( void )
static

Start measurement.

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

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

References i2c_arch_acquire(), i2c_arch_release(), i2c_arch_write(), and value().

◆ 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 346 of file hdc-1000-sensor.c.

References HDC_1000_SENSOR_STATUS_DISABLED.

◆ 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 263 of file hdc-1000-sensor.c.

References convert(), HDC_1000_SENSOR_STATUS_READINGS_READY, and value().

Referenced by convert(), notify_ready(), sensor_init(), start(), and value().