2016-12-02 16:42:33 -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-12-02 16:42:33 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-12-02 16:42:33 -07:00
|
|
|
*/
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <mb704x.hpp>
|
2016-12-02 16:42:33 -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-12-02 16:42:33 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2016-12-02 16:42:33 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2016-12-02 16:42:33 -07:00
|
|
|
{
|
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2016-12-02 16:42:33 -07:00
|
|
|
|
|
|
|
// Instantiate a MB704X sensor using default parameters (bus 0,
|
|
|
|
// address 112)
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::MB704X sensor;
|
2016-12-02 16:42:33 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
|
|
|
cout << "Range: " << sensor.getRange() << " cm" << endl;
|
2016-12-02 16:42:33 -07:00
|
|
|
|
|
|
|
upm_delay_ms(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Exiting..." << endl;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2016-12-02 16:42:33 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|