mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
examples: Updated IADC example to use updated interface
Signed-off-by: Henry Bruce <henry.bruce@intel.com> Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
bbdbe56355
commit
4220dd25b4
@ -262,6 +262,6 @@ add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bm
|
|||||||
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
||||||
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
|
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
|
||||||
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||||
#add_custom_example (adc-example adc-sensor.cxx ads1015)
|
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||||
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||||
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||||
|
@ -24,14 +24,16 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "ads1015.h"
|
#include "ads1015_iadc.h"
|
||||||
|
#include "mraa/gpio.hpp"
|
||||||
|
|
||||||
#define EDISON_I2C_BUS 1
|
#define EDISON_I2C_BUS 1
|
||||||
#define FT4222_I2C_BUS 0
|
#define FT4222_I2C_BUS 0
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Simple example of using IADC to determine
|
// Simple example of using IADC to determine
|
||||||
// which sensor is present and return its name.
|
// which sensor is present and return its name.
|
||||||
// IADC is then used to get readings from sensor
|
// IADC is then used to get readings from sensor
|
||||||
|
|
||||||
@ -40,25 +42,27 @@ upm::IADC* getADC()
|
|||||||
{
|
{
|
||||||
upm::IADC* adc = NULL;
|
upm::IADC* adc = NULL;
|
||||||
try {
|
try {
|
||||||
adc = new upm::ADS1015(EDISON_I2C_BUS);
|
adc = new upm::ADS1015_IADC(EDISON_I2C_BUS);
|
||||||
|
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
||||||
|
gpio.dir(mraa::DIR_OUT_HIGH);
|
||||||
return adc;
|
return adc;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
std::cerr << "ADS1015: " << e.what() << std::endl;
|
std::cerr << "ADS1015: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
upm::IADC* adc = getADC();
|
upm::IADC* adc = getADC();
|
||||||
if (adc == NULL) {
|
if (adc == NULL) {
|
||||||
std::cout << "ADC not detected" << std::endl;
|
std::cout << "ADC not detected" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
||||||
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
for (int i=0; i<adc->getNumInputs(); ++i) {
|
for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
|
||||||
std::cout << "Input " << i;
|
std::cout << "Input " << i;
|
||||||
try {
|
try {
|
||||||
float voltage = adc->getVoltage(i);
|
float voltage = adc->getVoltage(i);
|
||||||
@ -67,10 +71,10 @@ int main ()
|
|||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
delete adc;
|
delete adc;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Author: Marc Graham <marc@m2ag.net>
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
* Based on work by Marc Graham <marc@m2ag.net>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -21,6 +22,7 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ads1015_iadc.h"
|
#include "ads1015_iadc.h"
|
||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Author: Marc Graham <marc@m2ag.net>
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
* Copyright (c) 2015 Intel Corporation.
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
* Based on work by Marc Graham <marc@m2ag.net>
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@ -12,6 +13,7 @@
|
|||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be
|
* The above copyright notice and this permission notice shall be
|
||||||
* included in all copies or substantial portions of the Software.
|
* included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user