mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
ABPDRRT005PG2A5: Initial Commit
This commit enables the ABP Honeywell sensor. Java examples is yet to be tested and has not been provided with the current commit and will be provided in a future commit. Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
cc0174910b
commit
d965b92af1
@ -331,6 +331,7 @@ add_example (mcp2515)
|
|||||||
add_example (max30100)
|
add_example (max30100)
|
||||||
add_example (sensortemplate)
|
add_example (sensortemplate)
|
||||||
add_example (p9813)
|
add_example (p9813)
|
||||||
|
add_example (abpdrrt005pg2a5)
|
||||||
|
|
||||||
# These are special cases where you specify example binary, source file and module(s)
|
# These are special cases where you specify example binary, source file and module(s)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||||
|
66
examples/c++/abpdrrt005pg2a5.cxx
Normal file
66
examples/c++/abpdrrt005pg2a5.cxx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "abpdrrt005pg2a5.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate an A110X sensor on digital pin D2
|
||||||
|
upm::ABPDRRT005PG2A5* abp = new upm::ABPDRRT005PG2A5(0, ABPDRRT005PG2A5_ADDRESS);
|
||||||
|
|
||||||
|
// check every second for the presence of a magnetic field (south
|
||||||
|
// polarity)
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
float x = abp->get_pressure_psi();
|
||||||
|
cout << "psi pressure: " << x << endl;
|
||||||
|
float y = abp->get_pressure_pascal();
|
||||||
|
cout << "pascal pressure: " << y << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete abp;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -151,6 +151,7 @@ add_example (enc03r)
|
|||||||
add_example (nunchuck)
|
add_example (nunchuck)
|
||||||
add_example (bno055)
|
add_example (bno055)
|
||||||
add_example (bmp280)
|
add_example (bmp280)
|
||||||
|
add_example (abpdrrt005pg2a5)
|
||||||
|
|
||||||
# Custom examples
|
# Custom examples
|
||||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||||
|
55
examples/c/abpdrrt005pg2a5.c
Normal file
55
examples/c/abpdrrt005pg2a5.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "abpdrrt005pg2a5.h"
|
||||||
|
|
||||||
|
#include "upm_utilities.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
abpdrrt005pg2a5_context dev = abpdrrt005pg2a5_init(0, ABPDRRT005PG2A5_ADDRESS);
|
||||||
|
if(dev == NULL) {
|
||||||
|
printf("Unable to initialize sensor\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
float psi = 0;
|
||||||
|
float pascal = 0;
|
||||||
|
while(1){
|
||||||
|
if(abpdrrt005pg2a5_get_pressure_psi(dev, &psi) != UPM_SUCCESS){
|
||||||
|
printf("error in retrieving the psi value\n");
|
||||||
|
}
|
||||||
|
if(abpdrrt005pg2a5_get_pressure_pascal(dev, &pascal) != UPM_SUCCESS){
|
||||||
|
printf("error in retrieving the pascal value\n");
|
||||||
|
}
|
||||||
|
upm_delay(1);
|
||||||
|
printf("PSI Value: %f and Pascal Value: %f\n", psi, pascal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
41
examples/javascript/abpdrrt005pg2a5.js
Normal file
41
examples/javascript/abpdrrt005pg2a5.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var abpdrrt005pg2a5 = require("jsupm_abpdrrt005pg2a5");
|
||||||
|
|
||||||
|
// Instantiate a Honeywell ABP Pressure Sensor at bus 0
|
||||||
|
var abp_sensor = new abpdrrt005pg2a5.ABPDRRT005PG2A5(0, 0x28);
|
||||||
|
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
console.log("Pressure Pascal: " + abp_sensor.get_pressure_pascal());
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
// When exiting: clear interval and print message
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
53
examples/python/abpdrrt005pg2a5.py
Normal file
53
examples/python/abpdrrt005pg2a5.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
# Copyright (c) 2017 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
from upm import pyupm_abpdrrt005pg2a5 as abpdrrt005pg2a5
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Instantiate a Honeywell ABP Pressure sensor on the I2C bus 0
|
||||||
|
abp_sensor = abpdrrt005pg2a5.ABPDRRT005PG2A5(0, 0x28);
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit, including functions from abpdrrt005pg2a5
|
||||||
|
def exitHandler():
|
||||||
|
print("Exiting")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
# Read the value every second and detect the pressure
|
||||||
|
while(1):
|
||||||
|
print("Pressure PSI: {0}".format(abp_sensor.get_pressure_psi()))
|
||||||
|
print("Pressure Pascal: {0}".format(abp_sensor.get_pressure_pascal()))
|
||||||
|
time.sleep(.1)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
8
src/abpdrrt005pg2a5/CMakeLists.txt
Normal file
8
src/abpdrrt005pg2a5/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
upm_mixed_module_init (NAME abpdrrt005pg2a5
|
||||||
|
DESCRIPTION "Honeywell ABP Pressure Sensor"
|
||||||
|
C_HDR abpdrrt005pg2a5.h
|
||||||
|
C_SRC abpdrrt005pg2a5.c
|
||||||
|
CPP_HDR abpdrrt005pg2a5.hpp
|
||||||
|
CPP_SRC abpdrrt005pg2a5.cxx
|
||||||
|
CPP_WRAPS_C
|
||||||
|
REQUIRES mraa)
|
102
src/abpdrrt005pg2a5/abpdrrt005pg2a5.c
Normal file
102
src/abpdrrt005pg2a5/abpdrrt005pg2a5.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "abpdrrt005pg2a5.h"
|
||||||
|
|
||||||
|
abpdrrt005pg2a5_context abpdrrt005pg2a5_init(uint8_t bus, uint8_t dev_address){
|
||||||
|
// make sure MRAA is initialized
|
||||||
|
int mraa_rv;
|
||||||
|
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
||||||
|
{
|
||||||
|
printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
abpdrrt005pg2a5_context dev =
|
||||||
|
(abpdrrt005pg2a5_context) malloc(sizeof(struct _abpdrrt005pg2a5_context));
|
||||||
|
|
||||||
|
if (!dev)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev->i2c_bus_number = bus;
|
||||||
|
dev->address = dev_address;
|
||||||
|
|
||||||
|
dev->i2c = mraa_i2c_init(dev->i2c_bus_number);
|
||||||
|
if (dev->i2c == NULL){
|
||||||
|
free(dev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS)
|
||||||
|
{
|
||||||
|
mraa_i2c_stop(dev->i2c);
|
||||||
|
free(dev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
void abpdrrt005pg2a5_close(abpdrrt005pg2a5_context dev){
|
||||||
|
free(dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
upm_result_t abpdrrt005pg2a5_get_pressure_psi(abpdrrt005pg2a5_context dev, float* pressure_psi){
|
||||||
|
uint8_t temp[2];
|
||||||
|
int output;
|
||||||
|
|
||||||
|
int16_t ret = mraa_i2c_read_word_data(dev->i2c, ABPDRRT005PG2A5_ADDRESS);
|
||||||
|
if(ret == -1)
|
||||||
|
return UPM_ERROR_OPERATION_FAILED;
|
||||||
|
|
||||||
|
temp[0] = (uint8_t) ret; // msb
|
||||||
|
temp[1] = (uint8_t)(ret >> 8); // lsb
|
||||||
|
// Status bits should be 0 and 0, other values might mean a different mode or a wrong value
|
||||||
|
uint8_t status = (temp[0] >> 6) & 0x03;
|
||||||
|
if(status != 0)
|
||||||
|
return UPM_ERROR_UNSPECIFIED;
|
||||||
|
output = temp[0]*256 + temp[1];
|
||||||
|
|
||||||
|
// Formula as per the data sheet
|
||||||
|
// output(% of 2^14 counts) = (((output(90% counts) - output(10% counts))/Pmax - Pmin)*(Papplied - Pmin)) + output(10% count)
|
||||||
|
// based on the formula we can calculate the pressure
|
||||||
|
// Papplied = ((output(counts) - output(10% count))*(Pmax - Pmin))/(output(90% counts) - output(10% counts)) + Pmin
|
||||||
|
*pressure_psi = ((((float)output - OUTPUT_10_PERCENT_COUNT)*(ABPDRRT005PG2A5_PRESSURE_MAX - ABPDRRT005PG2A5_PRESSURE_MIN))/(OUTPUT_90_PERCENT_COUNT - OUTPUT_10_PERCENT_COUNT)) + ABPDRRT005PG2A5_PRESSURE_MIN;
|
||||||
|
|
||||||
|
return UPM_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
upm_result_t abpdrrt005pg2a5_get_pressure_pascal(abpdrrt005pg2a5_context dev, float* pressure_pascal){
|
||||||
|
float int_pressure;
|
||||||
|
|
||||||
|
if(abpdrrt005pg2a5_get_pressure_psi(dev, &int_pressure) != UPM_SUCCESS){
|
||||||
|
return UPM_ERROR_OPERATION_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conversion obtained from google
|
||||||
|
*pressure_pascal = 6894.75729*int_pressure;
|
||||||
|
|
||||||
|
return UPM_SUCCESS;
|
||||||
|
}
|
68
src/abpdrrt005pg2a5/abpdrrt005pg2a5.cxx
Normal file
68
src/abpdrrt005pg2a5/abpdrrt005pg2a5.cxx
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "abpdrrt005pg2a5.hpp"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
ABPDRRT005PG2A5::ABPDRRT005PG2A5(int bus, int devAddress) :
|
||||||
|
m_abpdrrt005pg2a5(abpdrrt005pg2a5_init(bus, devAddress))
|
||||||
|
{
|
||||||
|
if(!m_abpdrrt005pg2a5)
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": abpdrrt005pg2a5_init failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
ABPDRRT005PG2A5::~ABPDRRT005PG2A5()
|
||||||
|
{
|
||||||
|
abpdrrt005pg2a5_close(m_abpdrrt005pg2a5);
|
||||||
|
}
|
||||||
|
|
||||||
|
float ABPDRRT005PG2A5::get_pressure_psi()
|
||||||
|
{
|
||||||
|
float psi_pressure;
|
||||||
|
if(abpdrrt005pg2a5_get_pressure_psi(m_abpdrrt005pg2a5, &psi_pressure) != UPM_SUCCESS) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": abpdrrt005pg2a5_get_pressure_psi unable to get " +
|
||||||
|
"pressure from sensor");
|
||||||
|
}
|
||||||
|
|
||||||
|
return psi_pressure;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ABPDRRT005PG2A5::get_pressure_pascal()
|
||||||
|
{
|
||||||
|
float pascal_pressure;
|
||||||
|
if(abpdrrt005pg2a5_get_pressure_pascal(m_abpdrrt005pg2a5, &pascal_pressure) != UPM_SUCCESS) {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": abpdrrt005pg2a5_get_pressure_pascal unable to get " +
|
||||||
|
"pressure from sensor");
|
||||||
|
}
|
||||||
|
|
||||||
|
return pascal_pressure;
|
||||||
|
}
|
92
src/abpdrrt005pg2a5/abpdrrt005pg2a5.h
Normal file
92
src/abpdrrt005pg2a5/abpdrrt005pg2a5.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "upm.h"
|
||||||
|
#include "mraa/i2c.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ABPDRRT005PG2A5_ADDRESS 0x28
|
||||||
|
#define OUTPUT_10_PERCENT_COUNT 1638
|
||||||
|
#define OUTPUT_90_PERCENT_COUNT 14746
|
||||||
|
#define ABPDRRT005PG2A5_PRESSURE_MAX 5
|
||||||
|
#define ABPDRRT005PG2A5_PRESSURE_MIN 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file abpdrrt005pg2a5.h
|
||||||
|
* @library abpdrrt005pg2a5
|
||||||
|
* @brief C API for the ABPDRRT005PG2A5 Honeywell Pressure Sensor
|
||||||
|
*
|
||||||
|
* @include abpdrrt005pg2a5.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _abpdrrt005pg2a5_context {
|
||||||
|
mraa_i2c_context i2c;
|
||||||
|
uint8_t i2c_bus_number;
|
||||||
|
uint8_t address;
|
||||||
|
} *abpdrrt005pg2a5_context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ABPDRRT005PG2A5 Initialization function
|
||||||
|
*
|
||||||
|
* @param bus I2C bus to use
|
||||||
|
* @return device context pointer
|
||||||
|
*/
|
||||||
|
abpdrrt005pg2a5_context abpdrrt005pg2a5_init(uint8_t bus, uint8_t dev_address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ABPDRRT005PG2A5 Close function
|
||||||
|
*
|
||||||
|
* @param dev abpdrrt005pg2a5_context pointer
|
||||||
|
*/
|
||||||
|
void abpdrrt005pg2a5_close(abpdrrt005pg2a5_context dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to get the pressure in psi
|
||||||
|
* The datasheet provides a way to calculate the pressure
|
||||||
|
* in psi.
|
||||||
|
*
|
||||||
|
* @return upm_result_t UPM success/error code
|
||||||
|
*/
|
||||||
|
upm_result_t abpdrrt005pg2a5_get_pressure_psi(abpdrrt005pg2a5_context dev, float* pressure_psi);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to get the pressure in pascal
|
||||||
|
* This is calculated using a conversion function.
|
||||||
|
*
|
||||||
|
* @return upm_result_t UPM success/error code
|
||||||
|
*/
|
||||||
|
upm_result_t abpdrrt005pg2a5_get_pressure_pascal(abpdrrt005pg2a5_context dev, float* pressure_pascal);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
88
src/abpdrrt005pg2a5/abpdrrt005pg2a5.hpp
Normal file
88
src/abpdrrt005pg2a5/abpdrrt005pg2a5.hpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2017 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "abpdrrt005pg2a5.h"
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
/**
|
||||||
|
* @defgroup abpdrrt005pg2a5 libupm-abpdrrt005pg2a5
|
||||||
|
* @ingroup honeywell i2c
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library abpdrrt005pg2a5
|
||||||
|
* @sensor abpdrrt005pg2a5
|
||||||
|
* @comname ABP Honeywell Pressure Sensor
|
||||||
|
* @type other
|
||||||
|
* @man Honeywell
|
||||||
|
* @web https://sensing.honeywell.com/honeywell-sensing-basic-board-mount-pressure-sensors-abp-series-datasheet-323005128-c-en.pdf
|
||||||
|
* @con i2c
|
||||||
|
* @kit other
|
||||||
|
*
|
||||||
|
* @brief API for the ABP Honeywell Pressure Sensor
|
||||||
|
*
|
||||||
|
* This is the UPM Module for the ABPDRRT005PG2A5 Honeywell Pressure
|
||||||
|
* sensor. This sensor uses an onboard ASIC to output values
|
||||||
|
* of pressure that are updated at approximately 2 KHz. It is capable
|
||||||
|
* of detecting pressure in the 0-5 psi range and it has an i2c
|
||||||
|
* based interface. Temperature calculation using this sensor
|
||||||
|
* is not recommended as the values are not calibrated.
|
||||||
|
*
|
||||||
|
* @image html abpdrrt005pg2a5.jpg
|
||||||
|
* @snippet abpdrrt005pg2a5.cxx Interesting
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ABPDRRT005PG2A5 {
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* ABPDRRT005PG2A5 constructor
|
||||||
|
*
|
||||||
|
* @param bus i2c bus to be used
|
||||||
|
* @param devAddress i2c address of the sensor
|
||||||
|
*/
|
||||||
|
ABPDRRT005PG2A5(int bus, int devAddress);
|
||||||
|
/**
|
||||||
|
* ABPDRRT005PG2A5 destructor
|
||||||
|
*/
|
||||||
|
~ABPDRRT005PG2A5();
|
||||||
|
/**
|
||||||
|
* Get pressure in pounds per square inch
|
||||||
|
*
|
||||||
|
* @return pressure in psi
|
||||||
|
*/
|
||||||
|
float get_pressure_psi();
|
||||||
|
/**
|
||||||
|
* Get pressure in pascals
|
||||||
|
*
|
||||||
|
* @return pressure in pascal
|
||||||
|
*/
|
||||||
|
float get_pressure_pascal();
|
||||||
|
|
||||||
|
private:
|
||||||
|
abpdrrt005pg2a5_context m_abpdrrt005pg2a5;
|
||||||
|
};
|
||||||
|
}
|
20
src/abpdrrt005pg2a5/javaupm_abpdrrt005pg2a5.i
Normal file
20
src/abpdrrt005pg2a5/javaupm_abpdrrt005pg2a5.i
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
%module javaupm_abpdrrt005pg2a5
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "stdint.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "abpdrrt005pg2a5.hpp"
|
||||||
|
%}
|
||||||
|
%include "abpdrrt005pg2a5.hpp"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_abpdrrt005pg2a5");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
8
src/abpdrrt005pg2a5/jsupm_abpdrrt005pg2a5.i
Normal file
8
src/abpdrrt005pg2a5/jsupm_abpdrrt005pg2a5.i
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
%module jsupm_abpdrrt005pg2a5
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "abpdrrt005pg2a5.hpp"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "abpdrrt005pg2a5.hpp"
|
11
src/abpdrrt005pg2a5/pyupm_abpdrrt005pg2a5.i
Normal file
11
src/abpdrrt005pg2a5/pyupm_abpdrrt005pg2a5.i
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
%module pyupm_abpdrrt005pg2a5
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
%include "abpdrrt005pg2a5.hpp"
|
||||||
|
%{
|
||||||
|
#include "abpdrrt005pg2a5.hpp"
|
||||||
|
%}
|
Loading…
x
Reference in New Issue
Block a user