ABP: Making driver generic

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2017-04-04 13:38:28 -07:00
parent 336251740d
commit 8d43c431f2
19 changed files with 544 additions and 354 deletions

View File

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

View File

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

View File

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

View File

@ -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);
});
});

View File

@ -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()