upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
enc03r.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2014-2017 Intel Corporation.
4 emacs . *
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 #pragma once
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 
30 #include <mraa/aio.h>
31 #include <upm.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
47  typedef struct _enc03r_context {
48  mraa_aio_context aio;
49 
50  // determined by calibrate();
51  float calibrationValue;
52 
53  // our computed value
54  float angular_velocity;
55 
56  // analog reference voltage
57  float a_ref;
58  // analog ADC resolution (max value)
59  float a_res;
60 
61  // offset
62  float offset;
63 
64  // scale
65  float scale;
66 
67  // normalized ADC value
68  float normalized;
69 
70  } *enc03r_context;
71 
79  enc03r_context enc03r_init(int pin, float aref);
80 
86  void enc03r_close(enc03r_context dev);
87 
96  upm_result_t enc03r_update(enc03r_context dev);
97 
107  upm_result_t enc03r_calibrate(const enc03r_context dev,
108  unsigned int samples);
109 
116  float enc03r_calibration_value(const enc03r_context dev);
117 
126  float enc03r_angular_velocity(const enc03r_context dev);
127 
135  void enc03r_set_offset(const enc03r_context dev, float offset);
136 
144  void enc03r_set_scale(const enc03r_context dev, float scale);
145 
155  float enc03r_get_normalized(const enc03r_context dev);
156 
157 #ifdef __cplusplus
158 }
159 #endif
float enc03r_calibration_value(const enc03r_context dev)
Definition: enc03r.c:126
upm_result_t enc03r_calibrate(const enc03r_context dev, unsigned int samples)
Definition: enc03r.c:101
float enc03r_angular_velocity(const enc03r_context dev)
Definition: enc03r.c:133
void enc03r_close(enc03r_context dev)
Definition: enc03r.c:70
void enc03r_set_offset(const enc03r_context dev, float offset)
Definition: enc03r.c:140
struct _enc03r_context * enc03r_context
enc03r_context enc03r_init(int pin, float aref)
Definition: enc03r.c:32
upm_result_t enc03r_update(enc03r_context dev)
Definition: enc03r.c:80
void enc03r_set_scale(const enc03r_context dev, float scale)
Definition: enc03r.c:147
float enc03r_get_normalized(const enc03r_context dev)
Definition: enc03r.c:154
Definition: enc03r.h:47