upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
abp.h
Go to the documentation of this file.
1 /*
2  * Author: Abhishek Malik <abhishek.malik@intel.com>
3  * Copyright (c) 2017 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 #pragma once
25 
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include "upm.h"
32 #include "mraa/i2c.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define ABP_DEFAULT_ADDRESS 0x28
39 #define OUTPUT_10_PERCENT_COUNT 1638
40 #define OUTPUT_90_PERCENT_COUNT 14746
41 #define ABP_PRESSURE_MAX 5
42 #define ABP_PRESSURE_MIN 0
43 #define ABP_PRESSURE_HIGH_BYTE_MASK 0x3f
44 #define ABP_TEMPERATURE_LOW_BYTE_SHIFT 5
45 #define ABP_TEMPERATURE_MASK 0x7ff
46 
47 typedef enum {
48  NORMAL_OPERATION = 0,
49  COMMAND_MODE,
50  STALE_DATA,
51  DIAGNOSTIC } ABP_STATUS;
52 
61 typedef struct _abp_context {
62  mraa_i2c_context i2c;
63  int i2c_bus_number;
64  uint8_t address;
65  int abp_pressure_max;
66  int abp_pressure_min;
67  uint8_t readings[4];
68  ABP_STATUS status;
69 } *abp_context;
70 
77 abp_context abp_init(int bus, uint8_t dev_address);
78 
84 void abp_close(abp_context dev);
85 
94 float abp_get_pressure(abp_context dev);
95 
106 
116 void abp_set_max_pressure(abp_context dev, int max);
117 
127 void abp_set_min_pressure(abp_context dev, int min);
128 
137 upm_result_t abp_update(abp_context dev);
138 
139 #ifdef __cplusplus
140 }
141 #endif
void abp_close(abp_context dev)
Definition: abp.c:67
float abp_get_temperature(abp_context dev)
Definition: abp.c:129
void abp_set_min_pressure(abp_context dev, int min)
Definition: abp.c:75
float abp_get_pressure(abp_context dev)
Definition: abp.c:109
upm_result_t abp_update(abp_context dev)
Definition: abp.c:79
abp_context abp_init(int bus, uint8_t dev_address)
Definition: abp.c:26
void abp_set_max_pressure(abp_context dev, int max)
Definition: abp.c:71
Definition: abp.h:61