upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
flex.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 _flex_context {
46  /* mraa aio pin context */
47  mraa_aio_context aio;
48  /* Analog voltage reference */
49  float m_aRef;
50  /* Scale */
51  float m_scale;
52  /* Offset in sensor units */
53  float m_offset;
54 } *flex_context;
55 
61 flex_context flex_init(int16_t pin);
62 
67 void flex_close(flex_context dev);
68 
75 upm_result_t flex_set_aref(const flex_context dev, float aref);
76 
84 upm_result_t flex_set_scale(const flex_context dev, float scale);
85 
93 upm_result_t flex_set_offset(const flex_context dev, float offset);
94 
100 float flex_get_aref(const flex_context dev);
101 
107 float flex_get_scale(const flex_context dev);
108 
114 float flex_get_offset(const flex_context dev);
115 
122 upm_result_t flex_get_normalized(const flex_context dev, float *value);
123 
130 upm_result_t flex_get_raw_volts(const flex_context dev, float *value);
131 
138 upm_result_t flex_get_volts(const flex_context dev, float *value);
139 #ifdef __cplusplus
140 }
141 #endif
upm_result_t flex_set_aref(const flex_context dev, float aref)
Definition: flex.c:67
float flex_get_scale(const flex_context dev)
Definition: flex.c:90
flex_context flex_init(int16_t pin)
Definition: flex.c:30
upm_result_t flex_set_offset(const flex_context dev, float offset)
Definition: flex.c:79
upm_result_t flex_get_normalized(const flex_context dev, float *value)
Definition: flex.c:100
upm_result_t flex_get_raw_volts(const flex_context dev, float *value)
Definition: flex.c:108
struct _flex_context * flex_context
upm_result_t flex_set_scale(const flex_context dev, float scale)
Definition: flex.c:73
float flex_get_aref(const flex_context dev)
Definition: flex.c:85
upm_result_t flex_get_volts(const flex_context dev, float *value)
Definition: flex.c:120
float flex_get_offset(const flex_context dev)
Definition: flex.c:95
Definition: flex.h:45
void flex_close(flex_context dev)
Definition: flex.c:61