mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
ABP: Making driver generic
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
336251740d
commit
8d43c431f2
@ -331,7 +331,7 @@ add_example (mcp2515)
|
||||
add_example (max30100)
|
||||
add_example (sensortemplate)
|
||||
add_example (p9813)
|
||||
add_example (abpdrrt005pg2a5)
|
||||
add_example (abp)
|
||||
add_example (lcdks)
|
||||
add_example (mmc35240)
|
||||
add_example (tcs37727)
|
||||
|
61
examples/c++/abp.cxx
Normal file
61
examples/c++/abp.cxx
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "abp.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 ABP sensor on i2c bus 0
|
||||
upm::ABP* abp = new upm::ABP(0, ABP_DEFAULT_ADDRESS);
|
||||
while (shouldRun) {
|
||||
abp->update();
|
||||
cout << "Retrieved pressure: " << abp->getPressure() << endl;
|
||||
cout << "Retrieved Temperature: " << abp->getTemperature() << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete abp;
|
||||
return 0;
|
||||
}
|
@ -151,7 +151,7 @@ add_example (enc03r)
|
||||
add_example (nunchuck)
|
||||
add_example (bno055)
|
||||
add_example (bmp280)
|
||||
add_example (abpdrrt005pg2a5)
|
||||
add_example (abp)
|
||||
add_example (lcdks)
|
||||
add_example (bmg160)
|
||||
add_example (bma250e)
|
||||
|
@ -27,29 +27,24 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "abpdrrt005pg2a5.h"
|
||||
#include "abp.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
abpdrrt005pg2a5_context dev = abpdrrt005pg2a5_init(0, ABPDRRT005PG2A5_ADDRESS);
|
||||
abp_context dev = abp_init(0, ABP_DEFAULT_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");
|
||||
}
|
||||
abp_update(dev);
|
||||
printf("Retrieved pressure value: %f\n", abp_get_pressure(dev));
|
||||
printf("Retrieved temperature value: %f\n", abp_get_temperature(dev));
|
||||
upm_delay(1);
|
||||
printf("PSI Value: %f and Pascal Value: %f\n", psi, pascal);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -22,14 +22,16 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var abpdrrt005pg2a5 = require("jsupm_abpdrrt005pg2a5");
|
||||
var abp = require("jsupm_abp");
|
||||
|
||||
// Instantiate a Honeywell ABP Pressure Sensor at bus 0
|
||||
var abp_sensor = new abpdrrt005pg2a5.ABPDRRT005PG2A5(0, 0x28);
|
||||
var abp_sensor = new abp.ABP(0, 0x28);
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
console.log("Pressure Pascal: " + abp_sensor.get_pressure_pascal());
|
||||
abp_sensor.update();
|
||||
console.log("Pressure: " + abp_sensor.getPressure());
|
||||
console.log("Temperature: " + abp_sensor.getTemperature());
|
||||
}, 100);
|
||||
|
||||
// When exiting: clear interval and print message
|
||||
@ -38,4 +40,4 @@ process.on('SIGINT', function()
|
||||
clearInterval(myInterval);
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
@ -23,11 +23,11 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_abpdrrt005pg2a5 as abpdrrt005pg2a5
|
||||
from upm import pyupm_abp as abp
|
||||
|
||||
def main():
|
||||
# Instantiate a Honeywell ABP Pressure sensor on the I2C bus 0
|
||||
abp_sensor = abpdrrt005pg2a5.ABPDRRT005PG2A5(0, 0x28);
|
||||
abp_sensor = abp.ABP(0, 0x28);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
@ -45,9 +45,10 @@ def main():
|
||||
|
||||
# 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)
|
||||
abp_sensor.update()
|
||||
print("Pressure: {0}".format(abp_sensor.getPressure()))
|
||||
print("Temperature: {0}".format(abp_sensor.getTemperature()))
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
8
src/abp/CMakeLists.txt
Normal file
8
src/abp/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
upm_mixed_module_init (NAME abp
|
||||
DESCRIPTION "Honeywell ABP Pressure Sensor"
|
||||
C_HDR abp.h
|
||||
C_SRC abp.c
|
||||
CPP_HDR abp.hpp
|
||||
CPP_SRC abp.cxx
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa)
|
144
src/abp/abp.c
Normal file
144
src/abp/abp.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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 "abp.h"
|
||||
|
||||
abp_context abp_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;
|
||||
}
|
||||
|
||||
abp_context dev =
|
||||
(abp_context) malloc(sizeof(struct _abp_context));
|
||||
|
||||
if (!dev)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// initialize the I2C bus
|
||||
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;
|
||||
}
|
||||
|
||||
// setting up defaults
|
||||
dev->abp_pressure_max = 5;
|
||||
dev->abp_pressure_min = 0;
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void abp_close(abp_context dev){
|
||||
free(dev);
|
||||
}
|
||||
|
||||
void abp_set_max_pressure(abp_context dev, int max) {
|
||||
dev->abp_pressure_max = max;
|
||||
}
|
||||
|
||||
void abp_set_min_pressure(abp_context dev, int min) {
|
||||
dev->abp_pressure_min = min;
|
||||
}
|
||||
|
||||
upm_result_t abp_update(abp_context dev) {
|
||||
int ret;
|
||||
|
||||
// the first 4 bytes are of interest to us
|
||||
ret = mraa_i2c_read(dev->i2c, dev->readings, 4);
|
||||
if (ret == -1)
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// the two MSBs are status bits
|
||||
// S1 S0 Status
|
||||
// 0 0 Normal operation, valid data
|
||||
// 0 1 Device in command mode
|
||||
// 1 0 Stale Data
|
||||
// 1 1 Diagnostic condition
|
||||
uint8_t status = (dev->readings[0] >> 6) & 0x03;
|
||||
if(status == 1) {
|
||||
dev->status = COMMAND_MODE;
|
||||
return UPM_ERROR_UNSPECIFIED;
|
||||
} else if(status == 2) {
|
||||
dev->status = STALE_DATA;
|
||||
return UPM_ERROR_UNSPECIFIED;
|
||||
} else if(status == 3) {
|
||||
dev->status = DIAGNOSTIC;
|
||||
return UPM_ERROR_UNSPECIFIED;
|
||||
} else
|
||||
dev->status = NORMAL_OPERATION;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
float abp_get_pressure(abp_context dev) {
|
||||
float pressure_comp;
|
||||
|
||||
if(dev->status != NORMAL_OPERATION) {
|
||||
printf("Error: Data might not be correct\n");
|
||||
}
|
||||
int output = (dev->readings[0]&ABP_PRESSURE_HIGH_BYTE_MASK)*256 + dev->readings[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_comp = ((((float)output - OUTPUT_10_PERCENT_COUNT)*
|
||||
(dev->abp_pressure_max - dev->abp_pressure_min))/
|
||||
(OUTPUT_90_PERCENT_COUNT - OUTPUT_10_PERCENT_COUNT)) +
|
||||
dev->abp_pressure_min;
|
||||
|
||||
return pressure_comp;
|
||||
}
|
||||
|
||||
float abp_get_temperature(abp_context dev) {
|
||||
float temp_comp;
|
||||
|
||||
if(dev->status != NORMAL_OPERATION) {
|
||||
printf("Error: Data might not be correct\n");
|
||||
}
|
||||
|
||||
int output = (((dev->readings[2] << 8)|(dev->readings[3])) >>
|
||||
ABP_TEMPERATURE_LOW_BYTE_SHIFT)&ABP_TEMPERATURE_MASK;
|
||||
|
||||
// Formula as per datasheet:
|
||||
// Temperature(C) = ((Output(decimal)/2047)*200) - 50
|
||||
temp_comp = (((float)output/2047)*200) - 50;
|
||||
|
||||
return temp_comp;
|
||||
}
|
@ -26,43 +26,45 @@
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "abpdrrt005pg2a5.hpp"
|
||||
#include "abp.hpp"
|
||||
|
||||
using namespace upm;
|
||||
|
||||
ABPDRRT005PG2A5::ABPDRRT005PG2A5(int bus, int devAddress) :
|
||||
m_abpdrrt005pg2a5(abpdrrt005pg2a5_init(bus, devAddress))
|
||||
ABP::ABP(int bus, int devAddress) :
|
||||
m_abp(abp_init(bus, devAddress))
|
||||
{
|
||||
if(!m_abpdrrt005pg2a5)
|
||||
if(!m_abp)
|
||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||
": abpdrrt005pg2a5_init failed");
|
||||
": abp_init failed");
|
||||
}
|
||||
|
||||
ABPDRRT005PG2A5::~ABPDRRT005PG2A5()
|
||||
ABP::~ABP()
|
||||
{
|
||||
abpdrrt005pg2a5_close(m_abpdrrt005pg2a5);
|
||||
abp_close(m_abp);
|
||||
}
|
||||
|
||||
float ABPDRRT005PG2A5::get_pressure_psi()
|
||||
void ABP::update()
|
||||
{
|
||||
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;
|
||||
if(abp_update(m_abp) != UPM_SUCCESS)
|
||||
std::cout << " ABP sensor unable to update data" << std::endl;
|
||||
}
|
||||
|
||||
float ABPDRRT005PG2A5::get_pressure_pascal()
|
||||
float ABP::getPressure()
|
||||
{
|
||||
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 abp_get_pressure(m_abp);
|
||||
}
|
||||
|
||||
return pascal_pressure;
|
||||
}
|
||||
float ABP::getTemperature()
|
||||
{
|
||||
return abp_get_temperature(m_abp);
|
||||
}
|
||||
|
||||
void ABP::setMaxPressure(int max)
|
||||
{
|
||||
abp_set_max_pressure(m_abp, max);
|
||||
}
|
||||
|
||||
void ABP::setMinPressure(int min)
|
||||
{
|
||||
abp_set_min_pressure(m_abp, min);
|
||||
}
|
141
src/abp/abp.h
Normal file
141
src/abp/abp.h
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 ABP_DEFAULT_ADDRESS 0x28
|
||||
#define OUTPUT_10_PERCENT_COUNT 1638
|
||||
#define OUTPUT_90_PERCENT_COUNT 14746
|
||||
#define ABP_PRESSURE_MAX 5
|
||||
#define ABP_PRESSURE_MIN 0
|
||||
#define ABP_PRESSURE_HIGH_BYTE_MASK 0x3f
|
||||
#define ABP_TEMPERATURE_LOW_BYTE_SHIFT 5
|
||||
#define ABP_TEMPERATURE_MASK 0x7ff
|
||||
|
||||
typedef enum {
|
||||
NORMAL_OPERATION = 0,
|
||||
COMMAND_MODE,
|
||||
STALE_DATA,
|
||||
DIAGNOSTIC } ABP_STATUS;
|
||||
|
||||
/**
|
||||
* @file abp.h
|
||||
* @library abp
|
||||
* @brief C API for the ABP Honeywell Pressure Sensor
|
||||
*
|
||||
* @include abp.c
|
||||
*/
|
||||
|
||||
typedef struct _abp_context {
|
||||
mraa_i2c_context i2c;
|
||||
uint8_t i2c_bus_number;
|
||||
uint8_t address;
|
||||
int abp_pressure_max;
|
||||
int abp_pressure_min;
|
||||
uint8_t readings[4];
|
||||
ABP_STATUS status;
|
||||
} *abp_context;
|
||||
|
||||
/**
|
||||
* ABP Initialization function
|
||||
*
|
||||
* @param bus I2C bus to use
|
||||
* @return device context pointer
|
||||
*/
|
||||
abp_context abp_init(uint8_t bus, uint8_t dev_address);
|
||||
|
||||
/**
|
||||
* ABP Close function
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
*/
|
||||
void abp_close(abp_context dev);
|
||||
|
||||
/**
|
||||
* Function to get the compensated pressure.
|
||||
* The datasheet provides a way to calculate the pressure.
|
||||
* In order to know the units take a look at the datasheet.
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
* @return float compensated pressure value
|
||||
*/
|
||||
float abp_get_pressure(abp_context dev);
|
||||
|
||||
/**
|
||||
* Function to retrieve the compensated temperature values.
|
||||
* All ABP seem to calculate temperature in degree Celsius.
|
||||
* (The above fact needs to be verified)
|
||||
* NOTE: This functionality is not available in all the ABP sensors.
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
* @return float compensated temperature value
|
||||
*/
|
||||
float abp_get_temperature(abp_context dev);
|
||||
|
||||
/**
|
||||
* Function to set the max pressure that the sensor
|
||||
* can read, can be retrieved from the datasheet, if this function is
|
||||
* not explicitly called to the set the max value, then a default max
|
||||
* value of 5 will be set.
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
* @param min int maximum pressure value possible
|
||||
*/
|
||||
void abp_set_max_pressure(abp_context dev, int max);
|
||||
|
||||
/**
|
||||
* Function to set the min pressure that the sensor
|
||||
* can read, can be retrieved from the datasheet, if this function is
|
||||
* not explicitly called to the set the min value, then a default min
|
||||
* value of 5 will be set.
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
* @param min int minimum pressure value possible
|
||||
*/
|
||||
void abp_set_min_pressure(abp_context dev, int min);
|
||||
|
||||
/**
|
||||
* This function has to be called before calling either of the get
|
||||
* temperature or get pressure functions. This function updates the
|
||||
* device context with the latest values. Not calling this function
|
||||
* will lead to stale values.
|
||||
*
|
||||
* @param dev abp_context pointer
|
||||
*/
|
||||
upm_result_t abp_update(abp_context dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
126
src/abp/abp.hpp
Normal file
126
src/abp/abp.hpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 "abp.h"
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @defgroup abp libupm-abp
|
||||
* @ingroup honeywell i2c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library abp
|
||||
* @sensor abp
|
||||
* @comname ABP Honeywell Pressure and Temperature 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 ABP Honeywell Pressure and Temp
|
||||
* 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 driver is possible
|
||||
* but not all ABP sensors support that functionality.
|
||||
*
|
||||
* NOTE: This driver supports only the I2C based ABP sensors, it does
|
||||
* not currently support SPI and Analog based sensors.
|
||||
*
|
||||
* @image html abp.jpg
|
||||
* @snippet abp.cxx Interesting
|
||||
*/
|
||||
|
||||
class ABP {
|
||||
|
||||
public:
|
||||
/**
|
||||
* ABP constructor
|
||||
*
|
||||
* @param bus i2c bus to be used
|
||||
* @param devAddress i2c address of the sensor
|
||||
*/
|
||||
ABP(int bus, int devAddress);
|
||||
/**
|
||||
* ABP destructor
|
||||
*/
|
||||
~ABP();
|
||||
/**
|
||||
* Function to get the compensated pressure.
|
||||
* The datasheet provides a way to calculate the pressure.
|
||||
* In order to know the units take a look at the datasheet.
|
||||
*
|
||||
* @return float compensated temperature value
|
||||
*/
|
||||
float getPressure();
|
||||
|
||||
/**
|
||||
* Function to retrieve the compensated temperature values.
|
||||
* All ABP seem to calculate temperature in degree Celsius.
|
||||
* (The above fact needs to be verified)
|
||||
* NOTE: This functionality is not available in all the ABP sensors.
|
||||
*
|
||||
* @return float compensated temperature value
|
||||
*/
|
||||
float getTemperature();
|
||||
|
||||
/**
|
||||
* This functio has to be called before calling either of the get
|
||||
* temperature or get pressure functions. This function updates the
|
||||
* device context with the latest values. Not calling this function
|
||||
* will lead to stale values.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Function to set the max pressure that the sensor
|
||||
* can read, can be retrieved from the datasheet, if this function is
|
||||
* not explicitly called to the set the min value, then a default max
|
||||
* value of 5 will be set.
|
||||
*
|
||||
* @param min int minimum pressure value possible
|
||||
*/
|
||||
void setMaxPressure(int max);
|
||||
|
||||
/**
|
||||
* Function to set the min pressure that the sensor
|
||||
* can read, can be retrieved from the datasheet, if this function is
|
||||
* not explicitly called to the set the min value, then a default min
|
||||
* value of 0 will be set.
|
||||
*
|
||||
* @param min int minimum pressure value possible
|
||||
*/
|
||||
void setMinPressure(int min);
|
||||
private:
|
||||
abp_context m_abp;
|
||||
ABP(const ABP& src) { /* do not create copied constructor */}
|
||||
ABP& operator=(const ABP&) {return *this;}
|
||||
};
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
%module javaupm_abpdrrt005pg2a5
|
||||
%module javaupm_abp
|
||||
%include "../upm.i"
|
||||
%include "stdint.i"
|
||||
%include "typemaps.i"
|
||||
|
||||
%{
|
||||
#include "abpdrrt005pg2a5.hpp"
|
||||
#include "abp.hpp"
|
||||
%}
|
||||
%include "abpdrrt005pg2a5.hpp"
|
||||
%include "abp.hpp"
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_abpdrrt005pg2a5");
|
||||
System.loadLibrary("javaupm_abp");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
8
src/abp/jsupm_abp.i
Normal file
8
src/abp/jsupm_abp.i
Normal file
@ -0,0 +1,8 @@
|
||||
%module jsupm_abp
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "abp.hpp"
|
||||
%}
|
||||
|
||||
%include "abp.hpp"
|
@ -1,11 +1,11 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_abpdrrt005pg2a5
|
||||
%module pyupm_abp
|
||||
%include "../upm.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%include "abpdrrt005pg2a5.hpp"
|
||||
%include "abp.hpp"
|
||||
%{
|
||||
#include "abpdrrt005pg2a5.hpp"
|
||||
#include "abp.hpp"
|
||||
%}
|
@ -1,8 +0,0 @@
|
||||
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)
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
};
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
%module jsupm_abpdrrt005pg2a5
|
||||
%include "../upm.i"
|
||||
|
||||
%{
|
||||
#include "abpdrrt005pg2a5.hpp"
|
||||
%}
|
||||
|
||||
%include "abpdrrt005pg2a5.hpp"
|
Loading…
x
Reference in New Issue
Block a user