Contiki-NG
Files | Macros | Functions

   Due to the time required for the sensor to startup, this driver is
   meant to be used in an asynchronous fashion.
More...

Files

 
 

Macros

#define VAL_CONFIG_ON   0x1000
 Sensor on state.
 
#define VAL_CONFIG_OFF   0x0000
 Sensor off state.
 
#define VAL_PROD_ID   0x0078
 Product ID.
 

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 TMP-007 sensor driver. More...
 
static void notify_ready_cb (void *not_used)
 Callback when sensor is ready to read data from.
 
static bool enable_sensor (bool enable)
 Turn the sensor on or off.
 
static bool read_data (uint16_t *local_tmp, uint16_t *obj_tmp)
 Read the sensor value registers. More...
 
static void convert (uint16_t *local_tmp, uint16_t *obj_tmp)
 Convert raw data to values in degrees Celsius. More...
 
static int value (int type)
 Returns a reading from the sensor. More...
 
static int configure (int type, int enable)
 Configuration function for the TMP-007 sensor. More...
 
static int status (int type)
 Returns the status of the sensor. More...
 

Detailed Description

   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 is stable, the driver will generate a sensors_changed event.

The caller should then use value(TMP_007_SENSOR_TYPE_ALL) to read sensor values and latch them. Once completed successfully, individual readings can be retrieved with calls to value(TMP_007_SENSOR_TYPE_OBJECT) or value(TMP_007_SENSOR_TYPE_AMBIENT).

Once required readings have been taken, the caller has two options:

Function Documentation

◆ configure()

static int configure ( int  type,
int  enable 
)
static

Configuration function for the TMP-007 sensor.

Parameters
typeActivate, enable or disable the sensor. See below.
enableEnable or disable 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 367 of file tmp-007-sensor.c.

◆ convert()

static void convert ( uint16_t *  local_tmp,
uint16_t *  obj_tmp 
)
static

Convert raw data to values in degrees Celsius.

Parameters
local_tmpOutput variable holding the raw ambient temperature from sensor.
obj_tmpOutput variable holding the raw object temperature from sensor.

Definition at line 302 of file tmp-007-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 180 of file tmp-007-sensor.c.

References i2c_write_read().

◆ 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 168 of file tmp-007-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 148 of file tmp-007-sensor.c.

Referenced by i2c_read(), and i2c_write().

◆ read_data()

static bool read_data ( uint16_t *  local_tmp,
uint16_t *  obj_tmp 
)
static

Read the sensor value registers.

Parameters
local_tmpOutput variable holding the Temperature in 16-bit format.
obj_tmpOutput variable holding the Object temperature in 16-bit format.
Returns
true if valid data could be retrieved; else, false.

Definition at line 252 of file tmp-007-sensor.c.

◆ sensor_init()

static bool sensor_init ( void  )
static

Initialize the TMP-007 sensor driver.

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

Definition at line 190 of file tmp-007-sensor.c.

◆ status()

static int status ( int  type)
static

Returns the status of the sensor.

Parameters
typeIgnored.
Returns
Status of the sensor.

Definition at line 409 of file tmp-007-sensor.c.

◆ value()

static int value ( int  type)
static

Returns a reading from the sensor.

Parameters
typeTMP_007_SENSOR_TYPE_OBJECT or TMP_007_SENSOR_TYPE_AMBIENT.
Returns
Object or Ambient temperature in milli degrees Celsius.

Definition at line 320 of file tmp-007-sensor.c.