2014-06-04 14:57:19 +00:00
|
|
|
/*
|
|
|
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
|
|
|
|
* Copyright (c) 2014 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.
|
2014-06-04 14:57:19 +00:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-06-04 14:57:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
|
|
|
#include "hcsr04.hpp"
|
|
|
|
#include "upm_utilities.h"
|
2014-06-04 14:57:19 +00:00
|
|
|
|
2017-06-07 10:46:57 -07:00
|
|
|
int shouldRun = true;
|
2014-06-04 14:57:19 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
|
|
|
{
|
|
|
|
if (signo == SIGINT) {
|
2017-06-07 10:46:57 -07:00
|
|
|
shouldRun = false;
|
2014-06-04 14:57:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 07:24:56 +00:00
|
|
|
//! [Interesting]
|
2014-06-04 14:57:19 +00:00
|
|
|
int
|
2017-08-30 15:00:29 -07:00
|
|
|
main(int argc, char** argv)
|
2014-06-04 14:57:19 +00:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::HCSR04 sonar(2, 4);
|
2014-06-04 14:57:19 +00:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(1);
|
2015-08-27 22:39:09 -03:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
2015-08-27 22:39:09 -03:00
|
|
|
std::cout << "get distance" << std::endl;
|
2017-08-30 15:00:29 -07:00
|
|
|
double distance = sonar.getDistance(HCSR04_CM);
|
2015-08-27 22:39:09 -03:00
|
|
|
std::cout << "distance " << distance << std::endl;
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(2);
|
2015-08-27 22:39:09 -03:00
|
|
|
}
|
2017-06-07 10:46:57 -07:00
|
|
|
std::cout << "Exiting... " << std::endl;
|
2014-06-04 14:57:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-10 07:24:56 +00:00
|
|
|
//! [Interesting]
|