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.
- sensors_event - event sent when a sensor has changed (the data argument will referer to the actual sensor)
Example for querying the button:
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.
Value:
Setup defined sensors.
- Parameters
-
comma-separated | list of pointers to defined sensors. |
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
-
name | of the sensor |
String | type name of the sensor |
pointer | to sensors value function |
pointer | to sensors configure function |
pointer | to sensors status function |
Definition at line 109 of file sensors.h.
To be called from sensor readout interrupt.
Polls sensor process.
- Parameters
-
s | Reference to the sensor that updated |
Definition at line 77 of file sensors.c.
References process_poll().
Returns first sensor in sensors list.
- Returns
- pointer to sensor
Definition at line 65 of file sensors.c.
Returns next sensor in sensors list.
- Returns
- pointer to sensor
Definition at line 71 of file sensors.c.