upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for dfrec.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <signal.h>
#include "dfrec.h"
#include "upm_utilities.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
// Instantiate a DFRobot EC sensor on analog pin A0, with a ds18b20
// temperature sensor connected to UART 0, and a device index (for
// the ds1820b uart bus) of 0, and an analog reference voltage of
// 5.0.
dfrec_context sensor = dfrec_init(0, 0, 0, 5.0);
if (!sensor)
{
printf("dfrec_init() failed.\n");
return(1);
}
// Every 2 seconds, update and print values
while (shouldRun)
{
dfrec_update(sensor);
printf("EC = %f ms/cm\n", dfrec_get_ec(sensor));
printf("Volts = %f, Temperature = %f C\n",
printf("\n");
upm_delay(2);
}
printf("Exiting...\n");
dfrec_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _dfrec_context
 

Functions

dfrec_context dfrec_init (unsigned int apin, unsigned int uart_ow, unsigned int device_idx, float a_ref)
 
void dfrec_close (dfrec_context dev)
 
upm_result_t dfrec_update (const dfrec_context dev)
 
void dfrec_set_offset (const dfrec_context dev, float offset)
 
void dfrec_set_scale (const dfrec_context dev, float scale)
 
float dfrec_get_ec (const dfrec_context dev)
 
float dfrec_get_volts (const dfrec_context dev)
 
float dfrec_get_temperature (const dfrec_context dev)
 
float dfrec_get_normalized (const dfrec_context dev)
 
void dfrec_set_threshold_min_max (const dfrec_context dev, float min, float max)
 
void dfrec_set_threshold_1 (const dfrec_context dev, float thres, float scale, float offset)
 
void dfrec_set_threshold_2 (const dfrec_context dev, float thres, float scale, float offset)
 
void dfrec_set_threshold_3 (const dfrec_context dev, float scale, float offset)
 

Typedefs

typedef struct _dfrec_contextdfrec_context
 

Function Documentation

dfrec_context dfrec_init ( unsigned int  apin,
unsigned int  uart_ow,
unsigned int  device_idx,
float  a_ref 
)

DFREC Initializer

Parameters
apinAnalog pin to use.
uart_owThe UART that the ds10b20 temperature sensor is connected to.
device_idxThe device index of the ds18b20 sensor to use. If you only have 1 ds18b20 sensor on your DS one wire bus, you would pass 0 here.
a_refThe analog reference voltage in use
Returns
dfrec context

Here is the call graph for this function:

void dfrec_close ( dfrec_context  dev)

DFREC sensor close function

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t dfrec_update ( const dfrec_context  dev)

Read the sensor status and update internal state. dfrec_update() must have been called before calling any of the other dfrec_get*() functions

Parameters
devsensor context
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void dfrec_set_offset ( const dfrec_context  dev,
float  offset 
)

Set sensor offset. This offset is applied to the EC value before scaling. Default is 0.0.

Parameters
devsensor context pointer
offsetOffset to apply to the computed EC value

Here is the caller graph for this function:

void dfrec_set_scale ( const dfrec_context  dev,
float  scale 
)

Set sensor scale. The EC return value is scaled by this value before the offset is applied. Default is 1.0.

Parameters
devsensor context pointer
scaleThe scale to apply to the computed EC value

Here is the caller graph for this function:

float dfrec_get_ec ( const dfrec_context  dev)

Get computed EC (in ms/cm) value from the sensor. dfrec_update() must have been called prior to calling this function.

Parameters
devsensor context pointer
Returns
EC value in millivolts

Here is the caller graph for this function:

float dfrec_get_volts ( const dfrec_context  dev)

Get the raw measured volts from the sensor. dfrec_update() must have been called prior to calling this function.

Parameters
devsensor context pointer
Returns
Voltage read from the sensor

Here is the caller graph for this function:

float dfrec_get_temperature ( const dfrec_context  dev)

Get the measured temperature from the temperature sensor. The return value will be in Celsius.

Parameters
devsensor context pointer
Returns
Temperature read from the sensor in Celsius.

Here is the caller graph for this function:

float dfrec_get_normalized ( const dfrec_context  dev)

Get the raw normalized ADC values from the sensor. dfrec_update() must have been called prior to calling this function.

Parameters
devsensor context pointer
Returns
Normalized ADC value read from the sensor

Here is the caller graph for this function:

void dfrec_set_threshold_min_max ( const dfrec_context  dev,
float  min,
float  max 
)

Set the global threshold min and max values. See the DFRobot wiki for details.

Parameters
devsensor context pointer
minMinimum threshold to be valid. Default 150.
maxMaximum threshold to be valid. Default 3300.

Here is the caller graph for this function:

void dfrec_set_threshold_1 ( const dfrec_context  dev,
float  thres,
float  scale,
float  offset 
)

Set the threshold 1 values. See the DFRobot wiki for details.

Parameters
devsensor context pointer
thresThreshold maximum for value section 1. Default 448.
scaleScale for value section 1. Default 6.64.
offsetOffset for value section 1. Default -64.32.

Here is the caller graph for this function:

void dfrec_set_threshold_2 ( const dfrec_context  dev,
float  thres,
float  scale,
float  offset 
)

Set the threshold 2 values. See the DFRobot wiki for details.

Parameters
devsensor context pointer
thresThreshold maximum for value section 2. Default 1457.
scaleScale for value section 2. Default 6.98.
offsetOffset for value section 2. Default -127.0.

Here is the caller graph for this function:

void dfrec_set_threshold_3 ( const dfrec_context  dev,
float  scale,
float  offset 
)

Set the threshold 3 values. See the DFRobot wiki for details.

Parameters
devsensor context pointer
scaleScale for value section 3. Default 5.3.
offsetOffset for value section 3. Default 2278.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _dfrec_context * dfrec_context

Device context