Contiki-Inga 3.x
Data Structures | Macros | Functions
Sensor interface

Data Structures

struct  sensors_sensor
 Sensor defintion structure. More...
 

Macros

#define SENSORS_ACTIVATE(sensor)   (sensor).configure(SENSORS_ACTIVE, 1)
 Activates sensor.
 
#define SENSORS_DEACTIVATE(sensor)   (sensor).configure(SENSORS_ACTIVE, 0)
 Deactivates sensor.
 
#define SENSORS_SENSOR(name, type, value, configure, status)   const struct sensors_sensor name = { type, value, configure, status }
 Defines new sensor. More...
 
#define SENSORS_NUM   (sizeof(sensors) / sizeof(struct sensors_sensor *))
 Provides the number of available sensors. More...
 
#define SENSORS(...)
 Setup defined sensors. More...
 

Functions

struct sensors_sensorsensors_find (const char *type)
 Returns sensor associated with type name if existing. More...
 
struct sensors_sensorsensors_next (const struct sensors_sensor *s)
 Returns next sensor in sensors list. More...
 
struct sensors_sensorsensors_first (void)
 Returns first sensor in sensors list. More...
 
void sensors_changed (const struct sensors_sensor *s)
 To be called from sensor readout interrupt. More...
 

Default constants for the configure/status API

#define SENSORS_HW_INIT   128
 internal - used only for (hardware) initialization. More...
 
#define SENSORS_ACTIVE   129
 Configuration: activates/deactives sensor: 0 -> turn off, 1 -> turn on. More...
 
#define SENSORS_READY   130
 Status query: Returns 1 if sensor is ready.
 

Detailed Description

Using a sensor

Each sensor has a set of functions for controlling it and query it for its state. Some sensors also generate an events when the sensors change. A sensor must be activated before it generates events or relevant values.

Example for querying the button:

SENSORS_ACTIVATE(button_sensor) // activate the button sensor
button_sensor::value(0) // the button has been pressed or not

Defining new sensors

Platform designers may need to define new sensors. This sections describes the steps required.

Each sensor requires 3 functions; one for quering data, one for configuring the sensor, and one for requesting status.

static int my_value(int type) {...}
static int my_configure(int type, int value) {...}
static int my_status(int type) {...}

These functions have to adapt the interface described in sensors_sensor.

To create a contiki sensor of them use the SENSORS_SENSOR() macro.

SENSORS_SENSOR(my_sensor, "MY_TYPE", my_value, my_configure, my_status);

Finally add the sensor to your platforms sensor list.

SENSORS(..., &my_sensor, ...);

Macro Definition Documentation

#define SENSORS (   ...)
Value:
const struct sensors_sensor *sensors[] = {__VA_ARGS__, NULL}; \
unsigned char sensors_flags[SENSORS_NUM]

Setup defined sensors.

Parameters
comma-separatedlist of pointers to defined sensors.
SENSORS_SENSOR(acc_sensor, "ACC", acc_val, acc_cfg, acc_status);
SENSORS_SENSOR(battery_sensor, "ACC", battery_val, battery_cfg, battery_status);
SENSORS(accsensor, battery_sensor);

Definition at line 124 of file sensors.h.

#define SENSORS_ACTIVE   129

Configuration: activates/deactives sensor: 0 -> turn off, 1 -> turn on.

Status query: Returns 1 if sensor is active.

Definition at line 92 of file sensors.h.

#define SENSORS_HW_INIT   128

internal - used only for (hardware) initialization.

Definition at line 88 of file sensors.h.

#define SENSORS_NUM   (sizeof(sensors) / sizeof(struct sensors_sensor *))

Provides the number of available sensors.

Definition at line 113 of file sensors.h.

#define SENSORS_SENSOR (   name,
  type,
  value,
  configure,
  status 
)    const struct sensors_sensor name = { type, value, configure, status }

Defines new sensor.

Parameters
nameof the sensor
Stringtype name of the sensor
pointerto sensors value function
pointerto sensors configure function
pointerto sensors status function

Definition at line 109 of file sensors.h.

Function Documentation

void sensors_changed ( const struct sensors_sensor s)

To be called from sensor readout interrupt.

Polls sensor process.

Parameters
sReference to the sensor that updated

Definition at line 77 of file sensors.c.

References process_poll().

struct sensors_sensor* sensors_find ( const char *  type)
read

Returns sensor associated with type name if existing.

Parameters
typeType name (string)
Returns
pointer to sensor

Definition at line 84 of file sensors.c.

References NULL, and sensors_sensor::type.

struct sensors_sensor* sensors_first ( void  )
read

Returns first sensor in sensors list.

Returns
pointer to sensor

Definition at line 65 of file sensors.c.

struct sensors_sensor* sensors_next ( const struct sensors_sensor s)
read

Returns next sensor in sensors list.

Returns
pointer to sensor

Definition at line 71 of file sensors.c.