mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
HCSR04: Modifying implementation and adding examples
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
@ -29,15 +29,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
upm::HCSR04 *sonar = NULL;
|
||||
int shouldRun = true;
|
||||
|
||||
void
|
||||
sig_handler(int signo)
|
||||
{
|
||||
printf("got signal\n");
|
||||
if (signo == SIGINT) {
|
||||
printf("exiting application\n");
|
||||
sonar->m_doWork = 1;
|
||||
shouldRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,20 +43,20 @@ sig_handler(int signo)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
sonar = new upm::HCSR04(5, 6);
|
||||
upm::HCSR04 *sonar = new upm::HCSR04(2, 4);
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
sleep(1);
|
||||
|
||||
for(;;){
|
||||
while(shouldRun){
|
||||
std::cout << "get distance" << std::endl;
|
||||
double distance = sonar->getDistance(CM);
|
||||
double distance = sonar->getDistance(HCSR04_CM);
|
||||
std::cout << "distance " << distance << std::endl;
|
||||
sleep(5);
|
||||
sleep(2);
|
||||
}
|
||||
std::cout << "Exiting... " << std::endl;
|
||||
|
||||
delete sonar;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//! [Interesting]
|
||||
|
Reference in New Issue
Block a user