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:
Abhishek Malik
2017-03-08 23:28:45 -08:00
parent cc0174910b
commit d965b92af1
14 changed files with 614 additions and 0 deletions

View 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)

View 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;
}

View 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;
}

View 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

View 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;
};
}

View 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);
}
}
%}

View File

@ -0,0 +1,8 @@
%module jsupm_abpdrrt005pg2a5
%include "../upm.i"
%{
#include "abpdrrt005pg2a5.hpp"
%}
%include "abpdrrt005pg2a5.hpp"

View 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"
%}