µracoli Manual  Version foo
Sensor API

High Level Sensor functions

. More...

Data Structures

struct  board_sensor_ctx_t
 

Detailed Description

Overview

The sensor API implements a generic abstraction for the sensors that are supported by µracoli. The low level drivers are documented in section Sensor Drivers.
uracoli_modules_sensors.png
Sensor API in liburacoli_<board>.a
The sensors of a board are defined in file board.cfg in the key sensors: <sensors1> <sensor2> ...
Usage
uint8_t nb_sensors;
nb_sensors = create_board_sensors();
/* beside the return value of create_board_sensors() the number of sensors can be retrieved with sensor_get_number() too */
PRINTF("number of sensors: %d\n", sensor_get_number());
for (i = 0; i < nb_sensors; i++)
{
PRINTF(" %d : id=%d name=%s type=%s data_sz=%d\n",
sensor_get(i, NULL));
}
while (1)
{
sensor_trigger(ALL_SENSORS, 1);
DELAY_MS(10); // wait for conversion ready
sensor_getALL_SENSORS, buf);
PRINTF("decode: %s\n",sensor_decode(buf, line, sizeof(line)));
DELAY_MS(2000);
}
Examples

Functions

uint8_t create_board_sensors ( void  )

This function creates the data structure for all sensors that are defined per board.

Examples:
xmpl_sensor.c.
char* sensor_decode ( uint8_t *  buf,
char *  line,
uint16_t  size 
)

Decode sensor data buffer to string.

Parameters
bufsensor data buffer
lineline buffer for decoded text.
sizemaximum size of the line buffer
Returns
a string pointer to line or NULL.
Examples:
xmpl_sensor.c.
uint8_t sensor_get ( int  idx,
uint8_t *  pdata 
)

Query sensor values

Parameters
idxnumber of the sensor or ALL_SENSORS (-1) for all
pdatadatabuffer to store the sensor data.
Returns
size in bytes of the queried data block (size depends on data availability, e.g. if the sensor has data).

Note: To estimate the max. size for pdata, call sensor_get(-1, NULL). This retrieves the max. block length for all sensors.

Examples:
xmpl_sensor.c.
uint8_t sensor_get_error ( uint8_t  idx)

Get last error code of the addressed sensor.

Parameters
idxnumber of the sensor.
uint8_t sensor_get_id ( uint8_t  idx)

Get sensor ID value for the sensor indexed by idx.

Parameters
idxnumber of the sensor.
Examples:
xmpl_sensor.c.
char* sensor_get_name ( uint8_t  idx)

get sensor type for the addressed sensor.

Parameters
idxnumber of the sensor.
Examples:
xmpl_sensor.c.
uint8_t sensor_get_number ( void  )

Return the number of sensors for this board.

Examples:
xmpl_sensor.c.
char* sensor_get_type ( uint8_t  idx)

Get sensor type for the adressed sensor.

Parameters
idxnumber of the sensor.
Examples:
xmpl_sensor.c.
void sensor_sleep ( int  idx)

Set sensor into sleep mode.

Parameters
idxnumber of the sensor or ALL_SENSORS (-1) for all
Examples:
xmpl_sensor.c.
void sensor_trigger ( int  idx,
bool  one_shot 
)

Trigger a sensor measurment.

Parameters
idxnumber of the sensor or ALL_SENSORS (-1) for all.
one_shotif one_shot is true, a single measurement is triggered, otherwise a continous measurement. It depends on the sensor if this parameter is really supported in hardware.
Examples:
xmpl_sensor.c.

Data Structure Documentation

struct board_sensor_ctx_t

board defined sensor data structure

Definition at line 76 of file sensor.h.