2015-12-16 16:26:25 -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.
|
2015-12-16 16:26:25 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-12-16 16:26:25 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-04-29 16:41:49 -07:00
|
|
|
#include "ds2413.hpp"
|
2015-12-16 16:26:25 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace upm;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2015-12-16 16:26:25 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
|
|
|
|
upm::DS2413 sensor(0);
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// find all of the DS2413 devices present on the bus
|
|
|
|
sensor.init();
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// how many devices were found?
|
|
|
|
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// read the gpio and latch values from the first device
|
|
|
|
// the lower 4 bits are of the form:
|
|
|
|
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
|
|
|
|
cout << "GPIO device 0 values: " << sensor.readGpios(0) << endl;
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// set the gpio latch values of the first device
|
|
|
|
cout << "Setting GPIO latches to on" << endl;
|
|
|
|
sensor.writeGpios(0, 0x03);
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2015-12-16 16:26:25 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
return 0;
|
2015-12-16 16:26:25 -07:00
|
|
|
}
|