2016-11-18 17:32:34 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2016 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-11-18 17:32:34 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-11-18 17:32:34 -07:00
|
|
|
*/
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <ecezo.hpp>
|
|
|
|
#include <iostream>
|
2016-11-18 17:32:34 -07:00
|
|
|
#include <signal.h>
|
|
|
|
#include <upm_utilities.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace upm;
|
|
|
|
|
|
|
|
bool shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2016-11-18 17:32:34 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2016-11-18 17:32:34 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2016-11-18 17:32:34 -07:00
|
|
|
{
|
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
|
|
|
|
// Instantiate a ECEZO sensor on uart 0 at 9600 baud.
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::ECEZO sensor(0, 9600, false);
|
2016-11-18 17:32:34 -07:00
|
|
|
|
|
|
|
// For I2C, assuming the device is configured for address 0x64 on
|
|
|
|
// I2C bus 0, you could use something like:
|
|
|
|
//
|
2017-08-30 15:00:29 -07:00
|
|
|
// upm::ECEZO sensor(0, 0x64, true);
|
2016-11-18 17:32:34 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
2016-11-18 17:32:34 -07:00
|
|
|
// this will take about 1 second to complete
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.update();
|
2016-11-18 17:32:34 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "EC " << sensor.getEC() << " uS/cm, TDS " << sensor.getTDS() << " mg/L, Salinity "
|
|
|
|
<< sensor.getSalinity() << " PSS-78, SG " << sensor.getSG() << endl;
|
2016-11-18 17:32:34 -07:00
|
|
|
|
|
|
|
upm_delay(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
|
|
|
|
cout << "Exiting..." << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|