2016-01-06 15:32:56 -08:00
|
|
|
/*
|
|
|
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2016-01-06 15:32:56 -08:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-01-06 15:32:56 -08:00
|
|
|
*/
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <exception>
|
2016-01-06 15:32:56 -08:00
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "ads1015.hpp"
|
2016-01-07 14:12:33 -08:00
|
|
|
#include "mraa/gpio.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2016-01-06 15:32:56 -08:00
|
|
|
|
2016-01-07 14:12:33 -08:00
|
|
|
#define EDISON_I2C_BUS 1
|
2016-01-06 15:32:56 -08:00
|
|
|
#define FT4222_I2C_BUS 0
|
2016-01-07 14:12:33 -08:00
|
|
|
#define EDISON_GPIO_SI7005_CS 20
|
2016-01-06 15:32:56 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
/* Create an instance of the ADS1015 sensor */
|
2018-09-27 17:33:40 +03:00
|
|
|
upm::ADS1015 adc(EDISON_I2C_BUS);
|
2017-08-30 15:00:29 -07:00
|
|
|
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
|
|
|
gpio.dir(mraa::DIR_OUT_HIGH);
|
2016-01-06 15:32:56 -08:00
|
|
|
|
2018-09-27 17:33:40 +03:00
|
|
|
// if (adc == NULL) {
|
|
|
|
// std::cout << "ADC not detected" << std::endl;
|
|
|
|
// return 1;
|
|
|
|
// }
|
|
|
|
std::cout << "ADC " << adc.getModuleName() << " detected. ";
|
|
|
|
std::cout << adc.getNumInputs() << " inputs available" << std::endl;
|
2017-08-30 15:00:29 -07:00
|
|
|
while (true) {
|
2018-09-27 17:33:40 +03:00
|
|
|
for (unsigned int i = 0; i < adc.getNumInputs(); ++i) {
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << "Input " << i;
|
|
|
|
try {
|
2018-09-27 17:33:40 +03:00
|
|
|
float voltage = adc.getVoltage(i);
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << ": Voltage = " << voltage << "V" << std::endl;
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upm_delay(1);
|
|
|
|
}
|
2016-01-06 15:32:56 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2016-01-06 15:32:56 -08:00
|
|
|
}
|
|
|
|
|
2016-01-07 14:12:33 -08:00
|
|
|
//! [Interesting]
|