upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
mma7361.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 #include "mraa/gpio.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
47  typedef struct _mma7361_context {
48  // at least one of these must be intialized
49  mraa_aio_context aio_x;
50  mraa_aio_context aio_y;
51  mraa_aio_context aio_z;
52 
53  // optional - enable selftest
54  mraa_gpio_context gpio_selftest;
55 
56  // optional - enable sleep mode
57  mraa_gpio_context gpio_sleep;
58 
59  // optional - detect free fall (0g)
60  mraa_gpio_context gpio_freefall;
61 
62  // optional - if unconnected, range is 1.5g
63  mraa_gpio_context gpio_range;
64 
65  // selected G range
66  float g_range;
67 
68  // analog ADC resolution
69  float a_res;
70 
71  // analog reference voltage
72  float a_ref;
73 
74  // for external offset and scaling of the results
75  float offset_x;
76  float offset_y;
77  float offset_z;
78 
79  float scale_x;
80  float scale_y;
81  float scale_z;
82 
83  // our measurements
84  float accel_x;
85  float accel_y;
86  float accel_z;
87 
88  // volts
89  float volts_x;
90  float volts_y;
91  float volts_z;
92 
93  // normalized ADC
94  float normalized_x;
95  float normalized_y;
96  float normalized_z;
97  } *mma7361_context;
98 
128  mma7361_context mma7361_init(int x_pin, int y_pin, int z_pin,
129  int selftest_pin, int sleep_pin,
130  int freefall_pin, int range_pin,
131  float a_ref);
132 
136  void mma7361_close(mma7361_context dev);
137 
145  void mma7361_set_range(const mma7361_context dev, bool range);
146 
154  upm_result_t mma7361_sleep(const mma7361_context dev, bool sleep);
155 
164  upm_result_t mma7361_freefall(const mma7361_context dev, bool *freefall);
165 
173  upm_result_t mma7361_selftest(const mma7361_context dev, bool selftest);
174 
184  upm_result_t mma7361_update(const mma7361_context dev);
185 
195  void mma7361_set_offset(const mma7361_context dev, float x, float y,
196  float z);
197 
207  void mma7361_set_scale(const mma7361_context dev, float x, float y,
208  float z);
209 
220  float *x, float *y, float *z);
221 
231  void mma7361_get_volts(const mma7361_context dev,
232  float *x, float *y, float *z);
233 
244  float *x, float *y, float *z);
245 
246 #ifdef __cplusplus
247 }
248 #endif
upm_result_t mma7361_sleep(const mma7361_context dev, bool sleep)
Definition: mma7361.c:239
upm_result_t mma7361_update(const mma7361_context dev)
Definition: mma7361.c:307
void mma7361_set_offset(const mma7361_context dev, float x, float y, float z)
Definition: mma7361.c:289
upm_result_t mma7361_freefall(const mma7361_context dev, bool *freefall)
Definition: mma7361.c:256
struct _mma7361_context * mma7361_context
upm_result_t mma7361_selftest(const mma7361_context dev, bool selftest)
Definition: mma7361.c:224
void mma7361_set_range(const mma7361_context dev, bool range)
Definition: mma7361.c:268
void mma7361_close(mma7361_context dev)
Definition: mma7361.c:199
void mma7361_get_volts(const mma7361_context dev, float *x, float *y, float *z)
Definition: mma7361.c:373
void mma7361_set_scale(const mma7361_context dev, float x, float y, float z)
Definition: mma7361.c:298
mma7361_context mma7361_init(int x_pin, int y_pin, int z_pin, int selftest_pin, int sleep_pin, int freefall_pin, int range_pin, float a_ref)
Definition: mma7361.c:43
Definition: mma7361.h:47
void mma7361_get_normalized(const mma7361_context dev, float *x, float *y, float *z)
Definition: mma7361.c:388
void mma7361_get_acceleration(const mma7361_context dev, float *x, float *y, float *z)
Definition: mma7361.c:358