upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
vdiv.h
Go to the documentation of this file.
1 /*
2  * Author: Noel Eck <noel.eck@intel.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include "upm.h"
28 #include "mraa/aio.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
45 typedef struct _vdiv_context {
46  /* mraa aio pin context */
47  mraa_aio_context aio;
48  /* ADC voltage reference */
49  float m_aRef;
50  /* Scale */
51  float m_scale;
52  /* Offset in sensor units */
53  float m_offset;
54  /* Offset in sensor units */
55  int m_vdiv_sw;
56 } *vdiv_context;
57 
58 
64 vdiv_context vdiv_init(int16_t pin, float voltage_ref);
65 
70 void vdiv_close(vdiv_context dev);
71 
79 upm_result_t vdiv_set_scale(const vdiv_context dev, float scale);
80 
88 upm_result_t vdiv_set_offset(const vdiv_context dev, float offset);
89 
95 float vdiv_get_scale(const vdiv_context dev);
96 
102 float vdiv_get_offset(const vdiv_context dev);
103 
110 upm_result_t vdiv_set_divsw(const vdiv_context dev, int vdiv_sw);
111 
117 int vdiv_get_divsw(const vdiv_context dev);
118 
125 upm_result_t vdiv_get_raw_volts(const vdiv_context dev, float *value);
126 
143 upm_result_t vdiv_get_computed_volts(const vdiv_context dev, float *value);
144 
145 #ifdef __cplusplus
146 }
147 #endif
Definition: vdiv.h:45
float vdiv_get_offset(const vdiv_context dev)
Definition: vdiv.c:84
upm_result_t vdiv_get_raw_volts(const vdiv_context dev, float *value)
Definition: vdiv.c:100
int vdiv_get_divsw(const vdiv_context dev)
Definition: vdiv.c:95
void vdiv_close(vdiv_context dev)
Definition: vdiv.c:61
upm_result_t vdiv_get_computed_volts(const vdiv_context dev, float *value)
Definition: vdiv.c:112
upm_result_t vdiv_set_offset(const vdiv_context dev, float offset)
Definition: vdiv.c:73
vdiv_context vdiv_init(int16_t pin, float voltage_ref)
Definition: vdiv.c:30
float vdiv_get_scale(const vdiv_context dev)
Definition: vdiv.c:79
struct _vdiv_context * vdiv_context
upm_result_t vdiv_set_divsw(const vdiv_context dev, int vdiv_sw)
Definition: vdiv.c:89
upm_result_t vdiv_set_scale(const vdiv_context dev, float scale)
Definition: vdiv.c:67