upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
dfrec.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 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 <stdint.h>
28 #include "upm.h"
29 #include "mraa/aio.h"
30 
31 #include "ds18b20.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
48  typedef struct _dfrec_context {
49  mraa_aio_context aio;
50 
51  // ds18b20 context (for temperature measurement
52  ds18b20_context ds18b20;
53  unsigned int device_idx;
54 
55  // analog ADC resolution
56  float a_res;
57 
58  // analog reference voltage
59  float a_ref;
60 
61  // for external offset and scaling of the results
62  float offset;
63  float scale;
64 
65  // volts
66  float volts;
67 
68  // normalized ADC
69  float normalized;
70 
71  // the EC value
72  float ec;
73 
74  // EC threshold min/max (mV)
75  float thres_min; // 150
76  float thres_max; // 3300
77 
78  // the temperature read from the ds18b29
79  float temperature;
80 
81  // thresholds, scales, and offsets taken from the DFRobot code
82  float thres_1; // 448
83  float scale_1; // 6.84
84  float offset_1; // -64.32
85 
86  float thres_2; // 1457
87  float scale_2; // 6.98
88  float offset_2; // -127.0
89 
90  float scale_3; // 5.3
91  float offset_3; // +2278.0
92  } *dfrec_context;
93 
106  dfrec_context dfrec_init(unsigned int apin, unsigned int uart_ow,
107  unsigned int device_idx,
108  float a_ref);
109 
113  void dfrec_close(dfrec_context dev);
114 
123  upm_result_t dfrec_update(const dfrec_context dev);
124 
132  void dfrec_set_offset(const dfrec_context dev, float offset);
133 
141  void dfrec_set_scale(const dfrec_context dev, float scale);
142 
150  float dfrec_get_ec(const dfrec_context dev);
151 
159  float dfrec_get_volts(const dfrec_context dev);
160 
168  float dfrec_get_temperature(const dfrec_context dev);
169 
178  float dfrec_get_normalized(const dfrec_context dev);
179 
188  void dfrec_set_threshold_min_max(const dfrec_context dev, float min,
189  float max);
190 
199  void dfrec_set_threshold_1(const dfrec_context dev, float thres,
200  float scale, float offset);
201 
210  void dfrec_set_threshold_2(const dfrec_context dev, float thres,
211  float scale, float offset);
212 
220  void dfrec_set_threshold_3(const dfrec_context dev, float scale,
221  float offset);
222 
223 
224 #ifdef __cplusplus
225 }
226 #endif
Definition: dfrec.h:48
struct _dfrec_context * dfrec_context
void dfrec_set_threshold_min_max(const dfrec_context dev, float min, float max)
Definition: dfrec.c:251
float dfrec_get_temperature(const dfrec_context dev)
Definition: dfrec.c:230
float dfrec_get_ec(const dfrec_context dev)
Definition: dfrec.c:223
void dfrec_set_threshold_1(const dfrec_context dev, float thres, float scale, float offset)
Definition: dfrec.c:260
upm_result_t dfrec_update(const dfrec_context dev)
Definition: dfrec.c:164
C API for the DS18B20 1-Wire Temperature Sensor.
void dfrec_set_threshold_3(const dfrec_context dev, float scale, float offset)
Definition: dfrec.c:280
Definition: ds18b20.h:52
void dfrec_set_threshold_2(const dfrec_context dev, float thres, float scale, float offset)
Definition: dfrec.c:270
void dfrec_set_offset(const dfrec_context dev, float offset)
Definition: dfrec.c:150
float dfrec_get_normalized(const dfrec_context dev)
Definition: dfrec.c:244
void dfrec_close(dfrec_context dev)
Definition: dfrec.c:137
float dfrec_get_volts(const dfrec_context dev)
Definition: dfrec.c:237
void dfrec_set_scale(const dfrec_context dev, float scale)
Definition: dfrec.c:157
dfrec_context dfrec_init(unsigned int apin, unsigned int uart_ow, unsigned int device_idx, float a_ref)
Definition: dfrec.c:60