Contiki-NG
Files | Functions

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

Files

file  opt-3001-sensor.c
 Driver for the Sensortag Opt3001 light sensor.
 
file  opt-3001-sensor.h
 Header file for the Sensortag Opt3001 light sensor.
 

Functions

static void select_on_bus (void)
 Select the sensor on the I2C bus.
 
static void enable_sensor (bool enable)
 Turn the sensor on/off. More...
 
static bool read_data (uint16_t *raw_data)
 Read the result register. More...
 
static float convert (uint16_t raw_data)
 Convert raw data to a value in lux. More...
 
static int value (int type)
 Returns a reading from the sensor. More...
 
static int configure (int type, int enable)
 Configuration function for the OPT3001 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 reading and conversion are complete, the driver will generate a sensors_changed event.

We use single-shot readings. In this mode, the hardware automatically goes back to its shutdown mode after the conversion is finished. However, it will still respond to I2C operations, so the last conversion can still be read out.

In order to take a new reading, the caller has to use SENSORS_ACTIVATE again.

Function Documentation

◆ configure()

static int configure ( int  type,
int  enable 
)
static

Configuration function for the OPT3001 sensor.

Parameters
typeActivate, enable or disable the sensor. See below
enableWhen 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 278 of file opt-3001-sensor.c.

◆ convert()

static float convert ( uint16_t  raw_data)
static

Convert raw data to a value in lux.

Parameters
raw_datadata Pointer to a buffer with a raw sensor reading
Returns
Converted value (lux)

Definition at line 230 of file opt-3001-sensor.c.

◆ enable_sensor()

static void enable_sensor ( bool  enable)
static

Turn the sensor on/off.

Parameters
enableTRUE: on, FALSE: off

Definition at line 168 of file opt-3001-sensor.c.

◆ read_data()

static bool read_data ( uint16_t *  raw_data)
static

Read the result register.

Parameters
raw_dataPointer to a buffer to store the reading
Returns
TRUE if valid data

Definition at line 196 of file opt-3001-sensor.c.

Referenced by value().

◆ status()

static int status ( int  type)
static

Returns the status of the sensor.

Parameters
typeignored
Returns
The state of the sensor SENSOR_STATE_xyz

Definition at line 314 of file opt-3001-sensor.c.

◆ value()

static int value ( int  type)
static

Returns a reading from the sensor.

Parameters
typeIgnored
Returns
Illuminance in centilux

Definition at line 246 of file opt-3001-sensor.c.

References read_data().