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

API Description

/*
* Author: Noel Eck <noel.eck@intel.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 "vdiv.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 sensor on analog pin A0
vdiv_context sensor = vdiv_init(0, 5);
if (!sensor)
{
printf("vdiv_init() failed.\n");
return(1);
}
// Every half a second, sample the sensor output
while (shouldRun)
{
float raw_volts = 0.0, computed_volts = 0.0;
vdiv_get_raw_volts(sensor, &raw_volts);
vdiv_get_computed_volts(sensor, &computed_volts);
printf("Divide SW: %d ADC voltage: %0.03f Sensor voltage: %0.03f\n",
vdiv_get_divsw(sensor), raw_volts, computed_volts);
upm_delay_ms(500);
}
printf("Exiting\n");
vdiv_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _vdiv_context
 

Functions

vdiv_context vdiv_init (int16_t pin, float voltage_ref)
 
void vdiv_close (vdiv_context dev)
 
upm_result_t vdiv_set_scale (const vdiv_context dev, float scale)
 
upm_result_t vdiv_set_offset (const vdiv_context dev, float offset)
 
float vdiv_get_scale (const vdiv_context dev)
 
float vdiv_get_offset (const vdiv_context dev)
 
upm_result_t vdiv_set_divsw (const vdiv_context dev, int vdiv_sw)
 
int vdiv_get_divsw (const vdiv_context dev)
 
upm_result_t vdiv_get_raw_volts (const vdiv_context dev, float *value)
 
upm_result_t vdiv_get_computed_volts (const vdiv_context dev, float *value)
 

Typedefs

typedef struct _vdiv_contextvdiv_context
 

Function Documentation

vdiv_context vdiv_init ( int16_t  pin,
float  voltage_ref 
)

Initialize analog sensor

Parameters
pinis Analog pin
Returns
sensor context as void pointer
void vdiv_close ( vdiv_context  dev)

Analog sensor destructor

Parameters
sensorcontext pointer deallocate memory
upm_result_t vdiv_set_scale ( const vdiv_context  dev,
float  scale 
)

Set sensor scale. This scale is applied to the return value: counts = counts * scale

Parameters
devsensor context pointer
scalecount scale value used
Returns
Function result code
upm_result_t vdiv_set_offset ( const vdiv_context  dev,
float  offset 
)

Set sensor offset. This offset is applied to the return value: counts = counts + offset

Parameters
devsensor context pointer
offsetcount offset value used
Returns
Function result code
float vdiv_get_scale ( const vdiv_context  dev)

Get sensor scale

Parameters
devsensor context pointer
Returns
Sensor scale
float vdiv_get_offset ( const vdiv_context  dev)

Get sensor offset

Parameters
devsensor context pointer
Returns
Sensor offset
upm_result_t vdiv_set_divsw ( const vdiv_context  dev,
int  vdiv_sw 
)

Set sensor divide switch value

Parameters
devsensor context pointer
vdiv_swDivide switch value
Returns
Function result code
int vdiv_get_divsw ( const vdiv_context  dev)

Get divide switch value

Parameters
devsensor context pointer
Returns
Sensor divide switch value
upm_result_t vdiv_get_raw_volts ( const vdiv_context  dev,
float *  value 
)

Read raw voltage from the sensor

Parameters
devsensor context pointer
*valueRaw sensor voltage
Returns
Function result code
upm_result_t vdiv_get_computed_volts ( const vdiv_context  dev,
float *  value 
)

Gets the true voltage value from the sensor. Voltage divides by 3 or 10, depending on the toggle switch on the board. The dynamic range of the vdiv sensor is listed below.

ADC Ref SW max VOL in


3.3v 3 8.5v 3.3v 10 28.4v 5.0v 3 12.9v 5.0v 10 43.0v

Parameters
devsensor context pointer
*valueVoltage (v)
Returns
Function result code

Typedef Documentation

typedef struct _vdiv_context * vdiv_context

device context