diff --git a/examples/c++/CMakeLists.txt b/examples/c++/CMakeLists.txt index 182097d2..dc1fb62c 100644 --- a/examples/c++/CMakeLists.txt +++ b/examples/c++/CMakeLists.txt @@ -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 (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280") 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-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h") diff --git a/examples/c++/adc-sensor.cxx b/examples/c++/adc-sensor.cxx index 55139268..adb11c32 100644 --- a/examples/c++/adc-sensor.cxx +++ b/examples/c++/adc-sensor.cxx @@ -24,14 +24,16 @@ #include #include -#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 EDISON_GPIO_SI7005_CS 20 //! [Interesting] -// Simple example of using IADC to determine +// Simple example of using IADC to determine // which sensor is present and return its name. // IADC is then used to get readings from sensor @@ -40,25 +42,27 @@ upm::IADC* getADC() { upm::IADC* adc = NULL; 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; } catch (std::exception& e) { - std::cerr << "ADS1015: " << e.what() << std::endl; + std::cerr << "ADS1015: " << e.what() << std::endl; } - return adc; + return adc; } int main () { upm::IADC* adc = getADC(); if (adc == NULL) { - std::cout << "ADC not detected" << std::endl; + std::cout << "ADC not detected" << std::endl; return 1; } std::cout << "ADC " << adc->getModuleName() << " detected. " ; - std::cout << adc->getNumInputs() << " inputs available" << std::endl; + std::cout << adc->getNumInputs() << " inputs available" << std::endl; while (true) { - for (int i=0; igetNumInputs(); ++i) { + for (unsigned int i=0; igetNumInputs(); ++i) { std::cout << "Input " << i; try { float voltage = adc->getVoltage(i); @@ -67,10 +71,10 @@ int main () std::cerr << e.what() << std::endl; } } - sleep(1); + sleep(1); } delete adc; return 0; } -//! [Interesting] \ No newline at end of file +//! [Interesting] diff --git a/src/ads1x15/ads1015_iadc.cxx b/src/ads1x15/ads1015_iadc.cxx index 0359941f..327355b2 100644 --- a/src/ads1x15/ads1015_iadc.cxx +++ b/src/ads1x15/ads1015_iadc.cxx @@ -1,6 +1,7 @@ /* - * Author: Marc Graham + * Author: Henry Bruce * Copyright (c) 2015 Intel Corporation. + * Based on work by Marc Graham * * Permission is hereby granted, free of charge, to any person obtaining * 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 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + #include "ads1015_iadc.h" using namespace upm; diff --git a/src/ads1x15/ads1015_iadc.h b/src/ads1x15/ads1015_iadc.h index 795152bf..bcd5fca9 100644 --- a/src/ads1x15/ads1015_iadc.h +++ b/src/ads1x15/ads1015_iadc.h @@ -1,6 +1,7 @@ /* - * Author: Marc Graham + * Author: Henry Bruce * Copyright (c) 2015 Intel Corporation. + * Based on work by Marc Graham * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -12,6 +13,7 @@ * * 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