RSC: Initial Commit

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2017-04-02 23:04:04 -07:00
parent b239866e99
commit 96eb834e9b
15 changed files with 1688 additions and 0 deletions

View File

@ -342,6 +342,7 @@ add_example (hdc1000)
add_example (bmg160)
add_example (bma250e)
add_example (bmm150)
add_example (rsc)
# These are special cases where you specify example binary, source file and module(s)
include_directories (${PROJECT_SOURCE_DIR}/src)

64
examples/c++/rsc.cxx Normal file
View File

@ -0,0 +1,64 @@
/*
* 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 "rsc.hpp"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main ()
{
signal(SIGINT, sig_handler);
//! [Interesting]
upm::RSC* rsc = new upm::RSC(0, 9, 8);
cout << "Sensor Name: " << rsc->getSensorName() << endl;
rsc->setMode(NORMAL_MODE);
rsc->setDataRate(N_DR_330_SPS);
while (shouldRun) {
cout << "inH2O pressure: " << rsc->getPressure() << endl;
cout << "Temp (C): " << rsc->getTemperature() << endl;
sleep(1);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete rsc;
return 0;
}

View File

@ -156,6 +156,7 @@ add_example (lcdks)
add_example (bmg160)
add_example (bma250e)
add_example (bmm150)
add_example (rsc)
# Custom examples
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)

47
examples/c/rsc.c Normal file
View File

@ -0,0 +1,47 @@
/*
* 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 "upm_utilities.h"
#include "rsc.h"
int main(void) {
//! [Interesting]
rsc_context dev = rsc_init(0, 9, 8);
rsc_set_data_rate(dev, N_DR_330_SPS);
rsc_set_mode(dev, NORMAL_MODE);
float pressure;
float temp;
while(1){
pressure = rsc_get_pressure(dev);
printf("Retrieved pressure: %f %d\n", pressure, dev->unit);
temp = rsc_get_temperature(dev);
printf("Retieved temperature: %f C\n", temp);
upm_delay_ms(500);
}
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,45 @@
/*
* 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 rsc = require("jsupm_rsc");
// Instantiate a Honeywell RSC Pressure Sensor at bus 0
var rsc_sensor = new rsc.RSC(0, 9, 8);
console.log("Sensor Name: " + rsc_sensor.getSensorName());
console.log("Sensor Serial No.: " + rsc_sensor.getSensorSerialNumber());
var myInterval = setInterval(function()
{
console.log("Pressure: " + rsc_sensor.getPressure() + " " + rsc_sensor.getPressureUnit());
console.log("Temperature: " + rsc_sensor.getTemperature() + " C");
}, 100);
// When exiting: clear interval and print message
process.on('SIGINT', function()
{
clearInterval(myInterval);
console.log("Exiting...");
process.exit(0);
});

55
examples/python/rsc.py Normal file
View File

@ -0,0 +1,55 @@
#!/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_rsc as rsc
def main():
# Instantiate a Honeywell RSC Pressure sensor on the SPI bus 0
rsc_sensor = rsc.RSC(0, 9, 8);
## 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
print("Sensor Name: {0}".format(rsc_sensor.getSensorName()))
print("Sensor Serial Number: {0}".format(rsc_sensor.getSensorSerialNumber()))
while(1):
print("Pressure {0}: {1}".format(rsc_sensor.getPressureUnit(), rsc_sensor.getPressure()))
print("Temperature C: {0}".format(rsc_sensor.getTemperature()))
time.sleep(1)
if __name__ == '__main__':
main()